1 / 24

Lesson 4

Lesson 4. Mathematical Operators! October 6, 2009. Today’s Agenda. Looking at Vocabulary Words Working with Mathematical Operators Create a Simple Addition Program. Performing Calculations in Visual Basic. Operators Are symbols that perform certain operations in Visual Basic Statements.

faith
Télécharger la présentation

Lesson 4

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

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 Operator Description = Assignment + Addition - Subtraction * Multiplication /(Forward Slash) Division \(Backward Slash)Integer division Mod Modulus

  5. Purpose ofLabel 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! • Open Visual Basic. • Open New Standard EXE project. • In the properties window, give the new form the name frmAddition and the caption Addition. • Insert a label and click the Caption property. • Key in your name for the label. • Name your label lblMyName. • Save the project with the form named frmAddition and project name Addition.

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

  8. What happen? Who can explain?

  9. Working with Mathematical Operators October 7, 2009

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

  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 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! Text –vs-Numeric Data

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

  17. Homework • Make sure you pick up the Homework worksheet before you leave!

  18. Performing Integer Division using Mod! October 8, 2009

  19. Open VB and design the following screen!

  20. Performing Integer Division and Using Mod! Name your form frmDivision. Change the caption of your form to Division. Name the first button to cmdcalculate and second button cmdExit. Name the first text box txtDivisor. Name the second text box txtDividend. Name the first label lblQuotient. Name the third label lblRemainder.

  21. 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?

  22. 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!!!!!!!

More Related