Hi all,
I name my files with our part numbers and the revision number. Our part numbers are 6 to 9 digits long and sometimes start with a zero! My iLogic rule, while simple, drops the first zero if its there. See the "FirstNumbers" below: (I tried to add the CStr(), but now I see that it just changes it to text after it drops the zero!)
Any suggestions?
ThisFile = ThisDoc.FileName(False) 'without extension FirstNumbers = CStr(Val(ThisFile)) 'sets the first numbers from the file name to text PartNumber = iProperties.Value("Project", "Part Number") 'reads part number from file
'check to see if the part number is the same as the file name's numbers If String.Compare(FirstNumbers, PartNumber, True) = 0 Then 'do nothing Else
'set the Part Number to the file name's numbers iProperties.Value("Project", "Part Number") = FirstNumbers
'let's me know that something has been done MessageBox.Show("Part Number has been set to " & FirstNumbers, "Part Number from File Name") End If
Solved! Go to Solution.
Solved by planglais75. Go to Solution.
Hi nick,
Why you don't simply compare PartNumber with ThisFile ?
or here's two suggestions to format your ThisFile variable:
FirstNumbers = String.Format("{0:000000000}" ,Val(ThisFile)) ' Always return 9 digits with leading 0
FirstNumbers = String.Format(ThisFile, "{c}") ' Return
planglais,
Thanks for the quick reply! I can't change the length of the part numbers, as they are tied into our inventory system - otherwise the "String" example would work fine.
Here are some examples of file names I have to work with:
060321 Rev2.iam
990101500 Rev1.ipt
0512135.ipt
625121 90-32dn.iam
201301 - Rev3.ipt
(Set the first numbers to the part number.)
It seems there is always a space after the part number. Is there a way to get a string to the left of a space?
If a space is always present, you can use the split method:
Split("060321 Rev2.iam", " ")(0) ' Will return 060321
Method Split(string, separator) return an array of string:
element 0 => 060321
element 1 => Rev2.iam
So element 0 will return your part number.
Pascal