Aman1238
#swag
- Messages
- 4,644
- Location
- United States
[VB] Basic calculator Tutorial - SA_killer
You will need to know the basics of VB 2008.
Is the code you will need to enter.
-// This is the explanation for the code.
New project:
1. Create a new project. Name it what ever you want.
Design:
1. Resize till its comfortable.
2. Add 11 buttons for numbers and point (0 - 9, ".")
3. Add four buttons for Addition, Substraction, Division and multiplication.
4. Add a textbox for numbers.
5. Add a Button for equal sign.
6. Add a button for "C" which is clear.
7. Click each button and change the text from the properties to what ever is needed. (for example if the button is for "+" then change the text to "+". DO the same for every button.)
End of Design.
Codes: The hardest (for some people.)
1. Setting dimensions: (i dont have an explanation for this sorry.
At the very top of all codes add
2. You do not need any code for the textbox.
3. Numbers. The code for every number is the same expect for the number for the code. I personally like IF, Then commands. Double click "1" and the code is:
The code foe everynumber will be the same except for the "1" will be "2" ect.
-// Textbox1.text means the text to be added or changed. "( )" are to define it. + 1 is just to add one to textbox. " " are to specify not to do the addition problem but just add one.
4. Firstnumber and second number. Firstnumber is the first number you click and second is the second number you click.
5. +, -, *, /. The code is the same except for the arithimetic process. Double click any of the processes. the code is:
-// Val means the value in the textbox that it will pickup for the first number. Other code is easy. Do the same for every other functions and just change the + - / *
6. Now the = sign which the longest . As we already picked up the first number we now need to get the second number. Double click = and the code is :
-//If you read the code you will understand. Its not hard to get this.
Extras:
You can go in the form properties and change some stuff like font color, background, icons. Just explore!
Hope I helped. Btw, Notepad tutorial comming soon
You will need to know the basics of VB 2008.
Code:
...
-// This is the explanation for the code.
New project:
1. Create a new project. Name it what ever you want.
Design:
1. Resize till its comfortable.
2. Add 11 buttons for numbers and point (0 - 9, ".")
3. Add four buttons for Addition, Substraction, Division and multiplication.
4. Add a textbox for numbers.
5. Add a Button for equal sign.
6. Add a button for "C" which is clear.
7. Click each button and change the text from the properties to what ever is needed. (for example if the button is for "+" then change the text to "+". DO the same for every button.)
End of Design.
Codes: The hardest (for some people.)
1. Setting dimensions: (i dont have an explanation for this sorry.
At the very top of all codes add
Code:
Option Explicit On
Public Class Form1
Dim Firstnumber As Single
Dim Secondnumber As Single
Dim Answernumber As Single
Dim Arithmeticprocess As String
3. Numbers. The code for every number is the same expect for the number for the code. I personally like IF, Then commands. Double click "1" and the code is:
Code:
If TextBox1.Visible Then
TextBox1.Text = (TextBox1.Text) + "1"
End If
-// Textbox1.text means the text to be added or changed. "( )" are to define it. + 1 is just to add one to textbox. " " are to specify not to do the addition problem but just add one.
4. Firstnumber and second number. Firstnumber is the first number you click and second is the second number you click.
5. +, -, *, /. The code is the same except for the arithimetic process. Double click any of the processes. the code is:
Code:
FirstNumber = Val(TextBox1.Text)
Textbox1.text = "0"
Arithmeticprocess = "+"
6. Now the = sign which the longest . As we already picked up the first number we now need to get the second number. Double click = and the code is :
Code:
Secondnumber = Val(TextBox1.Text)
If Arithmeticprocess = "+" Then
Answernumber = Val(Firstnumber) + Val(Secondnumber)
End If
If Arithmeticprocess = "-" Then
Answernumber = Val(Firstnumber) - Val(Secondnumber)
End If
If Arithmeticprocess = "*" Then
Answernumber = Val(Firstnumber) * Val(Secondnumber)
End If
If Arithmeticprocess = "/" Then
Answernumber = Firstnumber / Secondnumber
End If
TextBox1.Text = Answernumber
Extras:
You can go in the form properties and change some stuff like font color, background, icons. Just explore!
Hope I helped. Btw, Notepad tutorial comming soon