Jump to content
New account registrations are disabed. This website is now an archive. Read more here.
Sign in to follow this  
formlesstree4

Lesson 1 - 2: Doing math with Variables

Recommended Posts

Well, I've spaced out the lesson a little longer than I had wanted, but here we go.

 

Open Visual Basic .NET Express Edition, and load a New Project, and call it mathProgram.

Once loaded, create one button, and double click it. The code editor will show up, revealing the following code:

 

Public Class Form1

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

End Sub
End Class

 

If there is something different, might wanna check something out. Now, inside the Button1_Click Sub, add the following code:

 

Dim Var1 As Double = 1
Dim Var2 As Double = 2

 

Now, add this:

Messagebox.show(Var1 + Var2)

Run your program by pressing the little Green Arrow at the top of the IDE (or by pressing F5) and click your button. If it worked right, you should now see a Messagebox with the number 3 inside it!

 

VB.net supports basic math operations, like adding, subtracting, multiplying, and dividing. It also support several advanced features that you will learn later on.

 

HOMEWORK:

Since you know how to assign a TextBox.text value to a variable, construct a program that will take in a number from two different textboxes and add them together, displaying the results in a messagebox like the lesson shows.

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...