Simple VB Calculator

Veering away from VBA for the experience -

Trying to create a simple calculator in Visual Basic using Visual Studio 2012. I've got 3 textboxes, and an add button - that's it

Below is the code I have for the add button - but I keep getting a build error: BC3021 Expression Expected

Public Class Form1

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        
       

       TextBox3.Text = ('(Convert.ToInt32(TextBox1.Text) + (Convert.ToInt32(TextBox2.Text)')  End Sub

End Classb

Open in new window


Input appreciated
dawber39Database Analyst / Application DeveloperAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Prakash SamariyaIT ProfessionalCommented:
Please try below
Public Class Form1
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
       TextBox3.Text = Convert.ToInt32(TextBox1.Text) + (Convert.ToInt32(TextBox2.Text)  
       'OR   TextBox3.Text = Val(Textbox1.text)+Val(Textbox2.text)
    End Sub
End Class

Open in new window

0
Tapan PattanaikSenior EngineerCommented:
Hi dawber39,

Please write the below code in Button1_Click event.

TextBox3.Text = (Convert.ToInt32(TextBox1.Text) + (Convert.ToInt32(TextBox2.Text)))

Regards,
Tapan Pattanaik
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
dawber39Database Analyst / Application DeveloperAuthor Commented:
As always you guys are great - I figured there was some kind of syntax error - I appreciate the input. I did try both - with the first I got another build error - you people are great. I can always count you
0
it_saigeDeveloperCommented:
While the above methods will work.  You will want to first sanitize (or validate) your input.  Luckily the .NET framework already has helper methods in place for this very reason.  It really then just becomes a matter of how verbose you want to get with your code.

Extremely verbose -
Public Class Form1
	Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
		If String.IsNullOrEmpty(TextBox1.Text) OrElse Not IsNumeric(TextBox1.Text) Then
			MessageBox.Show("The value in TextBox 1 must be a numeric value")
			Return
		End If

		If String.IsNullOrEmpty(TextBox2.Text) OrElse Not IsNumeric(TextBox2.Text) Then
			MessageBox.Show("The value in TextBox 2 must be a numeric value")
			Return
		End If

		TextBox3.Text = Convert.ToDecimal(TextBox1.Text) + Convert.ToDecimal(TextBox2.Text)
	End Sub
End Class

Open in new window

-saige-
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.