Download as pdf or txt
Download as pdf or txt
You are on page 1of 21

Standard EXE ● selection menu for controls used in

● Contains at least 6 windows inside the the VB application form at design


Main Window - consists of: time thereby creating the user
interface area
● default Toolbox Window: only
displays the most common
collection of toolbox controls or
tools
● additional controls can be included
in the toolbox by using the
Components menu item on the
Project menu

○ Title bar - indicates the project


name, the current Visual Basic
operating mode, and the current
form working on
○ Menu bar - has drop-down menus
used to control the operation of the
Visual Basic environment and
displays the commands that are
required to build an application
○ Toolbar - collection of icons that
provide shortcuts to some of the
menu options and carry out
standard operations when clicked
Control Name Function

Pointer Provides a way to move and resize the


form and its controls

Picture box Displays icons/bitmaps, metafiles, or text


and acts as a visual container for other
controls

Display text that user cannot modify or


Label interact with and commonly used as a
caption to the function of a control

Text box Display message and accept an input


value to end user

Frame A visual and functional container for


Note: The menu bar and the toolbar contain controls in groups
commands for developing, maintaining, and Command Carry out the specified action when
executing a program. The menu bar contains a button pressed or clicked
group of related capabilities from which the user
Checkbox Provides user with choice(s) and display
may select appropriately. The toolbar on the True/False or Yes/No option
other hand provides shortcuts to the commands
from the menu bar. Option button Aka radio button; allows the user to
select only 1 option

6 Windows Contains text box and a list box


Combo box Allows user to select an item from the
1) Toolbox Window
dropdown list box, or to type in a
● Found at the left side of the VB selection in the textbox
screen
List Box Display list of items user can select one
Horizontal ○ View Code
Scroll Bar Allows user to select a value within the ■ view of the Code
specified range of values Window that
Vertical Scroll
Bar contains the actual
basic coding
Executes the timer events at specified
■ lists code modules
Timer intervals of time (not visible to the user at
run-time) and classes
○ View Object
displays the valid disk drives and allows
Drive List Box the user to select and access one of ■ view of the Form
them Designer Window
○ Toggle Folders
Directory List allows the user to select and access the
Box directories and paths, which are ■ toggles the forms
displayed folder
File List Box displays a set of files user can select and
access the desired one 3) Properties Window

Shapes used to add or draw a shape (rectangle,


square, or circle) to a form

Lines used to draw a straight line to the form

used to display images such as icons,


Image Box bitmaps, and metafiles but has less
capability than the picture box

Data enables user to connect to an existing


database and display information from it

Object used to link or embed an object, display


Linking and manipulate data from other
Embedding windows-based applications

● docked under the Project Explorer window


2) Project Explorer Window and above the Form Layout Window
● exposes the properties
○ various characteristics or attributes
of selected objects in a form
○ characteristics of a control affect
not just the appearance of the
object but the way it behaves too
○ used to establish initial property
values for objects or controls
● drop-down box at the top of the window
known as the control box lists all objects in
the current form showing available
properties for the currently selected object
● docked on the right side of the
● properties are viewed:
screen, just under the toolbar
○ Alphabetic order - the properties or
● serves as a quick reference to the
attributes of a selected control or
various elements of a project
form are listed in alphabetical order
namely form, classes, and
○ Categorized order - the properties
modules, which are the actual
are categorically listed
project files
○ objects that make up the
application are packed in a
project
● contains three buttons:
4) Form Layout Window ● Object Box displays the name of the
control that will trigger the event
● Procedure Box specifies the type of
event for the control
● Private indicates that the procedure is
solely for the selected object and form
● Control Name indicates the control that
will do the event
● Event indicates the event or action that
should occur to the object or control
● Sub on the first line indicates the
beginning of the event procedure
● shows the position of the form relative to
● End Sub or the last line indicates the
the monitor’s screen upon program
termination of the event procedure
execution
● click the form inside this window and drag
Object Browser
it to the position where you want it

5) Form Designer Window

● allows the programmer to browse through


● central to developing Visual Basic the various properties, events, and
applications methods that are made available
● where the programmer draws the ● accessed by selecting Object Browser
application from the View menu or pressing the key
F2 or clicking the Object Browser icon in
the toolbar
6) Code Window ● left column of the Object Browser lists the
objects and classes that are available in
the projects that are opened and the
controls that have been referenced in
them
● possible to scroll through the list and
select the object or class that wishes to be
inspected
○ object is picked up from the
Classes list, the members
● where the codes or procedures for an (properties, methods, and events)
application are encoded are displayed in the right column
○ property is represented by a small
Note: icon that has a hand holding a
piece of paper
○ Methods are denoted by little Naming Controls
green blocks, while events are ● Names can be 40 character long
denoted by the yellow lightning bolt ● Must start with letter and contain only
icon letters numbers and underscore
● Names
Visual basic operates in 3 Modes ○ used by Visual Basic to refer to a
1) Design mode - used to build an particular control in code
application ○ used in setting properties at run
2) Run mode - used to run or execute the time and also in establishing
application procedure names for control
3) Break Mode - used to halt the application events
and make the debugger available for ○ used by Visual Basic to set up a
debugging or editing framework of event-driven
procedures to add code to

Structure of Visual Basic Application


Control Prefixes

Form frm

Image Box img

Picture Box pic

Label lbl

Text Box txt

● Forms - windows that the programmer Frame fme


creates for the user interface Command Button cmd
● Control - graphical features drawn on
forms to allow user interaction like text Checkbox chk
boxes, labels, scroll bars, command
Option Button opt
buttons
● Properties - every characteristic of a form Combo Button cbo
or a control that is specified by the
List Box lst
property like names, captions, size, color,
position, and contents Horizontal Scroll Bar hsb
● Methods - built-in procedure invoked to
Vertical Scroll Bar vsb
impart some action to a particular object
● Event Procedures - codes related to Shape shp
some object executed when a certain
event occurs Line lin
● General Procedures - codes not related
to objects and must be invoked by the
application Setting Control Properties
● Modules - collection of general ● run time changing: use dot notation
procedures, variable declarations, and ○ Syntax:
constant definitions used by an application ControlName.Property = NewValue

Steps in Developing VB Application


1) Draw user interface
2) Assign properties to controls
3) Attach code to controls
Adding Code or Procedure to an Event
Element Color

Comment Green

Syntax Error Red

Control Name and Black


Property

● Event - user’s action Comment Procedure


● Code - statement that carries out the ● code that is not executed by Visual basic
action when the event is triggered as the program is set into the runtime
● Event Procedure - adding a code in an ● serves as a bookmark or remarks which
event indicate the description of the code

Common Control Event Saving Project


Event Description ● .frm - extension name for form file
● .vbp - extension name for project file
Activate occurs when forms get a focus

Click occurs when the user clicks Modules - code in VB is stored in this form
anywhere on the form or control
3 Kinds on Modules
Initialize occurs when the form is first 1) Form Modules
generated a) simple application may contain a
single Form, and the code resides
Load occurs when the form is loaded
into the computer’s memory and in that Form module
displays on the screen b) As application grows, additional
Forms are added and there may
Dblclick occurs when the user be a common code to be executed
double-clicks the form or control in several Forms
Deactivate occurs when another form gets
the focus 2) Standard Modules
a) a separate module containing a
Unload occurs when the form is procedure created to implements
terminated from the computer’s the common code to avoid
memory
duplication of code
Resize occurs when the user changes
the size of a form 3) Class Modules
a) .CLS file name extension
Change occurs when the user changes b) foundation of object-oriented
the text inside a textbox
programming in Visual Basic
c) new objects can be created by
Procedure - section in the code window that writing code in class modules
holds assignment statements for control to d) Each Module can contain:
perform a specific task or action 1) Declarations - include
constant, type, variable,
Syntax - set of rules defining the proper use of and DLL procedure
programming language declarations
2) Procedures - sub function,
Syntax Error - result of violation of any of the or property procedure that
programming language rules contains pieces of code
that can be executed as a VB Data
unit ● Numeric - holds whole numbers
○ Integers - whole numbers and
The rules in naming elements in VB - variables, without decimal points
constants, controls, procedures, and so on: ○ Decimal - holds numbers with
1) A name must begin with a letter. decimal points that usually
2) Maybe as much as 255 characters long represent fractional values
3) Must not contain a space or an embedded ● Nonnumeric
period or typedeclaration characters used ○ Boolean - yes/no, true/false
to specify a data type; these are !, #, %, $, ○ String
&, and @. ○ Variant
4) Must not be a reserved word. ■ Data that can hold any kind
5) The dash, although legal, should be of data except for
avoided because it may be confused with fixed-length strings
the minus sign. ■ used as a storage area
when there is a need to
hold different kinds of data
Arithmetic Operators
● Follows EMDAS
Operation Symbol Notation

Addition + a+b

Subtraction - a-b

Multiplication * a*b

Division / a/b
(Floating)

Division | a\b
(Integer)

Exponentiation ^ a^b

String + & String1 + String 2


Concatenations String1 & String 2

Remainder of mod a mod b


Division

Logical Operators
Variables ● Syntax:
● inserted as code statements Dim VariableName As DataType
● temporarily named storage areas inside Dim Var1, Var2, Var3 As DataType
the program’s memory that will hold data

Variable Declaration
● may declared in 2 locations:
○ General declarations - variables
declared here can be used within
the project but not in other parts of
the program
○ Option explicit statement - tells
Visual Basic that the rest of the
code in a module is to declare all
variables before they are used
● can be declared as:
○ implicit declaration
○ explicit declaration
○ option explicit
○ scope variables
Implicit Declaration
Option Explicit Declaration
● Assigns default variable type and value
● forces the user to declare all the variables
● Syntax:
● Option Explicit statement checks in the
variablenameSuffic = value
module for the usage of any undeclared
variables and reports an error to the user

Scope of Variable
● scope of a variable, procedure, or object
determines which part of the code in our
application is aware of the variable's
existence
● variable is declared in the general
declaration section of a Form and hence is
available to all the procedures
● Types:
○ procedure-level (local)
■ recognized only in the
procedure in which they are
declared
■ the values of its local
variables are lost and the
memory used by these
variables is freed and can
Explicit Declaration be reclaimed after the
● user has more control in manipulating the execution of procedure
variables ■ only available to the code
● variables are declared with a Dim inside the procedure and
statement to name the variable and its can be declared using the
type Dim statements
● As type clause in the Dim statement
allows defining the data type or object
type of the variable
○ Static
■ reinitialized each time
Visual Basic invokes a
procedure and therefore
retains or preserves value
even when a procedure
end
■ ideal for making controls
alternately visible or
invisible
■ Syntax: Constant Variable
Static VariableName As DataType ● variable whose value cannot be changed
● 2 kinds
○ Intrinsic or symbolic
■ commonly used features
are prefixed with vb
■ vbYesNo, vbOkOnly,
vbBlue, vbBackcolor,
vbChecked
○ Module-level ○ User-defined
■ available to all the ■ constants defined by
procedures in the module programmers
■ declared using the Public or ■ Syntax:
the Private keyword Const ConstantName = Value
■ Private module-level ■ Example:
● variable is declared Const PI = 3.14159
using a Private or a Global Const PI = 3.14159
Dim statement in
the declaration Sub Procedures
section of a ● placed in standard, class, and form
module—a standard modules
BAS module, a form ● when called, the statements between Sub
module, a class and End Sub are executed
module, and so on ● Syntax:
● visible only from [Private|Public] [Static] Sub ProcedureName (arglist)
. . .statement block…
within the module
End Sub
they belong to and
can't be accessed
Types of SP
from the outside
● Event Procedures
■ Syntax
○ procedure block that contains the
Public/Private VariableName As DataType
control's actual name, an
underscore (_), and the event
name
○ Example:
Private Sub Form_Load()
. . .statement block…
End Sub
● General Procedures
○ declared when several event ● Module - declared in the general
procedures perform the same declarations using the keyword Dim or
actions Private
● Local - declared in a procedure using
Function Procedures Dim or Static
● like sub procedures, except they return a
value to the calling procedure Types of Array
● especially useful for taking one or more ● Fixed-Size
pieces of data, called arguments, and ○ Syntax:
performing some tasks with them Dim/Public ArrayVariable(Length) As DataType
● the functions return a value that indicates Dim/Public ArrayVar(LL To UL) As DataType
the results of the tasks complete within the
function ● Multidimensional
● Example: ○ used to represent tables of values
Function Hypotenuse (A As Double, B As Double) As Double consisting of information arranged
Hypotenuse = sqr (A^2 + B^2)
in rows and columns
End Function
○ VB supports at least 60 array D
○ 2D array - arrays that require two
Property Procedures
indexes to identify a particular
● used to create and manipulate custom
element
properties
○ to identify a particular table
● used to create read-only properties for
element, specify two indexes:
Forms, Standard modules, and Class
■ first (by convention)
modules
identifies the element's row
● 3 Kinds:
■ second (by convention)
1) Property Let - sets the value of a
identifies the element's
property
column
2) Property Get - returns the value
○ Syntax:
of a property
Dim ArrayName(Sub1,Sub2) As DataType
3) Property Set - sets the references
Dim ArrayName(Low1 To Up1,Low2 To Up2) As _
to an object
DataType
Array
● consecutive group of memory locations
that all have the same name and the
● Static
same type
○ include a fixed number of items,
● to refer to a particular location or element
and this number must be known at
in the array, specify the array name and
compile time so that the compiler
the array element position number
can set aside the necessary
● individual elements of an array are all of
amount of memory
the same data types
○ Uses Dim statement with a
● have upper and lower bounds and the
constant argument
elements have to lie within those bounds
○ Syntax:
● individual elements of an array are
Dim arrayname(length) As datatype
identified using an index (starts at 0)
○ each index number in an array is
● Dynamic
allocated individual memory space
○ Can be resized during execution
and therefore users must evade
○ Uses ReDim statement to resize
declaring arrays of larger size than
○ re-creating a dynamic array,
required
○ its contents are reset to 0 (or to an
empty string) and it loses the data
Array may be declared as:
it contains
● Public - declared in a code module

if need to resize an array without
Sqr(number) number
losing its contents, use the ReDim
Preserve command Abs returns the absolute value of a
○ To destroy, use Erase statement Abs(number) number
○ Syntax:
Exp Exp of a number x is the value of
Dim arrayname() As Datatype
Exp(number) ex
Sub Main()
ReDim arrayname(length) As Datatype Fix like Int but when the number is
negative, it will return the
Note: Fix(number) smallest integer that is larger
● Comment statements begin with the than the number
keyword Rem or a single quote ('). Round rounds up a number to a certain
Round(n, m) number of decimal places

Log returns the natural logarithm of a


Log(number) number

Sin compute the sine of a number in


● If a statement is very long, it may be Sin(number) radians
continued to the next line using the Cos compute the cosine of a number
continuation character, an underscore Cos(number) in radians
(_).
Tan compute the tangent of a number
Tan(number) in radians

Atn compute the arctangent of a


Atn(number) number in radians

● Statements can be stacked by using a Hex compute the hexadecimal (Base


colon (:) to separate them. Hex(number) 16) equivalent of a number

Oct compute the octal (Base 8)


Oct(number) equivalent of a number

Mathematical Functions
● useful and important in programming String Functions
because very often there is a need to deal
Name & Syntax Function
with mathematical concepts in
programmings such as chance and Len returns an integer value
probability, variables, mathematical logic, equal to the length of a
calculations, coordinates, time intervals Len(“Phrase”) phrase or a sentence,
including the empty spaces.
Name & Function
Syntax Right extracts the right portion of
Right(“Phrase”, n) a phrase from n to the right
Rnd returns a random value between
Rnd or 0 and 1 Left extracts the left portion of a
Int(Rnd*n) randomize whole number Left(“Phrase”, n) phrase from n to the left
Int converts a number into an Ltrim trims the empty spaces of
integer by truncating its decimal the left portion of the
Int(number) part and the resulting integer is Ltrim(“Phrase”) phrase
the largest integer that is smaller
than the number Rtrim trims the empty spaces of
the right portion of the
Sqr computes the square root of a Rtrim(“Phrase”) phrase
Trim trims the empty spaces on
Trim(“Phrase”) both sides of the phrase Other date and time functions are
DateAdd, DateDiff, DatePart, DateSerial,
Mid extracts n numbers of DateValue, Day, Hour, Minute, Month,
characters in the string MonthName, Second, TimeSerial, TimeValue,
Mid(“Phrase”, position, n) from position Weekday, WeekdayName, and Year
InStr looks for a phrase that is
embedded within the Formatting Functions
Instr (n, “original phase”, original phrase from n and
“embedded phrase”) Name & Function
returns the starting position Syntax
of the embedded phrase
Tab display text (string or
Ucase converts all the characters numbers) at n away from the
Ucase(“Phrase”) of a string to capital letters Tab(n); x left border of the output form
Lcase converts all the characters Space specifies the number of
Lcase(“Phrase”) of a string to small letters. a; Space(n); b spaces between two
consecutive items
Str converts a number to a
Str(number) string Format can display numeric values in
Format(n, a built-in form or in a way
Val converts a string to a
“style defined by the user
Val(string) number
argument”)
Chr returns the string that
corresponds to an ASCII Predefined Format Function
Chr(charcode) code
General display number without comma
Asc converts an ASCII Number separators
character or symbol to the
Asc(Character) corresponding ASCII code Fixed display number without comma
separators and round to 2 decimal
String returns a character places
repeated the specified n
String(n,"Character") times. Standard display number with comma
separators and round to 2 decimal
vbCrLf Named combination of two abbreviations places
Constant carriage return and line feed
Currency display the number with the dollar
Date and Time Functions sign with comma separators and
Name Function round to 2 decimal places

Date reads the system clock and


returns the current date as a Percent converts the number to the
string in the format: percentage form and displays a %
MM/DD/YYYY sign and rounds it up to two
decimal places
Time reads the system clock and
returns the current time as a
string in the format: hh:mm:ss
AM/PM

Now reads the system clock and


returns the current date and time
as a string in the format:
MM/DD/YYYY hh:mm:ss AM/PM

Timer reads the system clock and


returns the number of seconds
elapsed since midnight
Formatting Characters for Numbers
Format Description
Character

0 Represents a digit, with


non-significant leading and trailing
# zeros Control Structures
● If…Then…End If
. Decimal placeholder
○ performs an indicated action only
, Thousands separator when the condition is True, unlike
other conditional statements it
$ + - () Literal character; displayed as typed skipped an action if the logical test
space is not met
● If…Then…Else…End If ● Select…Case method
○ allows the programmer to specify ○ an alternative to If…Then…Else
that a different action is to be If…Else…End If for selectively
performed when the condition is executing a single block of
True than when the condition is statements from among multiple
False blocks of statements
○ If block statement is used to check ○ more convenient to use than the
whether the logical test is true or If…Else…End If
false ○ provides choices that are known as
○ requires the same number of End the selector
If the same as the number of ■ each of the choices has a
If-Then used corresponding action to be
executed
○ Case Else on this structure is
optional
■ value on each case
itemizes the values of the
selector for which action
should be taken.
○ paired with End Select

Nesting Syntax:
Method 1
If condition1 Then
Statements
Else If condition2 Then
Statements
Else If condition3 Then
Statements
Else
Statements
End If
Method 2
If condition1 Then
Statements Example:
Else Select Case Age
If condition2 Then Case 5
Statements Category = "Five Year Old"
Else Case 13 To 19
If condition3 Then Category = "Teenager"
Statements Case 20 To 35, 50, 60 To 65
Else Category = "Special Adult"
Statements Case Is > 65
End If Category = "Senior Citizen"
End If Case Else
End If Category = "Everyone Else"
End Select
Key Trapping
● prevent the user from typing in Repetition Structures
meaningless characters (for example, ● allows the programmer to do an action
letters) into the text boxes expecting that is to be repeated until the given
numerical data condition at the beginning or end of the
● process of intercepting unacceptable loop is true
keystrokes
● done in the KeyPress procedure of an Do loop
object ● repeats a sequence of statements or
● If KeyAscii is an acceptable value, the procedures as long as the condition is true
program will do nothing. However, if ● condition set to this uses keywords such
KeyAscii is not acceptable, set KeyAscii as while or until and followed by the word
equal to zero and exit the procedure. do or loop
Doing this has the same result of not ● statement Exit Do will get you out of a loop
pressing a key at all. and transfer program control to the
Syntax: statement following the Loop statement
Sub Textbox_KeyPress (KeyAscii as Integer)
statements Do While …loop
End Sub ● used to execute statements until a certain
condition is met
● first checks the condition set to this and if
the condition is true then the proceeding
statements are executed
● it will not execute even once if the While
condition is violated (False) the first time
through

ASCII Characters
Char Char Char

0 Null 41 ) 64 @

8 backspace 42 * 65 - 90 A to Z

9 tab 43 + 91 [

10 new line 44 , 92 \

13 enter 45 - 93 ]

32 space 46 . 94 ^ While…Wend Statement


● behaves like the Do While … Loop
33 ! 47 / 95 _
statement
34 “ 48 - 57 0 to 9 96 `

35 # 58 : 97 - 122 a to z

36 $ 59 ; 123 {

37 % 60 < 124 |

38 & 61 = 125 }

39 ‘ 62 > 126 ~

40 ( 63 ? 127 del
For…Next Loop
● used to make repetition of procedures or
Do Until…Loop Statement statements; it can give the same output as
● tests a condition for falsity the other repetition structure however the
● Statements in the body of a Do Until … structure is different
Loop are executed repeatedly as long as ● handles all the details of
the loop-continuation test evaluates to counter-controlled repetition
False ● using an Exit For statement will transfer
● will not be entered if the Until condition is program control to the statement following
already True on the first encounter the Next statement
● Syntax:
Do Until condition Syntax:
statements Method 1
Loop For condition
Statements
Next
Method 2
For condition Step update
Statements
Next

Example:
Method 1
Do…Loop While…Statement
Dim x As Integer
● first executes the statements and then
For x = 1 To 20
tests the condition after each execution
Print x
● always executed at least once
Next
Method 2
Dim x As Integer
For x = 1 To 20 Step 2
Print x;
Next

With…End With Statement


● multiple properties can be set and multiple
methods can be called using this
statement
● objects are evaluated only once
Do…Loop Until…Statement
● first executes the statements and then Syntax:
tests the condition for falsity With control
● always executes at least once Statements
● Syntax: End With
Do Example:
Statements With Label1
Loop Until condition .Caption = “Computer”
Example: .ForeColor = vbRed
Sum% = 1 .BackColor = vbYellow
Do .BorderStyle = 1
Debug.Print Sum .Height = 200
Sum = Sum + 3 .Width = 200
Loop Until Sum > 50 End With
Message Box ● If the box is Application Modal, the user
● displays a message, optional icon, and must respond to the box before continuing
selected set of command buttons work in the current application
● statement form of the message box ● If the box is System Modal, all
returns no value, it simply displays the box applications are suspended until the user
● Users have no control over where the responds to the message box
message box appears on the screen ● Note for each option in Type, there are
● function form of the message box returns numeric values listed and symbolic
an integer value, corresponding to the constants. Recall, it is strongly suggested
button clicked by the user that the symbolic constants be used
● Syntax: instead of numeric values.
MsgBox Message, Type, Title
where: Array
Message -Text message to be displayed ● Declared in a manner identical to that
Type - Type of message box used for regular variables
Title - Text in title bar of message box ○ to declare an integer array named
'Items', with dimension 9, at the
procedure level, use:
Dim Items(9) as Integer
○ for the array variables to retain
their value upon leaving a
procedure, use the keyword Static:
Static Items(9) as Integer
○ At the form or module level, in the
general declarations area of the
Code window, use:
Dim Items(9) as Integer
○ At the module level, for a global
declaration, use:
Global Items(9) as Integer
● index on an array variable begins at 0 and
ends at the dimensioned value

Control Arrays
● Option buttons are almost always grouped
in control arrays
● users can add or delete array elements at
run-time
● Elements of the array are referred to by
their name and index
● Two ways to create a control array:
● Create an individual control and
set desired properties. Copy the
control using the editor, then paste
it on the form.
● Create all the controls that to have
in the array. Assign the desired
control array name to the first
control. Then, try to name the
second control with the same
name.
Control ● It is important to note that an independent
● An object that can be drawn on a Form group of option buttons is defined by
object to enable or enhance user physical location within frames, not
interaction with an application according to a naming convention. That is,
● have properties that define aspects of a control array of option buttons does not
their appearance, such as position, size, work as an independent group just
and color, and aspects of their behavior, because it is a control array. It would only
such as their response to the user input work as a group if it were the only group of
● can respond to events initiated by the user option buttons within a frame or on the
or set off by the system form. So, remember physical location and
physical location only dictates the
Option Button independent operation of option button
● Aka radio buttons groups.
● allows the user to select from a set of Caption Title information at the top of frame
given choices
● allows the user to select from a set of Font Sets font type, style, size
given choices
● Are grouped (using frames) thus allowing Listbox
the user to choose only one among the ● presents a list of choices that are
available choices displayed vertically
Name allows the user to give a name to each of the ○ list is displayed in a vertical column
option buttons known as a list
○ A scroll bar appears if the list
Caption allows the user to display text to a specific option
button inside this control exceeds the
height of the list box
Value True - button is selected
False - not selected
● Syntax for Adding list:
controlname.AddItem list
● Syntax for Deleting an Item:
Checkbox
controlname.RemoveItem
● Gives choices to the user, although it is
controlname.ListIndex
different because checkboxes allow the
● Syntax for Deleting All Items:
user to choose as many choices as
controlname.Clear
presented in a checkbox
● For default selection:
Name allows the user to give a name to each of the controlname.ListIndex = Indexnumber
checkboxes
AddItem Used to add items inside the list box
Caption allows the user to display text to a specific
checkbox Appearance Selects a 3D or flat appearance

Value 0 - Unchecked or not selected Clear Removes all items from the list box
1 - Checked or selected
2 - Grayed Index Specifies the control array index

List returns/sets the items contained in a control’s


Frames list portion
● provide a way of grouping related controls ListCount number of items inside the list box
on a form
● in the case of option buttons, frames affect ListIndex number of the most recently selected item in
the list
how such buttons operate
○ Option buttons within a frame work MultiSelect Controls how items may be selected:
as a group, independently of option 0 - no multiple selections allowed
1 - multiple selections allowed
buttons in other frames. Option 2 - group selection allowed
buttons on the form, and not in
RemoveItem Used for removing or deleting an item
frames, work as another
independent group. That is, the Selected Set array with elements to True or False
form is itself a frame by default.
Sorted Sorts the list in ascending order ● Syntax for Loading Picture:
Picturebox.Picture = LoadPicture(“Path and Filename”)
Style Specifies the style: standard or check box ● Syntax for Unloading Picture:
Text Text of most recently selected item
Picturebox.Picture = LoadPicture(“”)
Set Picturebox.Picture = Nothing

Combo Box
Image Control
● control presents a set of choices that are
● supports lesser methods than PictureBox
displayed vertically in a column
controls
● appearance of the control because the
● Loads picture faster, consumes less
combo box includes a text box on top of a
memory space and system resources
list box and only allows the selection of
● Cannot autosize to fit the picture to the
one item
sides of the borders, instead it stretches
● displays the list when its drop-down button
● Same syntax as Picture Box control
is clicked
● Syntax for Adding list:
Timer
controlname.AddItem list
● Not visible at run time
● Syntax for Deleting an Item:
● Uses only one event (timer event) that
controlname.RemoveItem
happens at a certain time interval
controlname.ListIndex
measured in milliseconds
● Syntax for Deleting All Items:
Name Name given to the control used in procedure
controlname.Clear
● For default selection: Enabled Set used to activate and deactivate events:
controlname.ListIndex = Indexnumber False - not executed

AddItem Used to add items inside the list box Interval Set the number to milliseconds, measures the time
for an action to be executed
Appearance Selects a 3D or flat appearance

Clear Removes all items from the list box Vertical and Horizontal Scrollbar
● enables the user to set its value to
Index Specifies the control array index
position a picture on an item at the desired
List returns/sets the items contained in a control’s location; either horizontally or vertically
list portion
Large return/set the max amount of change to
ListCount number of items inside the list box Change value property in a scroll bar when scrollbar
area is clicked
ListIndex number of the most recently selected item in
the list. If no item is selected, ListIndex = -1 Small return/set the min amount of change to
Change value property in a scroll bar when scrollbar
RemoveItem Used for removing or deleting an item area is clicked

Selected Set array with elements to True or False Max return/sets a scrollbar position’s max value
property setting
Sorted Sorts the list in ascending order
Min return/sets a scrollbar position’s min value
Style Specifies the style: standard or check box property setting

Text Text of most recently selected item


Multiple Forms
● used if the program needs two or more
Picture forms
● Supports print method and cls
Load
○ Cls is used to clear or erase the Display the form
text graphics or graphics displayed Show
on the screen and to display
Unload Form disappears and no longer loaded in
pictures like image controls computer memory
● Display images or pictures in a program
● Supports bitmap, GIF, JPEG, metafiles Hide Form disappears but is loaded in memory
Menus Inputbox Functions
● Group of related commands ● Displays a messagebox that will display a
● menu structure is a hierarchical list of message or prompt with the textbox
command buttons that only appear when control when the user enters a value
pulled down from the menu bar ● Syntax:
● access keys are underscored characters Variable = InputBox(“Prompt”, “Title”,
of a menu “Default”, Xpos, Ypos)
● level of indentation indicates the position Prompt Message that will be displayed inside the input box
of a menu item within the hierarchy
Title Display the title of the input box
Menu Editor Default Displays the message inside the textbox in input box
● allows the user to define the menu
structure, adding access keys and Xpos, Values of the coordinates where the input box will
Ypos appear on the screen
shortcut keys, if desired

➔ Caption Box - where the user types the


text that appears in the menu bar
◆ Ampersand - used to make
access keys
◆ Separator Bars - used to separate
menu items and defined using a
Caption of a single hyphen (-)
➔ Name Box - where the user enters control
name usually with the prefix: mnu
➔ Index Box - used for indexing any menu Progressbar
items defined as control arrays ● An animated bar usually used to see if
➔ Shortcut Dropdown Box - used to assign there is a page tha is to be loaded
shortcut keystrokes to any item in a menu ● One of the common properties used in this
structure, appears to the right of caption control are Value and Max
➔ HelpContextID and NegotiatePosition ○ As the value of this program
Boxes - relate to using online help and changes, the bar inside the
object linking embedding progress bar moves.
Checked indicate whether a toggle option is turned on or off ○ The progress bar moves up to the
True - checkmark appears next to the menu item specified value in the max property
Enabled True - a menu item can be selected
False - menu item is grayed & can’t be selected Toolbar
● Control seen below the menu bar
Visible Controls whether menu item appears in structure
● A bar consisting of a collection of buttons
Window Used with Multiple Document Interface (MDI) that serve as a shortcut to the commands
List indie the menu bar
Imagelist Save As Common Dialog Box
● Ued to hold pictures for other controls ● provides the user a mechanism for
● Not visible at runtime specifying the name of a file to save
● Can be positioned anywhere on the form ● displayed by using the ShowSave method

Statusbar
● Bar seen at the bottom of an application’s
window
● Used to display the status of the user’s
work and action inside the app
● Commonly used property:
Statussbar.panels(n)
Where n is the index of the panels

Common Dialogue Boxes


● Used to give the user a standard interface
for common operations in Windows-based
applications
● Example: Open and Save As dialog boxes
● Invisible at run-time
● Are system modal
● invoked at run-time using one of five
‘Show’ methods

The Save File box is commonly configured in one


of two ways.
● If a file is being saved for the first time, the
Save As configuration is used with some
default name in the FileName property.
● In the Save configuration, it is assumed
Open Common Dialog Box a file has been previously opened with
● provides the user a mechanism for some name. Hence, when saving the file
specifying the name of a file to open again, that same name should appear in
● displayed by using the ShowOpen method the FileName property.

ADO - ActiveX Data Object (new database tools)


DAO - Data Access Object (older data base tools)

Database - collection of information stored in a


well-defined tables or matrices

Rows - in a database table, used to describe


similar items and no rows in a database table will
be alike

Columns - in a database table, provide


characteristics of the records called database
fields
● Each field contains one specific piece of
information. In defining a database field,
you specify the data type, assign a length,
and describe other attributes.
Indexes
● allow faster access to information
● sorted lists that point to a particular row in
a table

Flat Database - database using a single table


● When using multiple tables within a
database, these tables must have some
common fields to allow cross-referencing
of the tables. The referral of one table to
another via a common field is called a
relation. Such groupings of tables are
called relational databases.

Query - request for information form the database

Database Management System (DBMS) - tracks


all the information in a database and are used to
create database
● Examples of commercial DBMS programs
are Microsoft Access, Microsoft
FoxPro, Borland Paradox, Borland
dBase, and Claris FileMaker. We can
also use Visual Basic to develop a DBMS.
Visual Basic shares the same ‘engine’
used by Microsoft Access, known as the
Jet engine. In this class, we will see how
to use Visual Basic to access data, display
data, and perform some elementary
management operations.

You might also like