Results 1 to 6 of 6

Thread: TextBox

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Aug 2000
    Posts
    23

    Unhappy

    How do I check a textbox for characters when it should only accept chars? Also I am having trouble formatting the text.
    I would like to take the number entered and convert it to a percentage( 10 should look like this 10%) and one for time(1hr and 15min should look like this 1.15) Please help

  2. #2
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538
    Sorry if I hav understood this wrong, by "characters" do you mean text & not numbers?

    If so you could do something like:
    Code:
    private sub command1_click()
    If isnumeric(text1.text)  then
        MsgBox"please type letters only!"
    End If
    With the next part, you could use the format function...

    format(text1.text, "##" & "%") or
    Format(text1.text, "#.##")

    Hope this helps!
    Alex Read

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Aug 2000
    Posts
    23

    textbox

    Hey Alex
    the formatting isn't working, whenever I enter a number i t automatically multiplies it by 100(10 looks like 1000%) also I made a typo I am checking for text that should be numbers

  4. #4
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538
    Use If Not Isnumeric(text1.text) then...


    And also:

    Format(text1.text, "##")
    text1.text = text1.text & "%"


    Hope this helps!

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

  5. #5
    Guest
    Or you could capture the keys in the key press event:
    To disable numbers any other characters,

    Private Sub text1_KeyPress(KeyAscii As Integer)
    Select Case KeyAscii
    Case 65 To 90:
    Case 97 to 122:
    Case 8: 'backspace
    Case Else
    Beep
    KeyAscii = 0
    End Select
    End Sub

  6. #6
    Guest
    Try the following:
    Code:
    Private Sub Text1_KeyPress(KeyAscii As Integer)
        If KeyAscii = 8 Or KeyAscii = 32 Then Exit Sub
        If Not Chr(KeyAscii) Like "[A-z]" Then KeyAscii = 0
    End Sub

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