Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Drop characters off of text box entry

Status
Not open for further replies.

mot98

MIS
Jan 25, 2002
647
CA
Hi all,

I have 2 text boxes that I need to compare, however they both have different starting alpha characters that I need to drop before I can do this.

Example:

Text1: S123456 Text2: A123456

Is there a way to strip the alpha characters off and then do the comparison?



mot98
[cheers]
"Is it friday yet?"
 
Take a look at the Mid Funtion
Code:
    Dim str As String

        str = "A1234567"
        str = Mid$(str, 2)
        Debug.Print str

If you choose to battle wits with the witless be prepared to lose.

[cheers]
 
Okay, so here is what I am trying:

txtS1 = AA12345
txtS2 = S12345

var_sSerial1 = Left$(txtS1, 1)
var_sSerial2 = Left$(txtS2, 1)

If var_sSerial1 = "S" Then
Serial1 = Mid$(txtS1, 2)
Else
Serial1 = Mid$(txtS1, 3)
End If

If var_sSerial2 = "A" Then
Serial2 = Mid$(txtS2, 3)
Else
Serial2 = Mid$(txtS2, 2)
End If

However, my Serial1 and Serial2 values are not getting populated. Am I missing something here?



mot98
[cheers]
"Is it friday yet?"
 
Did you try Foada's method? It works fine, as does yours. I just tried yours, using a msgbox to tell me the values of Serial1 and Serial2. Both were populated.

I hope this helps.

Ron Repp
 
Your Serial1 and Serial2 values should be set. Try debug.print serial1 & " " & serial2

Bob
 
I might use a little function to drop the alpha characters...

Code:
txtS1 = "AA12345"
txtS2 = "S12345"

Serial1 = DropAlpha(txtS1.Text)
Serial2 = DropAlpha(txtS2.Text)

Private Function DropAlpha(sText As String) As String
    Dim lLen As Long
    Dim sTemp As String
    Dim c As Long
    
    lLen = Len(sText)
    
    For c = 1 To lLen
    
        If IsNumeric(Mid$(sText, c, 1)) Then
        
            sTemp = sTemp & Mid$(sText, c, 1)
        
        End If
    
    Next

    DropAlpha = sTemp

End Function
 
Assuming that number of alpha characters stay the same

Code:
Dim sString_1 As String
Dim sString_2 As String

sString_1 = Right(Len(Trim(Text1.Text))-1)
sString_2 = Right(Len(Trim(Text2.Text))-1)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top