1.introduction To VB What Is VB?: Notes For Visual Basic Part 1
1.introduction To VB What Is VB?: Notes For Visual Basic Part 1
1.Introduction to vb
What is vb?
vb is a user friendly event driven and partly objected oriented programming language using which we
can develop:
database application.
web enabled application.
and variety of other window based application.
What is event?
Event is any action performed by either performed by user or performed by program itself. for example
mouse-click, key press, window resize etc.
What is the difference between structured/procedure oriented and event driven programming
Program consists of one or more procedure. Program consists of one or more event
procedure.
What is module?
module is collection of procedures and functions corresponding to a file in disk will generate. benefits
are:
it provides code reusability and shariblity.
avoids code repetition.
testing and debugging becomes easier.
type of module:
form module: normally contains event procedures, other procedure and function which will be used
inside the same form module. extension is .frm
basic module: normally contains global variables, procedure and function which can be accessed across
other modules. extension is .bas
class module: contains definition of class, member function and properties. extension is .cls
2. Creating programs
What is Object?
object is class variable which is composition of properties, methods and data member. object is
fundamental requirement of any object oriented language. object has three characteristics:
state: state of any object it defines identity of object.
behaviour: behaviour of any object is decided by member functions(methods) to which object can
respond.
method: it is also known as member function it performs computation on data member or any kind of
action.
What is property?
property of any object is actually member procedure which allows to set value in data member (
working as mutator) or allows to retrieve value of data member ( working as accessor).
3.Variables Procedures
What is variable?
variable is name given to computer memory location where we can store value and retrieve the stored
value by name.
variable is fundamental requirement of any programming language.
rule of naming variable or identifier:
variable name must start with alphabet.
later on digits can be used, under score can also appear.
variable name is not case sensitive
only a-z, 0-9 and _ can appear in variable Name
space and special are not allowed.
variable name must not match with keyword
we can have variable name 255 characters long
name of control must not exceed 40 characters
1.Byte 0 , 255 1
6.string(fixed) $
Write notes on if control structure./ explain branching structure in vb./ write short notes on if
statement/ write short note on select case.. end select.
The general form of if statement is:
(a)if-endif statement
the general format of if statement is
if (condition is true) then
execute this statement
end if
The keyword if tells the compiler that what follows, is a decision control instruction. The condition
following the keyword if is optionally enclosed within a pair of parentheses. If the condition, whatever it
is, is true, then the statement is executed. If the condition is not true then the statement is not
executed; instead the program skips past it.
(b) if –else-endif statement
if statement by itself can execute only one statement if condition is true. If it required running a group
of statements when condition is true we have to enclose those statements inside curly brace known
as compound statement. The above form of if statement mentioned in (a) will not do anything when
condition is false. If we want to run statement when condition is false we need if-else construct.
General format of if-else construct is
If (condition is true) then
Execute this statement
Else
Execute this statement if condition is false
end if
Condition is specified using relational operator
x= y means x is equal to y.
x<>y means x is not equal to y.
x< y means x is less than y.
x>y means x is greater than y.
x<=y means x is less than or equal to y.
x>=y means x is greater than or equal to y
program to print message teenage, child, old etc. according to given age
Private Sub Command1_Click()
Dim a!
a = Text1
Select Case (a)
Case Is <= 8
Text2 = "child"
Case 9 To 14
Text2 = "teenager"
Case 15 To 20
Text2 = "young"
Case 21 To 28
Text2 = "adult"
Case Is > 28
Text2 = "old"
End Select
End Sub
place label : having caption enter age
place text1: having text property cleared
place label2 : having caption state
place text2: having text property cleared
place command1: having caption check age
1.All programs made using select-case canAll programs made by ‘if’ are not possible to
be solved using if. select case takessolve by ‘select-case’.
different action depending on value of a
single variable.‘if’ leads to less structured programming
and level of indentation is difficult to
2. ‘select-case’ leads to more structuredmanage if using nested ‘ifs’.
programming and level of indentation is
manageable even if we have nested select-
case.
1.multiple ‘if..else’ contains more than one1.nested ‘if..else’ contains more than one
end if. Each ‘end if’ corresponds to each ‘if’.‘else if’ but just one ‘end if’..
Write short notes on ‘while’ (entry level control structure/test and do) loop.
In programming we require to execute same set of instructions a fixed number of times. E.g. we want to
calculate gross salary of ten different persons, we want to convert temperatures from centigrade to
Fahrenheit for 15 different cities. The ‘while’ loop is suited for this.
‘ program to print 1 to 10 on form
private sub command1_click()
dim a%
a=1
do while a<=10
print a
a=a+1
loop
end sub
General format is
1.
initialize loop counter
do while(condition is true)
do this;
increment loop counter;
loop
Write short notes on ‘while’ (entry level control structure/test and do) loop.
In programming we require to execute same set of instructions a fixed number of times. E.g. we want to
calculate gross salary of ten different persons, we want to convert temperatures from centigrade to
Fahrenheit for 15 different cities. The ‘while’ loop is suited for this.
‘ program to print 1 to 10 on form
Do while loop must test a condition that will eventually become false, otherwise the loop would be
executed forever, indefinitely known as infinite or indefinite loop.
while loop or while..wend loop test condition and if condition is true then statements are executed if
condition is false statements are not executed even once.
do.. while loop test condition later therefore if condition is false statements are executed at least once.
while..wend statement can not use ‘exit do’ statement to come out of loop whereas do..while and
do..loop…while can use ‘exit do’ statement to come out of loop.
do this
and this
and this
next
Write short Notes on ‘exit do / exit for’ in Loop/write program to check primality.
We often come across situations when we want to jump out of a loop instantly, without waiting to get
back to the conditional test. The keyword ‘exit do / exit for’ allows us to do this. When the keyword
‘‘exit do / exit for’’ is encountered inside any loop statement, control automatically passed to the first
statement after the loop. An ‘exit do / exit for’ is usually associated with an ‘if’ statement applicable to
loop.
The keyword ‘exit do / exit for’ takes the control out of the loop inside which it is placed.
program to print prime series between 1 to 100 using for loop and exit for
Private Sub Command1_Click()
Dim a%, b%, c%, n%, t$, i%
a=1
b = 100
For n = a To b
For i = 2 To n - 1
If n Mod i = 0 Then
Exit For
End If
Next
If i >= n Then
t=t&""&n
End If
Next
Text1 = t
End Sub
place label1 : having caption set to prime series is
place text1: having text property cleared
place command1: having caption print series in text box
Define Array.
Array or Subscripted variables:
Array is collection of variables having common name and common data type. Individual variable in
collection is identified by index or subscript. Elements of array occupy contiguous memory location.
What is function?
a number of statements grouped into a single logical unit is referred to as a function which returns a
value and which is made to complete a specific task. A program can be made of many functions.
Types of functions:
User defined function: these are those functions which are made by programmer for his programming
convenience.
Library function: these are those functions which are readymade and are provided by compiler, uses of
which are possible by including corresponding header files. Source code of library function is not
available to programmer but its object codes are available in precompiled form.
What is procedure?
a number of statements grouped into a single logical unit is referred to as a procedure or subroutine
which does not return any value and which is made to complete a specific task. A program can be made
of many procedures.
call by reference:
'when called routine is able to change value of actual argument
'through dummy argument it is known as call by reference
Private Sub Command1_Click()
Dim a%, b%
a = Text1
b = Text2
swap a, b
'after call
Text5 = a
Text6 = b
End Sub
Private Sub swap(Byref a%, Byref b%)
'default is call by reference
Text3 = a
Text4 = b
Dim temp%
'interchange
temp = a
a=b
b = temp
End Sub
user interface:
6 textboxes: having text property clear and having default name text1,text2…
6 labels: having caption enter value of a, enter value of b, within called subroutine value of a, within
called subroutine value of b, after call to swap value of a, after call to swap value of b
1 command button: having caption swap and having default name command1