|
-
Sep 9th, 2012, 03:42 PM
#1
Thread Starter
New Member
Problem with writing a code to clear the result for TextBoxes using TextChanged
Hi All,
I am a newbie to VB. I use Visual Basic 2010. I am trying to build a basic Average Calculator Application. I can make the application calculate the average.
However, I am unable to write the code to clear the resultLabel after the user enters new input into any of the TextBoxes. Could anyone please help and point me to the right direction here? Below is my codes:
Public Class AverageCalculator
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim number1 As Integer
Dim number2 As Integer
Dim number3 As Integer
Dim total As Integer
Dim average As Integer
number1 = TextBox1.Text
number2 = TextBox2.Text
number3 = TextBox3.Text
total = number1 + number2 + number3
average = total / 3
resultLabel.Text = average
End Sub
'clear result
Private Sub TexBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
resultLabel.clear()
End Sub
Private Sub TextBox2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox2.TextChanged
resultLabel.clear()
End Sub
Private Sub Textbox3_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox3.TextChanged
resultLabel.Clear()
End Sub
End Class
Thanks in advance!
TheZealous
Last edited by TheZealous; Sep 9th, 2012 at 03:48 PM.
-
Sep 9th, 2012, 04:41 PM
#2
Re: Problem with writing a code to clear the result for TextBoxes using TextChanged
You could also save yourself a bit of code like this
vb.net Code:
'Handles all three textbox events in one sub
Private Sub TexBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged, TextBox2.TextChanged, TextBox3.TextChanged
resultLabel.Text = ""
End Sub
Last edited by dunfiddlin; Sep 9th, 2012 at 04:47 PM.
As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"
Reviews: "dunfiddlin likes his DataTables" - jmcilhinney
Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!
-
Sep 10th, 2012, 04:03 PM
#3
Thread Starter
New Member
Re: Problem with writing a code to clear the result for TextBoxes using TextChanged
Thanks for your help. The code does work!
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
|