0

howdy folks
please am working on an Annual Crop Cashflow Calculator like an Excel
i have 3 text boxes.
textbox22 textbox31 and textbox71
if i multiply textbox22 by textbox31 it shows in textbox71
but the problem is i need an event jus like excel after calculating and user goes back to empty either textbox31 or textbox22 the answer in texbox71 should be empty...
but with what i have here d previous answer will still be there until user inputs another entry

solution please
below is my code

 Private Sub TextBox71_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox22.TextChanged, TextBox31.TextChanged
        If String.IsNullOrEmpty(TextBox22.Text) OrElse String.IsNullOrEmpty(TextBox31.Text) Then Exit Sub
        If Not IsNumeric(TextBox22.Text) OrElse Not IsNumeric(TextBox31.Text) Then Exit Sub
         TextBox71.Text = CDbl(TextBox22.Text) * CDbl(TextBox31.Text)
    End Sub

Edited by happygeek: moved

3
Contributors
5
Replies
20
Views
3 Weeks
Discussion Span
Last Post by Reginald Xavier
0

Most common issue? The coder forgot to connect the event to the code that handles the event. It's not automatic.

1

@rproffitt - Actually the Handlesclause in VB.net looks after that.

@Reginald Xavier - It looks to me that after checking for the empty/incorrect string, you're exiting the sub routine and the recalculation never happens. One way around this is to reset the text to a base amount, probably 0, instead of exiting.

You also might have better results by handling the Validating event instead of the TextChanged event

Edited by tinstaafl

Votes + Comments
I wish that always worked for me. I had this not firing and went to the lightning bolt and had to fix it. Well, it is a Microsoft product so I agree
0

tinstafaal Thanks I went through MSDN and i used the Keypress event.. Now my code works just fine.
i edited the snipet and it worked

thanks

 Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged 
        TextBox2.Clear() 
    End Sub 

    Private Sub TextBox1_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress 
        TextBox1.Text = TextBox1.Text 
    End Sub 

    Private Sub TextBox2_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox2.KeyPress 
        TextBox1.Clear() 
    End Sub 

    Private Sub TextBox2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox2.TextChanged 
        TextBox2.Text = TextBox2.Text 
    End Sub 
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.