Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lesson 4 Mathematical Operators! September 29, 2008 (Pages 62-65)

Similar presentations


Presentation on theme: "Lesson 4 Mathematical Operators! September 29, 2008 (Pages 62-65)"— Presentation transcript:

1 Lesson 4 Mathematical Operators! September 29, 2008 (Pages 62-65)

2 Performing Calculations in Visual Basic Operators Are symbols that perform certain operations in Visual Basic Statements

3 Mathematical Operators OperatorDescription =Assignment +Addition -Subtraction *Multiplication /Division \Integer division ModModulus

4 Creating Label Controls Label Control Is used to place text on a form Sometimes is used to identify a text box Sometimes is used to add a title Sometimes is used to add a message Cannot be changed by user Also can be used to provide output

5 Creating some labels! 1.Open Visual Basic. 2.Open New Standard EXE project. 3.In the properties window, give the new form the name frmAddition and the caption Addition. 4.Insert a label and click the Caption property. 5.Key in your name for the label. 6.Name your label lblMyName. 7.Save the project with the form named frmAddition and project name Addition.

6

7 1.Insert another label on the form. 2.Position it in the center of the form. 3.Change the caption of the label to the number zero (0). 4.Change the name of the new label to lblAnswer. 5.Insert a command button. 6.Name the command button cmdCalculate. 7.Change the button’s caption to Calculate. 8.Add code in code view window. lblAnswer.Caption = 16 + 8 9.Close the code view window and run your program.

8

9 What happen? Who can explain?

10 Working with Mathematical Operators October 2, 2008 (Pages 65 – 69)

11 Using Text Boxes and the Val Function Text boxes Are the fields placed on dialog boxes and in other windows that allow the user to enter a value. The text property of a text box specifies what text will appear on the text box.

12 Text –vs-Numeric Data Text Boxes Accept data from the user. Comes in the form of text. Includes letters, symbols, and numbers. Numeric Data Numbers in a text box must be converted to a true numeric value before they can be used in a calculation. The conversion used to convert to numbers is the Val Function!

13 The Val Function Takes numbers that are in a text format and returns numeric value that can be used in calculations. Example: lblTotal.caption = Val(txtPrice.Text) + Val(txtSalesTax.Text)

14 Splitting Code Statements Among Lines When splitting a line of code among two or more lines use a underscore (_)! Example: lblTotal.caption = Val(txtPrice.Text)+_ Val(txtSalesTax.Text) The underscore is called line-continuation character and it tells the compiler to skip to the next line and treat the text there as if it were part of the same line.

15 Comments! The apostrophe ( ‘ ) at the beginning of the code tells the compiler to ignore everything that follows. Example: ‘ Calculate total expenses.

16 Profit and Loss Program 1.Open your profit&loss program.

17

18 Double-click the Calculate button. Add code to Calculate the total expense. 'Calculate Total Expenses lblTotalExp.Caption = Val(txtRent.Text) + _ Val(txtPayroll.Text) + Val(txtUtil.Text) + _ Val(txtSupp.Text) + Val(txtOther.Text)

19 Close the Code Window Save your program. Click the Start button on the standard toolbar to run the program. Key the following: Rent350 Payroll600 Utilities200 Supplies 100 Other 50 Click the Calculate button.

20 Homework Bring your program back. Worksheet!


Download ppt "Lesson 4 Mathematical Operators! September 29, 2008 (Pages 62-65)"

Similar presentations


Ads by Google