Results 1 to 6 of 6

Thread: Easy Help!!Formating Textboxes

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2000
    Location
    Greenville
    Posts
    73

    Post

    OK if i want to format a textbox so 'currency' or 'date' or something else where is it best to do it, such as under txt_GotFocus or txt_Change or something else so that it stays that when it is changed and saved like that?? PS Could you throw in the format for PhoneNumber?

  2. #2
    Frenzied Member Mark Sreeves's Avatar
    Join Date
    Nov 1999
    Location
    UK
    Posts
    1,845

    Post

    I reckon either in LostFocus or trapping a return key press would be as good a place as any!

    eg:
    Code:
    Private Sub text1_KeyPress(KeyAscii As Integer)
    If KeyAscii = 13 Then
      text1.Text = format(...... text1.Text etc)
    End If
    
    End Sub
    ------------------
    Mark Sreeves
    Analyst Programmer

    Mark.Sreeves@Softlab.co.uk
    A BMW Group Company



  3. #3
    Frenzied Member Mark Sreeves's Avatar
    Join Date
    Nov 1999
    Location
    UK
    Posts
    1,845

    Post

    lost focus would probably be better

    you could do both though...

    ------------------
    Mark Sreeves
    Analyst Programmer

    Mark.Sreeves@Softlab.co.uk
    A BMW Group Company



  4. #4

    Thread Starter
    Lively Member
    Join Date
    Jan 2000
    Location
    Greenville
    Posts
    73

    Post

    Thanks for all the input. I am learning quick by chatting on VB World, I love it.

  5. #5
    Frenzied Member Buzby's Avatar
    Join Date
    Jan 1999
    Location
    UK
    Posts
    1,670

    Post

    I use LostFocus to format the text box;

    Sub TextBox1_LostFocus
    Textbox1.Text=Format(TextBox1.Text,"Currency")
    End sub

    Note: If it's currency I tend to use the GotFocus event to return it to a double for easy editing;

    Sub Textbox1_GotFocus
    TextBox1.Text=Cdbl(TextBox1.Text)
    End Sub


    As for phone numbers, DO NOT attempt to format them - there is no guaranteed formatting for phone numbers. For example, a load of phone numbers in the UK have just changed (this is about the third change we've had in the last few years), so you never can be sure that they will stay the same.

    ------------------
    Mark "Buzby" Beeton
    VB Developer
    BuzbyB@HotMail.Com




    [This message has been edited by Buzby (edited 02-03-2000).]

  6. #6
    Hyperactive Member
    Join Date
    Jun 1999
    Location
    Calgary Alberta
    Posts
    359

    Post

    The problem with capturing a key press or the changed event is that if you use the standard :

    format(string, style)

    then it will fill the rest of the text with with the style. I really haven't been able to make it work there. Generally what I'll do is capture the lost focus. I could be wrong about the other, I've just never got it to work right.

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