Download presentation
Presentation is loading. Please wait.
1
Input Dialog Box An input dialog box can be used to obtain a single item of input from the user Presents a window (dialog box) requesting input Syntax: stringVar = InputBox(prompt, title)
2
Example of an Input Dialog Box Private Sub cmdDisplay_Click() Dim fileName As String, prompt As String, title As String Dim houseNumber As Single, street As String prompt = "Enter the name of the file containing the information." title = "Name of File" fileName = InputBox(prompt, title) Open fileName For Input As #1 Input #1, houseNumber Input #1, street picAddress.Print "The White House is at"; houseNumber; street Close #1 End Sub After executing, an input dialog box will pop up
3
Using Message Dialog Box for Output The message dialog box is used to present a pop-up window containing information for the user Syntax: MsgBox prompt,, title
4
Example of a Message Dialog Box MsgBox “Nice try, but no cigar”,, “Consolation” Stays on the screen until the user presses OK
5
Formatting the Output: Create easily readable output In the Print method, the spacing of the output is controlled by the following devices: semicolon comma Tab function
6
Semicolons The next value output is placed in the next column position. Example: picOutput.Print “Patrick”; ”Jon” Output: PatrickJon
7
Example of Semicolon picOutput.Print “Patrick”; “ Jon” Output Screen: Patrick Jon Space here
8
Example of Semicolon picOutput.Print 100; -200; 300 Output Screen: 100 -200 300 One space Two spaces
9
Commas A comma in a Print method causes the next value output to be placed in the next available print zone. Each print zone is 14 positions wide.
10
Using Commas Example: picOutput.Print “SEE”, ”YOU”, ”SOON” Output Screen: SEE YOU SOON Column 1 Column 15 Column 29
11
Using Commas A print zone can be skipped by typing consecutive commas Example: picOutput.Print “HOURLY”,, “PAY” Output Screen: HOURLY PAY Column 29
12
Tab Function Specifies the column where output will start Use only semicolons with the Tab function Can only be used to advance the print position (cannot move backwards)
13
Example of Tab Function Example: picOutput.Print Tab(3); “Hi there!” ; Tab(25) ;“Bye!” Output Screen: Hi there! Bye! Column 3 Column 25
14
Built-In Functions Take one or more input values and return an output value A means provided by Visual Basic for carrying out small, common tasks Types of Built-In functions Numeric functions (manipulate numbers) String functions (manipulate strings)
15
Numeric Functions
16
Example of Numeric Functions Private Sub cmdEvaluate_Click() Dim n As Single, root As Single n = 6.76 root = Sqr(n) picResults.Print root; Int(n); Round(n,1) End Sub Output: 2.6 6 6.8
17
Commonly-Used String Functions Function: Left(“Penguin”, 4) Purpose: Returns the number of characters specified, starting at the beginning of the string
18
Commonly-Used String Functions Function: Right(“Cork City”, 4) Purpose: Returns the number of characters specified from the end of the string
19
Commonly-Used String Functions Function: Mid(“Commissioner”, 4, 3) Purpose: Returns the substring starting at the position indicated by the first number and continuing for the length specified by the second number
20
Commonly-Used String Functions Function: UCase(“Yes”) Purpose: Converts any lowercase letters in a string to uppercase
21
String-Related Numeric Functions Function: InStr(“John Smith”, “m”) Purpose: Searches for the first occurrence of one string in another and gives the position at which the string is found
22
String-Related Numeric Function Function: Len(“John Smith”) Purpose: Returns the number of characters in the string.
23
Format Functions The format functions provide detailed control of how numbers, dates, and strings are displayed. Examples FormatNumber (12345.678, 1) 12,345.6 FormatCurrency (12345.678, 2) $12,345.68 FormatPercent (.185, 2) 18.50% FormatNumber (1 + Sqr(2), 3) 2.414
24
Format Function Format (expr, “@……..@”) Purpose: The value of this function is the value of expr right justified in a field of n spaces, where n is the number of @ symbols.
25
Format Examples Format(12345, “@@@@@”) 12345 Format(123, “@@@@@”) 123 Format(“123.4”, “@@@@@”) 123.4
26
FormatDateTime Example FormatDateTime (“9-15-04”, vbLongDate) Output: Monday, September 15, 2004
27
Rnd Function Returns a random number from 0 to 1. (excluding 1). Example: picBox.Print Int(6 * Rnd) + 1 Output: Displays a random integer from 1 through 6.
Similar presentations
© 2024 SlidePlayer.com Inc.
All rights reserved.