Posto ne nadjoh ono sto sam zeleo evo jedne zanimljive varijante
Code:
Private Sub txtDatum_KeyPress(KeyAscii As Integer)
Dim strValid As String
txtDatum.SelLength = 1 'Ovo je bitno
Select Case txtDatum.SelStart
Case 0 'D1
strValid = "0123"
If InStr(strValid, Chr(KeyAscii)) = 0 Then
KeyAscii = 1
txtDatum.SelLength = 0
End If
Case 1 'D2
strValid = "0123456789"
If InStr(strValid, Chr(KeyAscii)) = 0 Then
KeyAscii = 1
txtDatum.SelLength = 0
End If
Case 2 'Separator
txtDatum.SelStart = txtDatum.SelStart + 1
txtDatum.SelLength = 1
Case 3 'M1
strValid = "01"
If InStr(strValid, Chr(KeyAscii)) = 0 Then
KeyAscii = 1
txtDatum.SelLength = 0
End If
Case 4 'M2
strValid = "0123456789"
If InStr(strValid, Chr(KeyAscii)) = 0 Then
KeyAscii = 1
txtDatum.SelLength = 0
End If
Case 5 'Separator
txtDatum.SelStart = txtDatum.SelStart + 1
txtDatum.SelLength = 1
Case 6 'G1
strValid = "12"
If InStr(strValid, Chr(KeyAscii)) = 0 Then
KeyAscii = 1
txtDatum.SelLength = 0
End If
Case 7 'G2
strValid = "0123456789"
If InStr(strValid, Chr(KeyAscii)) = 0 Then
KeyAscii = 1
txtDatum.SelLength = 0
End If
Case 8 'G3
strValid = "0123456789"
If InStr(strValid, Chr(KeyAscii)) = 0 Then
KeyAscii = 1
txtDatum.SelLength = 0
End If
Case 9 'G4
strValid = "0123456789"
If InStr(strValid, Chr(KeyAscii)) = 0 Then
KeyAscii = 1
txtDatum.SelLength = 0
End If
Case Else
KeyAscii = 1
txtDatum.SelLength = 0
End Select
If KeyAscii = 13 Then 'Enter
'Konacna validacija
End If
End Sub
Naravno ovo treba jos malo doterati, ali mislim da u sustini moze da prodje
Trebalo bi jos srediti cut i paste kao i delete taster (jer ne izaziva KeyPress event)
Zanima me vase misljenje - ima li smisla ovo raditi?!
[Ovu poruku je menjao Dejan Jankovic dana 15.06.2008. u 21:56 GMT+1]
[Ovu poruku je menjao Dejan Jankovic dana 15.06.2008. u 21:58 GMT+1]