|
-
Dec 9th, 2010, 10:44 PM
#1
Thread Starter
PowerPoster
[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?
-
Dec 10th, 2010, 12:32 AM
#2
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
-
Dec 10th, 2010, 08:35 AM
#3
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
-
Dec 10th, 2010, 12:09 PM
#4
Thread Starter
PowerPoster
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.
-
Dec 10th, 2010, 01:23 PM
#5
Thread Starter
PowerPoster
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
-
Dec 15th, 2010, 09:45 AM
#6
Thread Starter
PowerPoster
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|