Download presentation
Presentation is loading. Please wait.
1
Chapter 3 (ctd) Sections 3.3 - 3.5 (partial) Input/Output NUMBERS & STRINGS
2
The basic arithmetic operations (for now…) z+, -, *, /, ^ yorder of precedence: x( ) x^ (or **) x*, / x+, -
3
Using PICTURE BOXES to display numeric values (Output) zFirst, we clear out the picture box, using a method provided for us by Visual Basic: yCls - used to clear a picture box PictureBox.Cls zNext, we use another method called Print to display the desired number: yPrint - used to display a value PictureBox.Print n where n is a numeric value
4
The basic plan... zCreate a command button & a picture box; when the user clicks the command button, a value will be displayed in the picture box. zWrite a CommandButton_Click() event procedure containing PictureBox.Cls & PictureBox.Print n statements
5
Variables - use to receive input & intermediate values within a program zVariables are symbols that represent values that have been stored in the computer’s memory. zEx:x = 5 y = 3 Picture1.Print x; y; x+y; x*y zVertical & horizontal spacing
6
Some Examples: zPage 80: z# 4,5,6,18,19,22 z# 29, 30, 33, 34, 35, 36, 37, 38
7
The basics about strings zString constants y“abcdefg”, “3”, “?;#&*!” zString variables yc = “abcdefg” ynumbers = “24812”
8
Using PICTURE BOXES to display character data (Output) zUse the method Print Picture1.Print “xyz” alpha = “abcdef” Picture1.Print alpha; “ghij”; 7 zHorizontal spacing leaves no blank spaces zCan mix numeric & character data
9
Variable types zA variable of type string is capable of storing only character values. zA variable of type single is capable of storing only numeric values. zIt 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 zInput: yYou can read character string values into your program from a user’s response in a text box: answer = TextBox.Text zOutput: yYou can use text boxes to display character string values from your program: TextBox.Text = “15”
11
Characters, digits & numbers zText 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. yVal (“123”) is equal to the number 123 yStr (123) is equal to the string “123”
12
Concatenation zTwo strings can be combined to form a new string. This process is called Concatenation and is represented by an ampersand (&) zE.g. zstr1 = “Hi” zstr2=“There” zPicBox.Print str1 & str2 zThe result will be zHIThere (no space)
13
zIf we want to put a space between the two strings, we must do it manually zE.g. zPicBox.Print str1 & “ “ & str2
14
Using TEXT BOXES to receive or display numeric results zInput: yYou can read numeric values into your program from a user’s response in a text box: answer = val(TextBox.Text) zOutput: yYou can use text boxes to display numeric values from your program: TextBox.Text = str(number)
15
Lab. Due Today zPage 96 z#27, 30, 32
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.