80 likes | 94 Views
Learn how to use input boxes to receive data from users and message boxes to display output. Examples and formatting options included.
E N D
Section 3.5 - Schneider • This section introduces nice ways to produce input & display output: • Input boxes • Message boxes
Input Boxes (Section 3.5) • An input box is an object that appears on the form solely for the purpose of receiving data to the program. Once the data is entered by the user, the box disappears. • str_var = InputBox(prompt,title) Variable to receive input data Caption Identifies the object Instruction to user
Private Sub Command1_Click() Dim Char As String, message1 As String Dim message2 As String Dim x As Single Picture1.Cls message1 = "Please enter a character string" message2 = "Please enter a 3-digit number" Char = InputBox(message1,”Character input”) x = Val(InputBox(message2,”Numeric input”)) Picture1.Cls Picture1.Print Char Picture1.Print x * 2 End Sub
Notes on Input boxes • We can use an input box if we want a user to provide input data to a program. The input boxappears when an event procedure invokes it and it disappears when the user clicks on OK or presses the Enter key. • The data entered is character string type. • Compare an input box to a text box
Message Boxes • Same idea as input boxes; object appears for the purpose of displaying output and then it disappears from sight. • MsgBoxprompt,, title • MsgBox “Better luck next time”, , “Hello” Identifies the object Message to user Caption
Formatting Output • Vertical - Each PictureBox.Print causes a new line to display; no argument causes a line skip • Horizontal - • ; or , print zones (p. 104) • Tab(n) - nth position of line (p. 105) • Spc(n) insert n spaces • Format (pp. 122 - 124)
Today’s Lab • Page 116 #49, 51
Homework Assignment (HW4) • Due next Tuesday • Page 117 #53. There is no input. Write code to calculate the total. Display the results in a picture box. • Page 117 #54. Make a command button and a picture box. When the button is clicked an input box appears. The user should enter the amount of the bill. Another input box then appears to collect the percentage tip. Display the results in the picture box.