Results 1 to 6 of 6

Thread: [RESOLVED] textbox change event

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Jul 2001
    Location
    Tucson, AZ
    Posts
    2,166

    Resolved [RESOLVED] textbox change event

    I'm using the textbox change event both to handle a XProcess call, but also
    need to allow the user to manually enter a string which represents currency.

    The problem I'm experiencing is the XProcess works fine, but the user entry
    to enter a currency "valued" string (e.g. 1234.75) is causing problems.
    (would not allow user to enter a proper string and would give weird results)
    I've identified it to the following line within the textbox Change event.

    Code:
    tbOrderPrice = Format$(tbOrderPrice.Text, "##.00")
    What is happening is this line is forcing the textbox change event to re-call itself.
    I need the above line to format the textbox string prior to calling
    several other procedures from this textbox change event.

    Anyone have any idea how I can get the textbox string to be correctly formatted
    without the event recalling itself?

  2. #2
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: textbox change event

    The Change event is triggered whenever the contents of the TextBox changes. So, when the user types a character into the textbox the change event triggers. I assume you want to format the entire contents, in which case you must find some way of identifying when the user has finished typing before you attempt to format it. You could, for example, have the user press the Return key and trap that using the KeyPress event rather than the Change event
    Code:
    Private Sub tbOrderPrices_KeyPress(KeyAscii As Integer)
    If KeyAscii = 13 Then
        KeyAscii = 0
        tbOrderPrices.Text = Format(tbOrderPrices.Text, "##.00")
        '
        ' Move the rest of the code from the Change event
        ' to here
        '
    End If
    End Sub

  3. #3
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: textbox change event

    I use textboxes occasionally for interprocess comm btwn 2 apps. When the textbox gets a command, it is to process the command and then delete the textbox contents. This obviously has the same effect you experience with the change event calling itself. Here's a simple way to avoid it...

    Code:
    Private Sub tbOrderPrice_Change()
       If tbOrderPrice.Tag =  "" Then
          tbOrderPrice.Tag = "NoAction" 
          tbOrderPrice = Format$(tbOrderPrice.Text, "##.00")
          tbOrderPrice.Tag = ""
       End If
    End Sub
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  4. #4

    Thread Starter
    PowerPoster
    Join Date
    Jul 2001
    Location
    Tucson, AZ
    Posts
    2,166

    Re: textbox change event

    Thanks both for responses.

    Moved Format$ outside of change event so that string being sent XProcess was formatted prior to arrival.

    Still testing to see if this will work as desired along with allowing the user to "alternately" manually enter info
    into the textbox when XProcess is not active.

    ======
    Will have to test both proposed concepts as Not sure whether when formatting the textbox on itself
    the assignment will again trigger the change event.

  5. #5

    Thread Starter
    PowerPoster
    Join Date
    Jul 2001
    Location
    Tucson, AZ
    Posts
    2,166

    Re: textbox change event

    Need some more testing. Will keep this thread open through next week.
    FWIW used a bit of both ideas.

    Code:
    Private Sub tbOrderPrice_KeyPress(KeyAscii As Integer)
       tbOrderPrices.Tag = "UserEntry"  
    End Sub
    
    Private Sub tbOrderPrice_Change()
       If tbOrderPrice.Tag =  "UserEntry" Then
          tbOrderPrice = Format$(tbOrderPrice.Text, "##.00")
          tbOrderPrice.Tag = ""
       Else
           '>> Price from XProcess App with formatting in XProcess App
    
       End If
    End Sub

  6. #6

    Thread Starter
    PowerPoster
    Join Date
    Jul 2001
    Location
    Tucson, AZ
    Posts
    2,166

    Re: textbox change event

    Resolved:

    1) Moved Format$ outside of change event so that string being sent XProcess was formatted prior to arrival.
    2) Also created a callback function to call the sending application so I could turn the XProcess on/off when
    user needed to manually enter information in the textbox.

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