You should have mentioned that you are using VBScript.
The code I gave would compile fine in VB6.
Anyway, here is the VBScript Code:
Code: VB
Function StripNumber (GetComputerName)
Dim Str,i,b
b = 1
GetComputerName = Trim(GetComputerName)
ComputerNameLength = Len(GetComputerName)
For i = ComputerNameLength To 1 Step -1
If IsNumeric(Mid(GetComputerName, i, 1)) Then
Str = Left(GetComputerName, ComputerNameLength - b)
b = b + 1
Else
Exit For
End If
Next
If Str = "" And b = 1 Then
Str = GetComputerName
End If
StripNumber = Trim(Str)
End Function
To try the above func, here is a test program:
Code: VB
Dim mStr
mStr = InputBox("Enter a test value")
Msgbox(StripNumber(mStr))
WScript.quit
Function StripNumber (GetComputerName)
Dim Str,i,b
b = 1
GetComputerName = Trim(GetComputerName)
ComputerNameLength = Len(GetComputerName)
For i = ComputerNameLength To 1 Step -1
If IsNumeric(Mid(GetComputerName, i, 1)) Then
Str = Left(GetComputerName, ComputerNameLength - b)
b = b + 1
Else
Exit For
End If
Next
If Str = "" And b = 1 Then
Str = GetComputerName
End If
StripNumber = Trim(Str)
End Function
The previous code had a very minor bug which return "blank" only when the input text was *purely* alphabetical.
Hope this one is alright.
Tell me if it works ..