iLogic - How to return double zeros?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Bear with me here, I'm not that proficient in ilogic or any sort of coding for that matter... hopefully I've got the terminology correct or at least correct enough to be understood.
Also, I do have a work-around for what I want to achieve but I'm curious to see if there is a better way of getting what I want.
My new work place has a semi-smart numbering system that looks like this: xx-xxxxxx
The two digit prefix is for category/type of part and the six digit number after the hyphen is simply a dumb sequential part number.
But recently I've found a snag when trying to separate the two parts of the part number, so that the can be used in other ways that we don't need to cover here.
In the past when using ilogic I've used Val when needed to return the first numerical value from a string.
For example:
Dim Category = Val(iProperties.Value("Project", "Part Number"))
This will return the numerical value to the left of the hyphen. No problem ... usually ....
.... I have now discovered that Val drops all proceeding zeros.
The prefixes of the part number starts at "01" and any numbers starting with the prefix "01" through "09" are returned as 1, 2, 3, 4 ... etc and not 01, 02, 03, 04 ....
I could of course use Left:
Dim Category = Left ((iProperties.Value("Project", "Part Number")),2)
But using Val provides a numerical value which in a way provides a kind of built in check that what ever has been entered as the part number is actually a number.
For example, if someone had mistakenly entered "p3" as the prefix, using Val will simply return 0.
Using Left will return "p3" but I'm not interested in using p3 as that is incorrect.
I can add a check by using IsNumeric but this adds an extra step and just doesn't seem as tidy as using just Val.
So, my question is, can Val be told to return proceeding zeros? Or is there some other way to return proceeding zeros as part of a numerical value instead of returning a string and then checking if it is numerical.
TIA, Ben