2
Contributors
4
Replies
10
Views
5 Years
Discussion Span
Last Post by Sturdy
1

You can use Mid() , Left() or Right() function to get The first four characters and the last 3 characters and Use Len() for the length of text.

Edited by Jx_Man: n/a

0

You can use Mid() , Left() or Right() function to get The first four characters and the last 3 characters and Use Len() for the length of text.

Thank you for the suggestion.
This how far i'm doing. But i don't know how to check if last 3 character is number?

Private Sub Command1_Click()
Dim First4Char, Last3Char As String
First4Char = Mid(Text1.Text, 1, 4)
Last3Char = Mid(Text1.Text, 5, 7)
If Len(Text1.Text) <= 7 Then
    If First4Char <> "ABCD" Then
        MsgBox "Wrong"
    End If
    ' How i can check if last 3 char is numbers?
    
End If
End Sub

Edited by Sturdy: n/a

3

This how far i'm doing. But i don't know how to check if last 3 character is number?

Use IsNumeric() function :

Private Sub Command1_Click()
Dim First4Char, Last3Char As String
First4Char = Mid(Text1.Text, 1, 4)
Last3Char = Mid(Text1.Text, 5, 7)
If Len(Text1.Text) <= 7 Then
    If First4Char <> "ABCD" Then
        MsgBox "Wrong"
    Else
        If Not IsNumeric(Last3Char) Then
            MsgBox "Wrong Input"
        Else
            ' Action if text is accepted
        End If
    End If
End If
End Sub

Edited by Jx_Man: n/a

Votes + Comments
It worked very nice. :D
0

Use IsNumeric() function :

Private Sub Command1_Click()
Dim First4Char, Last3Char As String
First4Char = Mid(Text1.Text, 1, 4)
Last3Char = Mid(Text1.Text, 5, 7)
If Len(Text1.Text) <= 7 Then
    If First4Char <> "ABCD" Then
        MsgBox "Wrong"
    Else
        If Not IsNumeric(Last3Char) Then
            MsgBox "Wrong Input"
        Else
            ' Action if text is accepted
        End If
    End If
End If
End Sub

Thank you sir. It worked very nice.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.