Step-By-Step tutorial by:
Kode King, this will explain: Basic data types, If Then/Else If Statements, and more. Please do not redistribute this tutorial without my permision.
If you say i stole this from ProWorksProductions i did not, i am the same person.....Ok lets get started.
===============================Step 1
===============================Create 5 buttons;
Create 4 Text Boxes;
To do this go to toolbox,
Then Common Controls
===============================Step 2
===============================once you have made your buttons name button 1 -
button 2 +
button 3 *
button 4 /
button 5 =
===============================Step 3
===============================Now name lable 1 First Number
then name lable 3 Second Number
===============================Step 4
===============================Now it is time to begin coding;
Double click on button1 or -
Now you should have:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
End Sub
ok our code goes here:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
(Code Here)
End Sub
Ok lets put:
TextBox2.Text = "-"
That will change the Text/caption of TextBox 2 to - when clicked.
===============================Step 5
===============================Repeate Step 4 for buttons 2-4 Except
For 2 put TextBox2.Text = "+"
For 3 put TextBox2.Text = "*"
For 4 put TextBox2.Text = "/"
===============================Step 6
===============================Now we are moving on to the equal sign, or button 5.
Double click button 5;
Put the coding were we did before;
Dim subtraction As Char
Dim addition As Char
Dim division As Char
Dim multiplycation As Char
Dim dnumberone As Integer
Dim dnumbertwo As Integer
Dim Answere As Integer
dnumberone = TextBox1.Text
dnumbertwo = TextBox3.Text
subtraction = "-"
addition = "+"
division = "/"
multiplycation = "*"
If TextBox2.Text = subtraction Then
Answere = dnumberone - dnumbertwo
TextBox4.Text = Answere
ElseIf TextBox2.Text = addition Then
Answere = dnumberone + dnumbertwo
TextBox4.Text = Answere
ElseIf TextBox2.Text = division Then
Answere = dnumberone / dnumbertwo
TextBox4.Text = Answere
ElseIf TextBox2.Text = multiplycation Then
Answere = dnumberone * dnumbertwo
TextBox4.Text = Answere
End If
I will now explain;
Dim subtraction As Char
Dim addition As Char
Dim division As Char
Dim multiplycation As Char
Dim dnumberone As Integer
Dim dnumbertwo As Integer
Dim Answere As Integer
This is creating variables;
Char is a data type for + A 2 etc..
Integer is Interchangeable numbers;
Integer also includes negititve numbers;
Note: These are not all variable types;
Now dnumberone is
the name of the variable;
Variable names are interchangeable,but
you have to replace the new variable name throughout the code
Declareing the values to the variables:
dnumberone = TextBox1.Text
dnumbertwo = TextBox3.Text
subtraction = "-"
addition = "+"
division = "/"
multiplycation = "*"
Ok so dnumberone = TextBox1.Text
that means that the text of textbox1 is dnumberone's value
Ex:
Textbox1.text = 12
then
dnumberone = 12
we do this so that dnumber's value is interchangeable by the user
That is where the user will insert the first number textbox1
Same With What I just explained for dnumbertwo;
Now subtraction = "-"
that is setting the value again,
but it's not interchangeable,
so the value of subtraction = -
Same with the rest.
Ok Moving On To our If Then
Else If Statements
If TextBox2.Text = subtraction Then
Answere = dnumberone - dnumbertwo
TextBox4.Text = Answere
ok thats one action, its saying
if the text of textbox 2 = - then
the variable answere = dnumberone - dnumbertwo
get it so its setting the variable answere to the answere of variable dnumberone subtracted by variable dnumbertwo
it then puts the variable answeres value to textbox4's text by doing
TextBox4.Text = Answere
Ok moving onto one of the ElseIf statements
ElseIf TextBox2.Text = addition Then
Answere = dnumberone + dnumbertwo
TextBox4.Text = Answere
That means If the conditions of the if command are not true then check these conditons if tru the do the actions basically
Conditions: TextBox2.Text = addition
that means if textbox2 = variable addition then do actions.
Ok now
End If
that ends the if command put above
End Sub
Tutorial By:
KodeKing,
once again i did not leech i am proworksproductionsDo Not Redistribute this Tutorial
btw i realize i spell answer wrong sorry
This is a simple calculator tutorial, I will post an advanced calculator tutorial somewhere in the near future
Please Post questions/comments belowIf you would like an example of this calculator contact me via email
Email :
openopenme@gmail.com