Sie sind auf Seite 1von 37

INPUT & OUTPUT BOX

INPUT & OUTPUT BOX


Input and Output box are the built-in functions (or internal functions) created in Visual Basic.

INPUT BOX
An input box is a specially designed dialog box that allows the programmer to request a value from the user and use that value as necessary.

The Interface
Title bar

Command Button

Message/ prompt

Text box

Command Button

INPUT BOX
It contains: A message/prompt - to indicate the requested value.
A textbox for user to enter data.
2 command buttons (Ok, Cancel) - used to

accept or cancel input data. A Title to show the title of the input box

SYNTAX/CODE
InputBox (prompt, title , default option , x position, y position)
Argument Description

Prompt Title Default option

String expression displayed as the message in the dialog box. It is required. String expression displayed in the title bar of the dialog box. String expression displayed in the text box as the default response if no other input is provided. If you omit default option, the text box is displayed empty. Numeric expressions that specify custom positioning of the box on screen.

x position, y position

Lets try to apply the inputbox function


Design the application as shown below:

Command button Name : cmdInput Caption : Input Label name : lblShow Caption : Show Name Here

Now, we can use the inputbox function


Double click button

and write

the following code:


Dim Nama As String

Nama = InputBox(Enter your full name: )


Run your program

1. Click Input button

Then the input box will appear as shown below

Message/prompt

Lets try to add title to the input box


Stop your program, back to your coding and add

the following blue colour code:


InputBox(Enter your full name: , Input Name )
Run your program again and find the changes that

happen in the input box

The title will change

Lets try to add default option to the input box


the default option will display a default value in the

textbox of the input box. Stop your program, back to your coding and add the following blue colour code:
InputBox(Enter your full name: , Input Name , UPPER CASE ONLY)
Run your program again and find the changes that

happen in the input box

Default value

Lets try to add position to the input box


Stop your program, back to your coding and add

the following blue colour code:


InputBox(Enter your full name: , Input Name , , UPPER CASE ONLY , 10,3000)
Run your program again.

What happen to the input box?

The code will change the position of the input box

So, the syntax of the input box function is:


InputBox(Prompt, title, default option,x position, y position)

Lets continue our exercise

How to show your name on the label you created before?

Stop your program, back to your coding and add

the following code. Make sure you add the code after the Inputbox function code. lblShow.Caption = nama
Run your program again.

2. Enter your name 3. Click button OK

1. Click button input

Whatever you entered in the textbox will appear here

OUTPUT BOX
The function of Output box :

Display information to the user. A useful dialog box function for displaying output is the MsgBox (Message box)

Title bar message

Icon

Button

SYNTAX/CODE
MsgBox(Message) , Button type + icon type ,title
Argument Description

Message Button , icon

String expression displayed as the message in the Message box. It is required Numeric expression that is the sum of values specifying the number and type of buttons to display and the icon style to use.

title

String expression displayed in the title bar of the dialog box. If you omit title, the application name is placed in the title bar.

Lets try to apply the outputbox function


Continue the previous exercise (input box). Apply

the following code. Make sure you write the code below the previous code (lblShow.Caption = nama) MsgBox(Hello )
Run your program

The pop up message will appear as shown below

Button & Icon in the outputbox function

BUTTON
0 1 2 3

4
5

ok ok, Cancel Abort, Retry, Ignore Yes, No, Cancel Yes, No Retry, Cancel

ICON
16 32 48

64

Lets try to apply button & icon in the outputbox function


Stop your program, back to your coding and add

the following blue colour code:


MsgBox(Hello ) , 3 + 32
Run your program.

Icon

Button

Lets try to add title in the outputbox function


Stop your program, back to your coding and add

the following blue colour code:


MsgBox(Hello ) , 3 + 32 , Message Box
Run your program.

The title will appear here

So, the syntax of the output box function is:


MsgBox(Message) , button+icon, title

How to add name in the Output box

Stop your program, back to your coding and add

the following blue colour code:

MsgBox(Hello ) & nama , 3 + 32 , Message Box


Run your application

Thats all for today Thank you!

Das könnte Ihnen auch gefallen