Free Games Forum
Free Games Games Forums Music Forums TV Forums

  Free Games Forum Home FORUM
HOME
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN
Rules & FAQ RULES / FAQ
REPORT SPAM

Free Games Forum: Game Technology: Visual Basic / VB:
VB 2005 Tutorial: make a basic calculater in VB2005

 

 


The chael
Newbie

Apr 2, 2006, 8:04 AM

Post #1 of 6 (461 views)
Shortcut
VB 2005 Tutorial: make a basic calculater in VB2005 Can't Post

Here I will show you my way of making a calculater in VB 2005. you will need to make: 3 textboxes

4 buttons

keep the default names for all of these...

change the text of the buttons to: Button1 : +

Button2 : -

Button3 : *

Buttons : /

Now, make the buttons farily compact and set-up you form similar to this: [URL=http://imageshack.us]

now, dubleclick on the + button and enter this code


Code
    

Public
Class Form1



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

Dim dblOperand1 As Double = CDbl(TextBox1.Text)

Dim dblOperand2 As Double = CDbl(TextBox2.Text)

Dim dblResult As Double = (dblOperand1 + dblOperand2)

TextBox3.Text = dblResult.ToString

End Sub



Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

Dim dblOperand1 As Double = CDbl(TextBox1.Text)

Dim dblOperand2 As Double = CDbl(TextBox2.Text)

Dim dblResult As Double = (dblOperand1 - dblOperand2)

TextBox3.Text = dblResult.ToString

End Sub



Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click

Dim dblOperand1 As Double = CDbl(TextBox1.Text)

Dim dblOperand2 As Double = CDbl(TextBox2.Text)

Dim dblResult As Double = (dblOperand1 * dblOperand2)

TextBox3.Text = dblResult.ToString

End Sub



Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click

Dim dblOperand1 As Double = CDbl(TextBox1.Text)

Dim dblOperand2 As Double = CDbl(TextBox2.Text)

Dim dblResult As Double = (dblOperand1 / dblOperand2)

TextBox3.Text = dblResult.ToString

End Sub

Now go back to the deign veiw (assuming you have no errors) and debug it.

here is my final version: http://www.thefilehut.com/userfiles/novacode/RS%20Calculater%20V.1.0.1.zip



of course you can add personal touches at the end as you wish like menustrips and labels etc. but this tutorial is making the calculator fullstop.

oh and I would just like to add two peices of code for if you were planning on expanding this or ANy other program:


Code
    

Private
Sub CloseToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CloseToolStripMenuItem.Click

Close()'if you create a menubar and want a "close" option, create that label on the menubar, doubleclick it and enter this code



End Sub



if you create a menubar and want a "close" option, create that label on the menubar, doubleclick it and enter the above code


Code



(This post was edited by The chael on Apr 2, 2006, 8:52 AM)



Jaymzanator
Enthusiast


Apr 2, 2006, 11:43 PM

Post #2 of 6 (447 views)
Shortcut
Re: [The chael] VB 2005 Tutorial: make a basic calculater in VB2005 [In reply to] Can't Post

Why not add an error handler ...


(17:20) Taz:
and tazg is lol'in at you all the way from canada
(17:21) James:
lol canadians


The chael
Newbie

Apr 3, 2006, 12:16 AM

Post #3 of 6 (446 views)
Shortcut
Re: [Jaymzanator] VB 2005 Tutorial: make a basic calculater in VB2005 [In reply to] Can't Post

erm.. yea... as I said I am new to this, I take it an error handler is something that handles errors (wee duh) I don't know the code to make one or anything about them, can u show me?


Jaymzanator
Enthusiast


Apr 4, 2006, 8:09 PM

Post #4 of 6 (439 views)
Shortcut
Re: [The chael] VB 2005 Tutorial: make a basic calculater in VB2005 [In reply to] Can't Post

also instead of this


Code
   

dim bleh as double

dim bleh as long




(17:20) Taz:
and tazg is lol'in at you all the way from canada
(17:21) James:
lol canadians


The chael
Newbie

Apr 5, 2006, 2:21 AM

Post #5 of 6 (435 views)
Shortcut
Re: [Jaymzanator] VB 2005 Tutorial: make a basic calculater in VB2005 [In reply to] Can't Post

Just tried that there now but it doesn't "do" decimel places...

eg. 5 / 4 as double was 1.25----correct

5 / 4 as long is 1----wrong

2.5 x 2 as double was 5----correct

2.5 x 2 as long is 4----very wrong


Jaymzanator
Enthusiast


Apr 5, 2006, 2:36 AM

Post #6 of 6 (434 views)
Shortcut
Re: [The chael] VB 2005 Tutorial: make a basic calculater in VB2005 [In reply to] Can't Post

bah, could try: as short


(17:20) Taz:
and tazg is lol'in at you all the way from canada
(17:21) James:
lol canadians

 
 
 


Search for (options) Web Design by Web Ideas - Page loaded in: 0.16 s on (CGI/1.1)