Hi everybody, i am new here and hoping to learn a thing or two.
I am having 2 textboxes which require a telephone number and a postcode.
The telephone one i got working, but the postcode is giving me a hard time.
This is my code for the control of the telephone textbox.
I am trying to make a similar control for the postcode.
The format should be 2 letters a space and 5 numbers like GE 64200
I got this code, but needles to say its not working like that.
The main issue i am having is controlling the 2 letters.
I am hoping someone could help me out get the one for the postcode to work.
P.S there is of course a code on the form which calls this class.
Private Sub TxtTelephone_LostFocus(ByVal sender As Object, ByVal e As
Thanks
I am having 2 textboxes which require a telephone number and a postcode.
The telephone one i got working, but the postcode is giving me a hard time.
This is my code for the control of the telephone textbox.
Code:
Public Function ControlTelephone(ByVal StrTelephone As String) As Boolean
Dim BlnTestresult As Boolean
BlnTestresult = True
Dim IntTeller As Integer = 0
If Len(StrTelephone) = 10 Then
For IntTeller = 1 To 3
If Microsoft.VisualBasic.Mid(StrTelephone, IntTeller, 1) < "0" Or Microsoft.VisualBasic.Mid _
(StrTelephone, IntTeller, 1) > "9" Then
BlnTestresult = False
End If
Next
If Microsoft.VisualBasic.Mid(StrTelephone, 4, 1) = "/" Then
Else
BlnTestresult = False
End If
For IntTeller = 5 To 10
If Microsoft.VisualBasic.Mid(StrTelephone, IntTeller, 1) < "0" Or Microsoft.VisualBasic.Mid _
(StrTelephone, IntTeller, 1) > "9" Then
BlnTestresult = False
End If
Next
Else
BlnTestresult = False
End If
ControleTelefoon = BlnTestresult
End Function
I am trying to make a similar control for the postcode.
The format should be 2 letters a space and 5 numbers like GE 64200
I got this code, but needles to say its not working like that.
The main issue i am having is controlling the 2 letters.
Code:
Public Function ControlePostcode(ByVal StrPostcode As String) As Boolean
Dim BlnTestresult As Boolean
BlnTestresult = True
Dim IntTeller As Integer = 0
If Len(StrPostcode) = 7 Then
For IntTeller = 1 To 2
If Microsoft.VisualBasic.Mid(StrPostcode, IntTeller, 1) < "A" Or Microsoft.VisualBasic.Mid _
(StrPostcode, IntTeller, 1) > "9" Then
BlnTestresult = False
End If
Next
If Microsoft.VisualBasic.Mid(StrPostcode, 3, 1) = " " Then
Else
BlnTestresult = False
End If
For IntTeller = 4 To 7
If Microsoft.VisualBasic.Mid(StrPostcode, IntTeller, 1) < "0" Or Microsoft.VisualBasic.Mid _
(StrPostcode, IntTeller, 1) > "9" Then
BlnTestresult = False
End If
Next
Else
BlnTestresult = False
End If
ControlePostcode = BlnTestresult
End Function
I am hoping someone could help me out get the one for the postcode to work.
P.S there is of course a code on the form which calls this class.
Private Sub TxtTelephone_LostFocus(ByVal sender As Object, ByVal e As
Code:
System.EventArgs) Handles TxtTelephone.LostFocus
Dim Tel As New controle
If Tel.ControleTelephone(TxtTelephone.Text) Then
Else
MsgBox("Wrong")
TxtTelephone.Text = ""
End If
Tel = Nothing
End Sub
Thanks