VISUAL BASIC : VISUAL BASIC Chapter-9
Presented by R.SHANTHIVICTORIA : Presented by R.SHANTHIVICTORIA
Contents : Contents Functions in Visual Basic
Simple controls
Command buttons
Textboxes
Labels
Drive list box Directory list box
File List box
List box
Combo box
Check box
Timer Control
Function Procedures : Function Procedures A Function procedure is a series of Visual Basic statements enclosed by the Function and End Function statements. The Function procedure performs a task and then returns control to the calling code. When it returns control, it also returns a value to the calling code.
Function Procedures(continued) : Function Procedures(continued) Declaration Syntax of Function Procedure
The syntax for declaring a Function procedure is as follows:
[modifiers] Function funcname [(paramlist)] As returntype
' Statements of the Function procedure.
functionname = expression
Return expression
End Function
Data TypeEvery Function procedure has a data type. This data type is specified by the As clause in the Function statement, and it determines the data type of the value the function returns to the calling code.
Returns control to the code that called a Function, Sub, Get, Set, or Operator procedure
Calling Function Procedure : Calling Function Procedure You invoke a Function procedure by including its name and arguments either on the right side of an assignment statement or in an expression. You must provide values for all arguments that are not optional, and you must enclose the argument list in parentheses. If no arguments are supplied, you can optionally omit the parentheses.
The syntax for a call to a Function procedure :
[ modifiers]Sub objectname_eventname [(parameterlist )]
varname = functionname [( argumentlist )]
End Sub
Example of Function Procedure : Example of Function Procedure Public Function Sum(ByRef a As Double, ByRef b As Double) As Double
Sum = a + b
Return sum
End Function
Private Sub command1_click()
csum= sum(10,20)
Print csum
End Sub
VISUAL BASIC PROGRAMMING : VISUAL BASIC PROGRAMMING Getting started with VB
VISUAL BASIC PROGRAMMING(continued) : VISUAL BASIC PROGRAMMING(continued) Click StartProgramsMicrosoft VisualStudio (or) Microsoft Visual Basic
Click Visual Basic Application to open Microsoft Visual Basic
Microsoft Visual Basic opens the “New Project “Template
VISUAL BASIC PROGRAMMING(continued) : VISUAL BASIC PROGRAMMING(continued) File-->NewStandard Exe
Select the proper template depending on the application and click open. : Select the proper template depending on the application and click open.
VISUAL BASIC PROGRAMMING(continued) : VISUAL BASIC PROGRAMMING(continued) Form:
Any object in VB can be executed only if you have placed controls on the form.
It is called as Platform
It can be saved as .FRM extension.
TOOL BAR : TOOL BAR Assist you to work with this environment easily and quickly.
It is in the form of Collections of icons.
4 types:
Debug
Edit
Form Editor
Standard
Properties Window : Properties Window It displays properties of all the controls that you can place on the form.
It allows the user to change the values according to the application without remembering every properties.
Project Explorer Window : Project Explorer Window It list the environment
Where you are currently working.
The information displayed in this window is also called as content of VB project.
Form Layout : Form Layout It shows the preview of the form windows location during design time while running the project.
ToolBox : ToolBox It has various controls that you can place on the form.
Code Builder : Code Builder Double click on the control , You can see the Code Builder window with event procedure for the selected control.
Parts of the Code Builder : Parts of the Code Builder
Saving the project. : Saving the project.
Saving the project. : Saving the project.
COMMAND BUTTON : COMMAND BUTTON CommandButton is a control that you press to tell a VB application to perform a particular task.
COMMAND BUTTON(continued) : COMMAND BUTTON(continued)
COMMAND BUTTON(continued) : COMMAND BUTTON(continued)
COMMAND BUTTON(continued) : COMMAND BUTTON(continued)
TEXTBOX CONTROL : TEXTBOX CONTROL TextBoxes accepts text input such as the users name or address.
TEXTBOX CONTROL Properties : TEXTBOX CONTROL Properties
TEXTBOX CONTROL Properties : TEXTBOX CONTROL Properties
TEXTBOX CONTROL Properties : TEXTBOX CONTROL Properties
Labels : Labels Labels hold text that appears on the Form.� Labels cannot be edited directly � an explicit code assigning a new caption to the Label should be carried out.� You use a Label, as its name obviously implies, to label a control, to provide instructions, etc.
Labels (continued) : Labels (continued)
Labels (continued) : Labels (continued)
Labels (continued) : Labels (continued)
Drive List Box : Drive List Box Used to display drives available on your system.
The default property for this control is “name”.
Directory List box : Directory List box Used to list out the directories in your drives.
The default property for this control is “name”.
File List box : File List box Used to list out the files available in your directories.
The default property for this control is “Archive”.
List Box : List Box ListBox gives the user a choice of several values.
The user selects an option instead of typing a value into a Textbox.
The ListBox ensures that the user always chooses one of the available options.
The contents of the ListBox may be set at design time or at runtime.
List Box(continued) : List Box(continued)
List Box(continued) : List Box(continued)
List Box(continued) : List Box(continued)
Methods supported by ListBoxes : Methods supported by ListBoxes
List Box(continued) : List Box(continued) How do I add an item to a ListBox?
There are two ways. One is by entering items in the List property of a ListBox. The other way is by executing the statement:
How do I remove an item to a ListBox?
Each item in a ListBox is associated with a subscript or index. The first item has a subscript 0, while the nth has subscript n-1. Execute the following to remove the first item.
List Box(continued) : List Box(continued) How do I remove all items in a ListBox?
Just execute the statement:
ListCourses.Clear
How do I know how many items are there in a ListBox?
The expression ListCourses.ListCount returns the total number of items in the ListBox named ListCourses.
How do I know if an item is selected or not?
Use the Selected method. If you want to know if the first item is selected, the expression ListCourses.Selected(0) returns True if item 0 is selected; otherwise, it returns False.
COMBO BOX : COMBO BOX ComboBoxes work much like ListBoxes except that these may allow the user to add items to a ComboBox at runtime through a built-in TextBox. VB has three kinds of ComboBoxes. All the properties of a ListBox apply to a ComboBox.
Here are the three kinds of ComboBoxes: : Here are the three kinds of ComboBoxes:
The Form below displays the three kinds. : The Form below displays the three kinds.
CHECK BOX : CHECK BOX It is used to select multiple choices by the
User from the application.
The default property for this control is “Caption”
Check Box Properties : Check Box Properties Properties
Value-0,1,2
0, the CheckBox is currently unchecked.
1, the CheckBox is checked. The CheckBox is disabled if this value is equal to 2.
Style-Standard Checkbox
Graphical Checkbox
TIMER CONTROL : TIMER CONTROL The Timer control works in the background . you do not see it on the Form at runtime.The primary purpose of a Timer is to trigger an event at a certain interval.
Properties of a Timer. : Properties of a Timer.
THANK YOU : THANK YOU 51