
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 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: 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
(This post was edited by The chael on Apr 2, 2006, 8:52 AM)
|