Results 1 to 3 of 3

Thread: text format

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2002
    Location
    Pilipinas
    Posts
    441

    text format

    if Use this code below.

    Private Sub Text1_Change()
    If Not IsNumeric(Text1.Text) Then
    SendKeys vbBack
    End If
    End Sub

    Private Sub Text1_Validate(Cancel As Boolean)
    Text1.Text = Format(Text1.Text, "#.#0")
    End Sub


    This code doesn't get what I want to happen..

    All I want is everytime I enter a number, the text of Text1 is formatted to "#.#0"

    WHat code should I write?

  2. #2
    PowerPoster lintz's Avatar
    Join Date
    Mar 2003
    Location
    The 19th Hole
    Posts
    2,697
    Try this...

    VB Code:
    1. Private Sub Text1_Change()
    2. If Not IsNumeric(Text1.Text) Then
    3. SendKeys vbBack
    4. Exit Sub
    5. End If
    6. Text1 = Format(Text1, "#.#0")
    7. End Sub

  3. #3
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431
    If you like you can click the NumberBox link in my signature. That will direct you to code for a NumberBox control that you can use in your project(s). It is like a normal textbox except that it accepts only numbers (including decimal point and minus sign) with the addition of properties that allow you to set the maximum number of decimals and if negatives are allowed.

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