I have to get rid of all zeros from the beginning of numbers, i.e. if the number is 0005678, I have to have 5678 as a result. The number of zeros may change. Is there any chance to make VB do this?
You may create your own function:
Public Function LTrimZero(myVar) As String
Dim s As String
s = myVar & ""
While Left(s, 1) = "0"
s = Mid(s, 2)
Wend
LTrimZero = s
End Function
Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
I think Mr. 03021979 has three zeros in front of his H's in that post.
If you're in Excel, my snippet still works (that's a zero in the quotes in my snippet). But maybe...
Do While Left(mystring, 1) = "0" 'zero
mystring = Right(mystring, Len(mystring) - 1)
Loop
Or
While InStr(1, mystring, "0") = 1
mystring = Right(mystring, Len(mystring) - 1)
Wend
either would be more generic.
I notice that the original question is from Mr. 03021979
then
OurQuestioner = "03021979"
Do While Left(OurQuestioner, 1) = "0" 'zero
mystring = Right(OurQuestioner, Len(OurQuestioner) - 1)
Loop
Mr. 03021979 probably uses 3021979 as a nickname. His surname appears to be "vendor" which doesn't need to be trimmed.
Of course I'm assuming that our questioner is male. Isn't an assumption what got me in trouble in the first place?
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.