How can I set the textbox to accept something of a given format like 'HH:mm' (12:22).
I belive that some API could solve it, but I can't find out how to do it.
TIA
Svein
Printable View
How can I set the textbox to accept something of a given format like 'HH:mm' (12:22).
I belive that some API could solve it, but I can't find out how to do it.
TIA
Svein
I haven't tested it, but I think this code will work:
Code:If Format(Text1,"hh mm")=Text1 Then
Msgbox "Ok"
Else
Msgbox "Wrong"
End If
So basically you want 4 numbers separated by a colon in the middle? If so, the Like operator would do the same.
Code:If Text1 Like "##:##" Then MsgBox "Format is correct"
I believe that you misunderstand me.
What I'm looking for is a API call to set the textbox to accept a given format of input. Something like setting the textbox to accept only numeric or letters except that I now would like it to accept hours with to digits and minutes with two digits. hours and minutes should be separated by a ':'..
TIA
Svein
Use a MaskedEdit Control for this.
Or if you want to use a standard TextBox, use the following. Make sure to set the TextBox's MaxLength to 5 (4 numbers + colon).
Code:Private Sub Text1_KeyPress(KeyAscii As Integer)
If Chr(KeyAscii) Like "#" Or KeyAscii = 8 Then
If Not KeyAscii = 8 Then If Len(Text1) = 2 Then Text1 = Text1 & ":"
Text1.SelStart = Len(Text1)
Else
KeyAscii = 0
End If
End Sub
I guess that I have not been clear enough when posting earlier.
I have a ComboBox and in the editfield of this Combo I would like to have the format of Short Time.
I know that I can use the masked Edit instead of EditBox, but I dont wanna mess the form up by using av Masked Edit in this case.
Do anyone know of some codesnippet that makes up the Masked Edit control ?? Would there be possible to transform this code to function in the combobox ???
TIA
Svein A. VĂ¥rdal