bobbailey22
asked on
500 Points for quick answer
I have a Sub (shown below) that handles the TextChanged event for multiple textboxes. How do test the value of the textbox that triggers the textchagned event. I think I need to use the WithEvents somehow but don't know how. My overall goal is to bold the text if the value is greater than zero. (not sure how to programatically bold a textbox either.)
Private Sub txtAdministration_TextChan ged(ByVal sender As Object, ByVal e As System.EventArgs) _
Handles txtCaseRelated.TextChanged , txtAdministration.TextChan ged, txtMarketing.TextChanged, txtPrecert.TextChanged, txtBetterBaby.TextChanged, txtDiseaseManagement.TextC hanged
If sender.Text > 0 Then
' Bold the textbox
End If
End Sub
Private Sub txtAdministration_TextChan
Handles txtCaseRelated.TextChanged
If sender.Text > 0 Then
' Bold the textbox
End If
End Sub
oops, sorry, just reread your question...
Private Sub txtAdministration_TextChan ged(ByVal sender As Object, ByVal e As System.EventArgs) _
Handles txtCaseRelated.TextChanged , txtAdministration.TextChan ged, txtMarketing.TextChanged, txtPrecert.TextChanged, txtBetterBaby.TextChanged, txtDiseaseManagement.TextC hanged
Dim thisTextBox as Textbox = DirectCast(sender, Textbox)
Dim thistext As String = thisTextBox.Text
If IsNumeric(thisText) Then
If Csng(thisText) > 0 Then
thisTextBox.Font = new Font(thisTextBox.Font, FontStyle.Bold)
Else
Else
End If
End Sub
Private Sub txtAdministration_TextChan
Handles txtCaseRelated.TextChanged
Dim thisTextBox as Textbox = DirectCast(sender, Textbox)
Dim thistext As String = thisTextBox.Text
If IsNumeric(thisText) Then
If Csng(thisText) > 0 Then
thisTextBox.Font = new Font(thisTextBox.Font, FontStyle.Bold)
Else
Else
End If
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Thanks Joe... I've not actually used the AndAlso operator before, you're right about it making things neater
ASKER
Very nice guys. Great job!
Would either of you mind explaining how the withevents works?
Would either of you mind explaining how the withevents works?
When you're declaring an object that you want to capture events for... you use the WithEvents... that's probably the simplest way I could put it
Correct me if I am wrong but don't you want to evaluate both
IsNumeric(thisText)
and
Csng(thisText) > 0
as this is written Csng(thisText) > 0 would only be evaluated if the value of thisText was not numeric.
If IsNumeric(thisText) AndAlso Csng(thisText) > 0 Then
thisTextBox.Font = new Font(thisTextBox.Font, FontStyle.Bold)
Else
thisTextBox.Font = new Font(thisTextBox.Font, FontStyle.Regular)
End If
IsNumeric(thisText)
and
Csng(thisText) > 0
as this is written Csng(thisText) > 0 would only be evaluated if the value of thisText was not numeric.
If IsNumeric(thisText) AndAlso Csng(thisText) > 0 Then
thisTextBox.Font = new Font(thisTextBox.Font, FontStyle.Bold)
Else
thisTextBox.Font = new Font(thisTextBox.Font, FontStyle.Regular)
End If
ASKER
how is that any different than "Handles" doen't capture the events that it "Handles"?
forget it I was backward and accidently posted. I don't know what I hit.
what i mean is... say you have a timer class..
Dim WithEvents tmrTimer as New Timers.Timer(500) ' the WithEVents lets VS know that we plan to capture events for it somewhere
Sub Timed(sender as object, e as timers.ElapsedEventArgs) Handles tmrTimer.Elapsed ' we planned to capture the event, and now we have
' some code
End Sub
=========================
Dim WithEvents tmrTimer as New Timers.Timer(500) ' the WithEVents lets VS know that we plan to capture events for it somewhere
Sub Timed(sender as object, e as timers.ElapsedEventArgs) Handles tmrTimer.Elapsed ' we planned to capture the event, and now we have
' some code
End Sub
=========================
For Corey2: "as this is written Csng(thisText) > 0 would only be evaluated if the value of thisText was not numeric."
No, it's the other way around. If the text is not numeric then the test for >0 is not performed. I'm assuming here that if the user types "Foobar" then he doesn't want it to be bold.
If you just used "And" instead of "AndAlso" then it would throw an exception for a non-numeric input.
No, it's the other way around. If the text is not numeric then the test for >0 is not performed. I'm assuming here that if the user types "Foobar" then he doesn't want it to be bold.
If you just used "And" instead of "AndAlso" then it would throw an exception for a non-numeric input.
While I was typing i realized that AndAlso only interupted if the first expression evaluated to false, where I was origional thinking it would continue if it evaluated to true. So I was going to abandon my post but it was too late when clicking back into this window I somehow caused it to post unintentionally. I hate it when that happens.
Corey2
Corey2
ASKER
They you for the explination. You are way ahead of me but thats why your the expert!
Thanks again,
Bob
Thanks again,
Bob
Private Sub txtAdministration_TextChan
Handles txtCaseRelated.TextChanged
Dim thisTextBox as Textbox = DirectCast(sender, Textbox)
If thisTextBox.TextLength > 0 Then 'I assume you meant textlength
' Bold the textbox
End If
End Sub