Chapter 3 ctd Sections 3 3 3 5

  • Slides: 15
Download presentation
Chapter 3 (ctd) Sections 3. 3 - 3. 5 (partial) Input/Output NUMBERS & STRINGS

Chapter 3 (ctd) Sections 3. 3 - 3. 5 (partial) Input/Output NUMBERS & STRINGS

The basic arithmetic operations (for now…) z+ , -, *, /, ^ yorder of

The basic arithmetic operations (for now…) z+ , -, *, /, ^ yorder of precedence: x( ) x^ (or **) x*, / x+, -

Using PICTURE BOXES to display numeric values (Output) z. First, we clear out the

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

The basic plan. . . z. Create a command button & a picture box;

The basic plan. . . z. Create a command button & a picture box; when the user clicks the command button, a value will be displayed in the picture box. z. Write a Command. Button_Click() event procedure containing Picture. Box. Cls & Picture. Box. Print n statements

Variables - use to receive input & intermediate values within a program z. Variables

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

Some Examples: z. Page 80: z# 4, 5, 6, 18, 19, 22 z# 29,

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

The basics about strings z. String constants y“abcdefg”, “ 3”, “? ; #&*!” z.

The basics about strings z. String constants y“abcdefg”, “ 3”, “? ; #&*!” z. String variables yc = “abcdefg” ynumbers = “ 24812”

Using PICTURE BOXES to display character data (Output) z. Use the method Print Picture

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

Variable types z A variable of type string is capable of storing only character

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

Using TEXT BOXES for String Input and Output z. Input: y. You can read

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

Characters, digits & numbers z. Text boxes can contain only string data, so we

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

Concatenation z Two strings can be combined to form a new string. This process

Concatenation z Two strings can be combined to form a new string. This process is called Concatenation and is represented by an ampersand (&) z E. g. z str 1 = “Hi” z str 2=“There” z Pic. Box. Print str 1 & str 2 z The result will be z HIThere (no space)

z. If we want to put a space between the two strings, we must

z. If we want to put a space between the two strings, we must do it manually z. E. g. z. Pic. Box. Print str 1 & “ “ & str 2

Using TEXT BOXES to receive or display numeric results z. Input: y. You can

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

Lab. Due Today z. Page 96 z#27, 30, 32

Lab. Due Today z. Page 96 z#27, 30, 32