Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lesson 4 Mathematical Operators! October 6, 2009.

Similar presentations


Presentation on theme: "Lesson 4 Mathematical Operators! October 6, 2009."— Presentation transcript:

1 Lesson 4 Mathematical Operators! October 6, 2009

2 Today’s Agenda Looking at Vocabulary Words Working with Mathematical Operators Create a Simple Addition Program

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

4 Mathematical Operators OperatorDescription =Assignment +Addition -Subtraction *Multiplication / (Forward Slash) Division \ (Backward Slash) Integer division ModModulus

5 Purpose of 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

6 Let’s create our example program! 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.

7

8 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.

9

10 What happen? Who can explain?

11 Working with Mathematical Operators October 7, 2009

12 Note! Hard-coded values –The term hard-coded refers to information that is entered directly into the source code and cannot change while the program runs. –Example: lblAnswer.Caption = 16 + 8

13 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.

14 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!

15 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)

16 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.

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

18 Fix Function There are times when you are interested in only whole numbers after a calucation is performed. Use the Fix Function! –Drops the fractional part of a number. –In other words, it removes everything to the right of the decimal point which is called truncation. –Returns the truncated whole number.

19 Homework Make sure you pick up the Homework worksheet before you leave!

20 Performing Integer Division using Mod! October 8, 2009

21 Open VB and design the following screen!

22 Performing Integer Division and Using Mod! 1.Name your form frmDivision. 2.Change the caption of your form to Division. 3.Name the first button to cmdcalculate and second button cmdExit. 4.Name the first text box txtDivisor. 5.Name the second text box txtDividend. 6.Name the first label lblQuotient. 7.Name the third label lblRemainder.

23 Double click the calculate button. Enter the following code: 'Calculate Quotient lblQuotient.Caption=Val(txtDividend.Text) \ Val(txtDivisor.Text) 'Calculate Remainder lblRemainder.Caption = Val(txtDividend.Text) Mod Val(txtDivisor.Text) Run your program! What happens?

24 Worksheet! Create the program on your worksheet! Save to your flash drive. Bring back tomorrow for coding! Don’t forget to turn in your homework before you leave!!!!!!!


Download ppt "Lesson 4 Mathematical Operators! October 6, 2009."

Similar presentations


Ads by Google