TillytheShark
Gebruiker
- Lid geworden
- 17 mei 2008
- Berichten
- 17
Met behulp van een textbox wil ik tijden wegschrijven. De textbox dient daarom gecontroleerd te worden op input format. Ik controleer de input van textbox1 met:
De code selecteert de tekst, maar op een of andere manier wordt textbox1.setfocus niet goed uitgevoerd. Ik heb de code van textbox2 aangepast naar:
De code selecteert, bij verandering van textbox2, de inhoud van textbox3 en setfocus op textbox3. Dit wordt wel goed uitgevoerd... (Zie eventueel de bijlage)
Kan iemand mij uitleggen waarom?
Met vriendelijke groet'n,
Tilly_the_Shark
PS. Bestand is nog in ontwikkeling dus soms krijg je twee keer een error, wordt aan gewerkt.
Code:
Private Sub TextBox1_AfterUpdate()
Dim char1 As Variant
Dim char2 As Variant
Dim char3 As Variant
Dim char4 As Variant
If TextBox1.TextLength = 5 Then
char1 = Mid(TextBox1.Text, 1, 1)
char2 = Mid(TextBox1.Text, 2, 1)
char3 = Mid(TextBox1.Text, 4, 1)
char4 = Mid(TextBox1.Text, 5, 1)
End If
If Not (TextBox1.Text Like "##:##") Then
MsgBox "Entry must be in the format:" & vbCrLf & _
"##:## where # is a single digit.", vbExclamation + vbOKOnly, "Input Error"
With TextBox1
.SetFocus
.SelStart = 0
.SelLength = .TextLength
End With
End If
If Not (char1 >= 0 And char1 <= 2 And _
char2 >= 0 And char2 <= 9 And _
char3 >= 0 And char3 <= 5 And _
char4 >= 0 And char4 <= 9) Then
MsgBox "Entry must be in the format:" & vbCrLf & _
"##:## where # is a single digit.", vbExclamation + vbOKOnly, "Input Error"
With TextBox1
.SetFocus
.SelStart = 0
.SelLength = .TextLength
End With
End If
End Sub
Code:
If Not (TextBox2.Text Like "##:##") Then
MsgBox "Entry must be in the format:" & vbCrLf & _
"##:## where # is a single digit.", vbExclamation + vbOKOnly, "Input Error"
With TextBox3
.SetFocus
.SelStart = 0
.SelLength = .TextLength
End With
End If
Kan iemand mij uitleggen waarom?
Met vriendelijke groet'n,
Tilly_the_Shark
PS. Bestand is nog in ontwikkeling dus soms krijg je twee keer een error, wordt aan gewerkt.