Professional Documents
Culture Documents
NET
PROGRAMMING
Functions
Chapter 6:
Objective
Functions
Functions are similar to normal procedures but the main purpose of the
functions is to accept certain inputs and pass them on the main program
to finish execution. There are two types of function, the built-in
functions and the user defined functions. We have encountered using the
built in functions such as the MsgBox function.
Chapter 6:
Functions
InputBox()
An InputBox display a prompt in a dialog box, waits for the user to
input text or click a button, and then returns a string containing the
contents of the text box.
Chapter 6:
Functions
Parts of InputBox Function
1. Prompt – Required String expression displayed as the message in the
dialog box.
2. Title – Optional. String expression displayed in the title bar of the
dialog box. If you omit Title, the application name is placed in the title
bar.
3. DefaultResponse – Optional. String expression displayed in the text
box as the default response if no other input is provided. If you omit
DefaultRespose, the displayed text box is empty.
Chapter 6:
Functions
Parts of InputBox Function
4. XPos – Optional. Numeric expression that specifies, in pixels, the
distance of the left edge of the dialog box from the left edge of the
screen. If you omit XPos, the dialog box is centered on the screen.
5. YPos – Optional. Numeric expression that specifies, in pixels, the
distance of the upper edge of the dialog box is centered on the screen.
Chapter 6:
Sample Program Function
Create a new Windows application and draw a label on it. Leave the
property text as Blank.
Double click on the form and declare a variable such:
Dim yourname As String
On the Form load procedure type the following:
Label1.Text = “Your name is “ + InputBox(“Input your name.”)
Run your program and you will be propted to input name like:
Chapter 6:
Sample Program Function
Chapter 6:
Sample Program Function
Chapter 6:
Sample Program Function
Chapter 6:
Sample Program Function
Chapter 6:
ListBoxes
A list box display a list of items from which the user can select one or
more items. If the number of items exceeds the number that can be
displayed, scroll bar is automatically added.
Chapter 6:
Working with ListBoxes
To add Contents to the Listbox
1. To the Properties Window, choose item and you can directly supply the
contents of your Listbox.
2. To your program, using Listbox.Items.Add(“Items to be Added”)
Chapter 6:
Working with ListBoxes
Chapter 6:
Working with ListBoxes