27
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)

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:

  • View
    218

  • Download
    0

Embed Size (px)

Citation preview

Page 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:

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)

Page 2: 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:

Example of an Input Dialog BoxPrivate 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 inputdialog box will pop up

Page 3: 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:

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

Page 4: 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:

Example of a Message Dialog Box

MsgBox “Nice try, but no cigar”, , “Consolation”

Stays on thescreen until the user presses OK

Page 5: 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:

Formatting the Output:

Create easily readable output In the Print method, the spacing of the

output is controlled by the following devices:semicoloncommaTab function

Page 6: 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:

Semicolons

The next value output is placed in the next column position.

Example:

picOutput.Print “Patrick”; ”Jon”

Output:

PatrickJon

Page 7: 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:

Example of Semicolon

picOutput.Print “Patrick”; “ Jon”

Output Screen:

Patrick Jon

Space here

Space here

Page 8: 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:

Example of Semicolon

picOutput.Print 100; -200; 300

Output Screen:

100 -200 300

One space

Two spaces

Page 9: 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:

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.

Page 10: 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:

Using Commas

Example:

picOutput.Print “SEE”, ”YOU”, ”SOON”

Output Screen:

SEE YOU SOON

Column 1

Column 15

Column 29

Page 11: 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:

Using Commas

A print zone can be skipped by typing consecutive commas

Example:

picOutput.Print “HOURLY”, , “PAY”

Output Screen:

HOURLY PAYColumn 29

Page 12: 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:

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)

Page 13: 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:

Example of Tab Function

Example: picOutput.Print Tab(3); “Hi there!” ; Tab(25) ;“Bye!”

Output Screen:

Hi there! Bye!

Column 3

Column 25

Page 14: 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:

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 functionsNumeric functions (manipulate numbers)String functions (manipulate strings)

Page 15: 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:

Numeric Functions

Rnd Returns a number between 0 and 1 (excluding 1)

Sqr(n) Returns the square root of the number n

Round(n,r) Returns the number n rounded to r decimal places

Int(n) Returns the greatest integer less than or equal to the number n

Page 16: 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:

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

Page 17: 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:

Commonly-Used String Functions

Function: Left(“Penguin”, 4)

Purpose: Returns the number of characters specified, starting at the beginning of the string

Page 18: 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:

Commonly-Used String Functions

Function: Right(“Cork City”, 4)

Purpose: Returns the number of characters specified from the end of the string

Page 19: 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:

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

Page 20: 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:

Commonly-Used String Functions

Function: UCase(“Yes”)

Purpose: Converts any lowercase letters in a string to uppercase

Page 21: 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:

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

Page 22: 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:

String-Related Numeric Function

Function: Len(“John Smith”)

Purpose: Returns the number of characters in the string.

Page 23: 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:

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

Page 24: 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:

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.

Page 25: 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:

Format Examples

Format(12345, “@@@@@”) 12345

Format(123, “@@@@@”) 123

Format(“123.4”, “@@@@@”) 123.4

Page 26: 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:

FormatDateTime Example

FormatDateTime (“9-15-04”, vbLongDate)

Output: Monday, September 15, 2004

Page 27: 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:

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.