Results 1 to 7 of 7

Thread: Format in textbox

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2000
    Posts
    3
    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

  2. #2
    Fanatic Member
    Join Date
    Feb 2000
    Location
    The Netherlands
    Posts
    715
    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

  3. #3
    Guest
    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"

  4. #4

    Thread Starter
    New Member
    Join Date
    Sep 2000
    Posts
    3

    Format in textbox

    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

  5. #5
    Guest
    Use a MaskedEdit Control for this.

  6. #6
    Guest
    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

  7. #7

    Thread Starter
    New Member
    Join Date
    Sep 2000
    Posts
    3
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width