Hack Forums
[.NET] Calculator tutorial! Visual Basic. - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [.NET] Calculator tutorial! Visual Basic. (/showthread.php?tid=4989476)



Calculator tutorial! Visual Basic. - Cece Drake - Sep 16, 2015

Open up Visual Studio, and start a new project.
Create a Visual Basic program & make it a "Windows form application".
-
What you need to do:
Drop in 3 labels.
First one: "Enter first number"
Second one: "Enter second number"
and the third one: "Result".
Drop in 4 buttons and name them
1: "Add"
2: "Subtract"
3: "Multiply"
and 4: "Divide"
Then just drop in 3 text boxes.
Put the first label at the top, with a text box under it.
Drop the second label under the first textbox and another text box under the second label.
Then just put the four buttons how ever you like under.
At the bottom put the result label & textbox in together.
Make sure that in the last textbox in the settings you turn ReadOnly to True.
-
iNcase you can't keep up, here's a photo
http ://postimg. org/image/6wb07x90n/
-
Time for the coding.
Double tap all the buttons, then close the tabs and go back to the original form.
Double tap the form and that should take you to this
http ://postimg. org/image/ih8bd28r7/
-
Under Button1_Click you have to enter in the following code
PHP Code

<?php 
Dim a
, b, r As Integer
a 
= Val(Textbox1.Text)
b = Val(Textbox2.Text)
r = a + b
Textbox3
.Text = r 
Dim a, b, r As Integer // This tells the program that textbox 1 = A, textbox 2 = b and textbox 3 = result/r.
-
For button2_Click enter the same code except change a + b to a - b.
:
PHP Code

<?php 
Dim a
, b, r As Integer
a 
= Val(Textbox1.Text)
b = Val(Textbox2.Text)
r = a - b
Textbox3
.Text = r 
-
Button3_click
PHP Code

<?php 
Dim a
, b, r As Integer
a 
= Val(Textbox1.Text)
b = Val(Textbox2.Text)
r = a * b
Textbox3
.Text = r 
-
PHP Code

<?php 
Dim a
, b, r As Integer
a 
= Val(Textbox1.Text)
b = Val(Textbox2.Text)
r = a / b
Textbox3
.Text = r 
-
Full code:
PHP Code

<?php 
Public Class Form1

    
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

    End Sub

    
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim a
, b, r As Integer
        a 
= Val(TextBox1.Text)
        
b = Val(TextBox2.Text)
        
r = a + b
        TextBox3
.Text = r
    End Sub

    
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        Dim a
, b, r As Integer
        a 
= Val(TextBox1.Text)
        
b = Val(TextBox2.Text)
        
r = a - b
        TextBox3
.Text = r
    End Sub

    
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
        Dim a
, b, r As Integer
        a 
= Val(TextBox1.Text)
        
b = Val(TextBox2.Text)
        
r = a * b
        TextBox3
.Text = r
    End Sub

    
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
        Dim a
, b, r As Integer
        a 
= Val(TextBox1.Text)
        
b = Val(TextBox2.Text)
        
r = a / b
        TextBox3
.Text = r
    End Sub
End 
Class 
-
END RESULT:
http ://postimg. org/image/vjbx2lp7r/
Thanks for reading :)
If you have any questions (I'm not a pro) feel free to ask! :)
Please leave some feedback if this helped you


* - Josh‎ - Sep 16, 2015

Not the most advanced of tutorials, and I'm not overly sure what will happen if someone enters something that's not a number into the boxes, but good start to the forum 🤝

Scratch that, source here: https://tech9tutorialz.wordpress.com/2015/09/16/calculator-tutorial-visual-basic/


* - Cece Drake - Sep 16, 2015

Isn't that the site that copies everything off HackForums?
I didn't copy off anywhere.


* - Josh‎ - Sep 16, 2015

(Sep 16, 2015 03:56 AM)Cece Drake Wrote:  Isn't that the site that copies everything off HackForums?
I didn't copy off anywhere.

I wouldn't know, I just saw the exact same text on another website.


* - Dorks. - Sep 16, 2015

(Sep 16, 2015 05:00 AM)Josh‎ Wrote:  I wouldn't know, I just saw the exact same text on another website.

It is.
Go through the posts and it has everything that HF has


* - VmX5 - Sep 16, 2015

You copied this from another website -.-

And This is not the BEST tut in the world.


* - Cece Drake - Sep 16, 2015

I didn't copy.
please provide a link


* - Jackie Chun - Sep 16, 2015

Lol, what if someone wants to calculate decimals as well? And why did you include empty form load events lol?


* - LijpeMD - Sep 17, 2015

Thanks, I have been looking for a calculator tutorial everywhere!


* - Jackie Chun - Sep 17, 2015

(Sep 17, 2015 02:48 PM)Smell Wrote:  Thanks, I have been looking for a calculator tutorial everywhere!

You didn't know what basic math is? +, -, x, /

You can use an integer to equal math problems. Hope you learned that.


* - nathan72389 - Sep 17, 2015

(Sep 17, 2015 03:17 PM)Jackie Chun Wrote:  You didn't know what basic math is? +, -, x, /

You can use an integer to equal math problems. Hope you learned that.

Your a fucking idiot. You do not know what scarsam is?