Presentation is loading. Please wait.

Presentation is loading. Please wait.

New Project in Visual Basic Please use speaker notes for additional information!

Similar presentations


Presentation on theme: "New Project in Visual Basic Please use speaker notes for additional information!"— Presentation transcript:

1 New Project in Visual Basic Please use speaker notes for additional information!

2 New Project This project is called Project1 by default and the form is called Form1 by default. The properties are showing the default properties for the form.

3 New Project I clicked on Project1 in the Project Window and the project was brought up in the Properties window. I then entered the new name under Name. The project is now called New Project. Notice that it also appears on the window above the form.

4 New Form I clicked on Form 1 under Forms which is under NewProject and this brought up the properties for the form. I then named the form NewForm.

5 Putting on a label The first thing I want to put on the form is a label box. I drag and drop and reposition it to the place where I want it. The properties are then used to name the label box and make other property changes. Note that the … when I click on font means that more information is available if you click on the … This brought up the font window.

6 Another label

7 Text Box This is a textbox that I named txtFirst. txtFirst was keyed into the Name property which does not show because I have scrolled past it.

8 Button I have now established a command button which I named cmdCalc. I will now need to write the code to make clicking on cmdCalc cause the addition of the numbers in txtFirst and txtSecond and the display of the answer in txtTotal.

9 Button - click event The code shown below is the code that will be executed when the Calculate button is clicked. Note that you can see that this is a subroutine that is executed when cmdCalc is clicked and you can also see the button and the event in separate windows.

10 Run/Execute To Run or Execute, click on Run. The form will come up in Run/Execute mode. I then entered the two numbers and clicked the Calculate button which calculated and showed the results.

11 ProArith

12 VB for ProArith

13 Option Explicit Private Sub cmdAdd_Click() txtTotal = Val(txtNum1) + Val(txtNum2) End Sub Private Sub cmdClear_Click() txtNum1 = " " txtNum2 = " " txtTotal = " " txtNum1.SetFocus End Sub Private Sub cmdDiv_Click() txtTotal = Val(txtNum1) / Val(txtNum2) End Sub Private Sub cmdExit_Click() End End Sub Private Sub cmdMult_Click() txtTotal = Val(txtNum1) * Val(txtNum2) End Sub Private Sub cmdSubt_Click() txtTotal = Val(txtNum1) - Val(txtNum2) End Sub VB Adds the contents of txtNum1 which is converted to a number and txtNum2 which is also converted and assigns the results to the txtTotal box. Sets all of the boxes back to spaces and then sets the focus (puts the cursor) in txtNum1. The End statement will stop the processing of the form. txtNum1 is divided by txtNum2 and the results are assigned to txtTotal. These two events are to multiply and subtract. Note that the multiply uses the *.

14 Run ProArith The SUBTRACT button was clicked.

15 ProArith1 Option Explicit Private Sub cmdAdd_Click() txtTotal.Text = Val(txtNum1.Text) + Val(txtNum2.Text) End Sub Private Sub cmdClear_Click() txtNum1.Text = " " txtNum2.Text = " " txtTotal.Text = " " txtNum1.SetFocus End Sub Private Sub cmdDiv_Click() txtTotal.Text = Val(txtNum1.Text) / Val(txtNum2.Text) End Sub Private Sub cmdExit_Click() End End Sub Private Sub cmdMult_Click() txtTotal.Text = Val(txtNum1.Text) * Val(txtNum2.Text) End Sub Private Sub cmdSubt_Click() txtTotal.Text = Val(txtNum1.Text) - Val(txtNum2.Text) End Sub.Text after the textbox name says that we are specifically interested in the Text property of the box.


Download ppt "New Project in Visual Basic Please use speaker notes for additional information!"

Similar presentations


Ads by Google