Ilogic part name

Ilogic part name

Anonymous
Not applicable
1,128 Views
2 Replies
Message 1 of 3

Ilogic part name

Anonymous
Not applicable

Our files have the following name "J12345-01-001.

I want to split the name so it returns the value after the second -

Can anybody help with a simple code.

I can split it using the count method but sometimes the value in the middle (01) is longer than 2 digits so

this then causes errors.

 

 

0 Likes
Accepted solutions (1)
1,129 Views
2 Replies
Replies (2)
Message 2 of 3

mcgyvr
Consultant
Consultant

@Anonymous wrote:

Our files have the following name "J12345-01-001.

I want to split the name so it returns the value after the second -

Can anybody help with a simple code.

I can split it using the count method but sometimes the value in the middle (01) is longer than 2 digits so

this then causes errors.

 

 


Sounds like you should be using the "Strings.Right" method

https://docs.microsoft.com/en-us/dotnet/api/microsoft.visualbasic.strings.right?view=netframework-4.8

A string containing a specified number of characters from the right side of a string.

Dim testString As String = "J12345-00001-002"
' Returns "002".
Dim subString As String = Right(testString, 3)


-------------------------------------------------------------------------------------------
Inventor 2023 - Dell Precision 5570

Did you find this reply helpful ? If so please use the Accept Solution button below.
Maybe buy me a beer through Venmo @mcgyvr1269
Message 3 of 3

Curtis_Waguespack
Consultant
Consultant
Accepted solution

Hi @Anonymous 

 

I typically use the Split function for something like this. Here is an example that splits the string using the dashes

sMyString = "12345-01-001"

'split the string into an array using the dash
sMyArray = sMyString.Split("-")

'use the members of the array in a message box
MsgBox("the first bit is this: " & vbLf & sMyArray (0) )
MsgBox("the middle bit is this: " & vbLf & sMyArray (1) ) 
MsgBox("the last bit is this: " & vbLf & sMyArray (2) )

 

Here's another example using a backslash as the split characther, and it shows how to use UBound to find the upper bounds of the array, which in the case of a file path will always be the file name:

sMyString = "C:\TEMP\Test\11111-01\11-111.ipt"

'split the string into an array using the dash
sMyArray = sMyString.Split("\")

'use the members of the array in a message box
MsgBox("the first bit is this: " & vbLf & sMyArray(0) )
MsgBox("the next bit is this: " & vbLf & sMyArray(1) ) 
MsgBox("the next bit after that is this: " & vbLf & sMyArray(2))

'get the upper bounds of the array
'in this case it would be the file name
i = UBound(sMyArray)
MsgBox("the file name is this: " & vbLf & sMyArray(i))

'change the string 
sMyString = "C:\TEMP\Test\111-1111\11111-01\111-1111\11111-01\11-111.ipt"
sMyArray = sMyString.Split("\")

'get the upper bounds of the array
'in this case it would be the file name
i = UBound(sMyArray)
MsgBox("Length of path changed, but we can still find the file name easily: " & vbLf & sMyArray(i))

Just a reminder, programming questions of this type are generally placed on the Inventor Customization forum :
http://forums.autodesk.com/t5/Autodesk-Inventor-Customization/bd-p/120

 

I'll as the forum moderators to move this thread to that forum for you.

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

EESignature