iproperties date is it 1st of november or 11th of january? vb.net

iproperties date is it 1st of november or 11th of january? vb.net

Anonymous
Not applicable
893 Views
3 Replies
Message 1 of 4

iproperties date is it 1st of november or 11th of january? vb.net

Anonymous
Not applicable

Hi,

 

I have a problem with reading out dates from the iproperties its as follows..

 

Im using a vb.net maskedtextbox which is as follows 00-00-0000 the problem is that the the input from inventor changes 01-01-2016 to 11-20-16 removing the 0 from days and moths befor the value of 10.

 

I could read the data in backwards (starting with the year) thats the years fixed but months and days are tricky take for example 01-11-2016 which is read by my masked textbox as 11-12-016 now I dont know weather its the 11th of january or the 1st of November.

 

how can I fix this in inventors vb.net/ API

 

tghe way i read the data into the textbox is as follows.

 

        ' Get the custom property set. 
        Dim DESTRACKPropSet As Inventor.PropertySet
        DESTRACKPropSet = Doc.PropertySets.Item("Design Tracking Properties")
        ' Get the existing property, if it exists. 
        Dim PROPDATE As Inventor.Property = Nothing
        PROPDATE = DESTRACKPropSet.Item("Date Checked")
        Dim VALDATE As String = PROPDATE.Value
        MaskedTextBox1.Text = VALDATE.Split(" "c)(0)
0 Likes
Accepted solutions (1)
894 Views
3 Replies
Replies (3)
Message 2 of 4

Anonymous
Not applicable

See how this works.

This snippet of code will look through your string VALDATE finding the single month (-9-) and add the missing leading zero in:

 

 

        VALDATE = Microsoft.VisualBasic.Replace(VALDATE, "-1-", "-01-")
        VALDATE = Microsoft.VisualBasic.Replace(VALDATE, "-2-", "-02-")
        VALDATE = Microsoft.VisualBasic.Replace(VALDATE, "-3-", "-03-")
        VALDATE = Microsoft.VisualBasic.Replace(VALDATE, "-4-", "-04-")
        VALDATE = Microsoft.VisualBasic.Replace(VALDATE, "-5-", "-05-")
        VALDATE = Microsoft.VisualBasic.Replace(VALDATE, "-6-", "-06-")
        VALDATE = Microsoft.VisualBasic.Replace(VALDATE, "-7-", "-07-")
        VALDATE = Microsoft.VisualBasic.Replace(VALDATE, "-8-", "-08-")
        VALDATE = Microsoft.VisualBasic.Replace(VALDATE, "-9-", "-09-")
0 Likes
Message 3 of 4

Owner2229
Advisor
Advisor
Accepted solution

Hi, you can simply look for the separators "-" and split the date by it:

 

' Get the custom property set
Dim DESTRACKPropSet As Inventor.PropertySet = Doc.PropertySets.Item("Design Tracking Properties")

' Get the date property
Dim PROPDATE As Inventor.Property = DESTRACKPropSet.Item("Date Checked")
Dim VALDATE As String = PROPDATE.Value
If VALDATE = vbNullString Then Exit Sub ' Look for the separators and split the date Dim SPa As Integer = InStr(VALDATE, "-") Dim SPb As Integer = InStr(SPa + 1, VALDATE, "-") Dim aMonth As String = Microsoft.VisualBasic.Left(VALDATE, SPa - 1) Dim aDay As String = Mid(VALDATE, SPa + 1, SPb - SPa - 1) Dim aYear As String = Mid(VALDATE, SPb + 1) MaskedTextBox1.Text = aMonth & " " & aDay & " " & aYear

 

Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
0 Likes
Message 4 of 4

Anonymous
Not applicable

Okay this works neat did have to change the structure to conform with EU date format (dd/mm/yyyy) instead of (mm/dd/yyyy)... Why is it that the U.S. has month before day anyway?

 

and I did have to actually change the code to add the extra 0 if it was missing.... but the code works like a charm couldnt of done it without your sugestion 🙂

 

        ' Get the custom property set
        Dim DESTRACKPropSet As Inventor.PropertySet = Doc.PropertySets.Item("Design Tracking Properties")

        ' Get the date property
        Dim PROPDATE As Inventor.Property = DESTRACKPropSet.Item("Date Checked")
        Dim VALDATE As String = PROPDATE.Value
        If VALDATE = vbNullString Then Exit Sub

        ' Look for the separators and split the date
        Dim SPa As Integer = InStr(VALDATE, "-")
        Dim SPb As Integer = InStr(SPa + 1, VALDATE, "-")

        Dim aDay As String = Microsoft.VisualBasic.Left(VALDATE, SPa - 1)
        If aDay.Length() = 1 Then
            aDay = ("0" & aDay)
        End If

        Dim aMonth As String = Mid(VALDATE, SPa + 1, SPb - SPa - 1)
        If aMonth.Length() = 1 Then
            aMonth = ("0" & aMonth)
        End If

        Dim aYear As String = Mid(VALDATE, SPb + 1)

        TextBox5.Text = aDay & "-" & aMonth & "-" & aYear 

 

0 Likes