1 / 15

Chapter 3 (ctd) Sections 3.3 - 3.5 (partial)

Chapter 3 (ctd) Sections 3.3 - 3.5 (partial). Input/Output NUMBERS & STRINGS. The basic arithmetic operations (for now…). + , -, *, /, ^ order of precedence: ( ) ^ (or **) *, / +, -. Using PICTURE BOXES to display numeric values (Output).

sarah
Download Presentation

Chapter 3 (ctd) Sections 3.3 - 3.5 (partial)

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. Chapter 3 (ctd)Sections 3.3 - 3.5 (partial) Input/Output NUMBERS & STRINGS

  2. The basic arithmetic operations (for now…) • + , -, *, /, ^ • order of precedence: • ( ) • ^ (or **) • *, / • +, -

  3. Using PICTURE BOXES to display numeric values (Output) • First, we clear out the picture box, using a method provided for us by Visual Basic: • Cls- used to clear a picture box PictureBox.Cls • Next, we use another method called Print to display the desired number: • Print - used to display a value PictureBox.Print nwhere n is a numeric value

  4. The basic plan... • Create a command button & a picture box; when the user clicks the command button, a value will be displayed in the picture box. • Write a CommandButton_Click() event procedure containing PictureBox.Cls & PictureBox.Print n statements

  5. Variables - use to receive input & intermediate values within a program • Variables are symbols that represent values that have been stored in the computer’s memory. • Ex: x = 5 y = 3 Picture1.Print x; y; x+y; x*y • Vertical & horizontal spacing

  6. Some Examples: • Page 80: • # 4,5,6,18,19,22 • # 29, 30, 33, 34, 35, 36, 37, 38

  7. The basics about strings • String constants • “abcdefg”, “3”, “?;#&*!” • String variables • c = “abcdefg” • numbers = “24812”

  8. Using PICTURE BOXES to display character data (Output) • Use the method Print Picture1.Print “xyz” alpha = “abcdef” Picture1.Print alpha; “ghij”; 7 • Horizontal spacing leaves no blank spaces • Can mix numeric & character data

  9. Variable types • A variable of typestringis capable of storing only character values. • A variable of typesingleis capable of storing only numeric values. • It is good programming practice to declare all variables at the top of the event procedure: Dim x As Single Dim y As String

  10. Using TEXT BOXES for String Input and Output • Input: • You can read character string values into your program from a user’s response in a text box: answer = TextBox.Text • Output: • You can use text boxes to display character string values from your program: TextBox.Text = “15”

  11. Characters, digits & numbers • Text boxes can containonly string data, so we must make use of special Visual Basic functions if we want to use this data in a numeric sense. • Val (“123”) is equal to the number 123 • Str (123) is equal to the string “123”

  12. Concatenation • Two strings can be combined to form a new string. This process is called Concatenation and is represented by an ampersand (&) • E.g. • str1 = “Hi” • str2=“There” • PicBox.Print str1 & str2 • The result will be • HIThere (no space)

  13. If we want to put a space between the two strings, we must do it manually • E.g. • PicBox.Print str1 & “ “ & str2

  14. Using TEXT BOXES to receive or display numeric results • Input: • You can read numeric values into your program from a user’s response in a text box: answer = val(TextBox.Text) • Output: • You can use text boxes to display numeric values from your program: TextBox.Text = str(number)

  15. Lab. Due Today • Page 96 • #27, 30, 32

More Related