This function removes a leading character from a string (e.g. aaaaa535a to 535a or 000123 to 123) 
 
If you want to just do a number and know that you have all numbers as the string. Then do the second function below. 
 
Function TrimString(oldstring As String, charstring) As String 
	' this function is meant to trim and leading characters off of an existing string based number 
	' oldstring is original string; charstring is leading character to remove (e.g. 0s) 
	Dim newstring As String 
	Dim a As Integer 
	Dim b As Integer 
	Dim ch As String 
	b = 0 
	For a = 1 To Len(oldstring) 
		ch =Mid(oldstring,a,1)  
		If ch <> charstring Then 
		' Stop at the first non-zero character 
			Goto FoundIt  
		End If 
		b=b+1 
	Next 
FoundIt: 
	newstring = Right(oldstring,Len(oldstring)-b) 
	If newstring ="" Then 
		TrimString = oldstring 
	Else 
		TrimString = newstring 
	End If 
End Function 
 
Function TrimNumStr(oldstring As String) 
Dim tmpnum As Long 
Dim newstr As String 
tmpnumb=CLng(oldstring) 
newstr=CStr(tmpnumb) 
TrimString=newstr 
End Function
  
previous page
 
  |