1 104704
1 104704
Unit 1
1. Write any three common properties for several visual basic controls.
BackColor and ForeColor- The BackColor property sets the background color of an object while the
ForeColor property changes the foreground color used to display text.
Caption-It sets the text displayed in the object's title bar or on the object. Font-You
can set the font property from the Properties Window.
2. What is toolbox? List the common collection of tools.
Displays the standard Visual Basic controls plus any ActiveX controls and inser table objects you have
added to your project. The tools in toolbox are label, textbox, combobox, option button, checkbox,
command button.
3. Define Variables. How to declare variable variables are areas allocated by the computer memory to
hold data. In Visual Basic, it is a good practice to declare the variables before using them by assigning
names and data types. They are normally declared in the general section of the codes' windows using the
Dim statement.
Dim VariableName As DataType
Dim yourName As String
Dim firstnum As Integer
4. Define Constants.
Constants are different from variables in the sense that their values do not change during the running of
the program.
Constant Name As Data Type = Value
Const Pi As Single=3.142
5. List the built_in functions with example.
Rnd is is very useful function for dealing with the concept of chance and probability.
Print Rnd
Int is the function that converts a number into an integer by truncating its decimal part.
Int(0.032)=0
Log is the function that returns the natural Logarithm of a number. For example, Log
10= 2.302585
6. How to declare multidimensional arrays in VB?
Dim a(2,3) as integer
2 represent rows 3
represents column
7. Define array.
An array is a set of values that are logically related to each other, such as the number of students in each
grade in a grammar school.
Declare a single-dimension array of 5 values
Dim numbers(4) As Integer
8. Write the syntax of inputbox function. Explain.
An InputBox( ) function will display a message box where the user can enter a value or a message in the
form of text. The format is myMessage=InputBox(Prompt, Title, default_text, x-position, y-position)
1
Visual Basic Programming
Gets or sets a value indicating whether the control redraws itself when resized.
ResizeRedraw
2
Visual Basic Programming
Form is the work place in visual basic were the user can place controls in it the header area as a
caption. Control menu and maximums , minima’s closed button.
Visual Basic Programming
The large area of the form is called the client area in visual basic the basic building block of on
application is a form which is simple a window and controls like check box, text box, label etc..or
place in it….
Properties :-
Captions :- this properties set the title of the form by default the caption is form one.
Name:- the user can change the name of the form as per his wish by default form1. Is the name this
properties is used while writing codes
Appearance :- this properties desides the forms appearance like normal 2d,3d
• -> none
• 1-> fixed single
• 2-> size able
• 3-> fixed double
• 4-> fixed tool window
• 5-> sizeable tool window.
Font :- the user can set the font, font style and size by using this properties
4
Visual Basic Programming
Height width :- this properties desides the height and width of a form.
Window state :- specified the state of the window like maximize minimize and normal
Events :-
Load :- this event is fixed when the form is loaded secondary memory to the primary memory
Unload :- this event is fired when the user closed the form.
Got focus :- fired when the controls received the input focus
Los focus :- fires when the control leaves the passes to another control
Key down :- respond when the user translate the key ansi numeric code
___________________________________________________________________________________
5
Visual Basic Programming
Tool box contains a set of controls with are used to customized form using this controls and interface between
6
Visual Basic Programming
user and application can be created by default tool box contains 21 activex controls to place a control on a form
select it with the mouse and then move the mouse over the form. And draw the control on the form. Otherway is
just double click on the required controls.
Text box:- text box is used to accept user input and it can also display some information.
Label :- label is used to display text in a form which cannot be edited during run time
Command button :- command button used to initate and action by pressing on the button
Check box :- check box used to do a choice for user multiple choices can be made.
Option button:- option button used in groups where one at a time can be true
Combo box :- used to provided a list of items from which user can select any one.
List box :- used to provided a list of items from which user can select multiple options
File list box:- used to access the files in the directory Shape
Image :- used to display images but less capacity than the picture box.
Ole :- [object link embaded] used to interact with other windows application.
7
Visual Basic Programming
8
Visual Basic Programming
Consist Of A Number Of Element Including Menu Bar, Title Bar, Tool Bar, Tool Box, Project Explorer And
Properties Window. The Main Window In The Middle Of the Screen Contain A Form Named Form One The
Form Is The Application Window Were The Uses Interfaces Can Be Placed
Menu Bar :- The Menu Bar Contains The Command Needed To Works With Visual Basic
Query :- contains commands that simple the structure query language Project
explorer
9
Visual Basic Programming
Project explorer displaced the components of the project. The user can switch over form code to design view
and viz..
Properties windows
Properties windows displays the properties of a form on a control.properties Are artibutes of an object
search as its size,name,captions and color.
Form layout
The form layout window in the lower right corner of the vb IDE. It is use to determain the initial
position form in the application this window is usefull for the application that use multipul forms
Tool box :-
Tool box contains a set of controls with are used to customized form using this controls and interface
between user and application can be created by default tool box contains 21 activex controls to place a control
on a form select it with the mouse and then move the mouse over the form. And draw the control on the form.
Otherway is just double click on the required controls.
11
Visual Basic Programming
Text box:- text box is used to accept user input and it can also display some information.
Label :- label is used to display text in a form which cannot be edited during run time
Command button :- command button used to initate and action by pressing on the button
Check box :- check box used to do a choice for user multiple choices can be made.
Option button:- option button used in groups where one at a time can be true
Combo box :- used to provided a list of items from which user can select any one.
List box :- used to provided a list of items from which user can select multiple options
File list box:- used to access the files in the directory Shape
Image :- used to display images but less capacity than the picture box.
Ole :- [object link embaded] used to interact with other windows application.
Form :-
12
Visual Basic Programming
13
Visual Basic Programming
Form is the work places in visual basic were the user can place controls in it the header area as a caption.
Control menu and maximums, minima’s closed button.
The large area of the form is called the client area in visual basic the basic building block of on application
is a form which is simple a window and controls like check box, text box, label etc..or place in it.
__________________________________________________________________________________________
14
Visual Basic Programming
Unit II
Part A (2 Marks)
5. Define array.
An array is a set of values that are logically related to each other, such as the number of students in each
grade in a grammar school.
Declare a single-dimension array of 5 values
Dim numbers(4) As Integer
Unit II
16
Visual Basic Programming
Case value2
Block of one or more VB Statements
Case Else
Block of one or more VB Statements
End Select Example :
Dim grade As String
Private Sub Compute_Click( ) grade=txtgrade.Text
Select Case grade Case
"A"
result.Caption="High Distinction" Case
"A-"
result.Caption="Distinction" Case
"B"
result.Caption="Credit" Case
"C"
result.Caption="Pass"
17
Visual Basic Programming
Case Else
18
Visual Basic Programming
result.Caption="Fail"
End Select
End Sub
b) Do
Block of one or more VB statements
Loop While condition
c) Do Until condition
Block of one or more VB statements
Loop
d) Do
Block of one or more VB statements
Loop Until condition
Example: Do while
counter <=1000
num.Text=counter
counter =counter+1
Loop
For....Next Loop
The For....Next Loop event procedure is written as follows:
19
Visual Basic Programming
displayed. The Title argument will display the title of the message board.
20
Visual Basic Programming
logarithm of a specified number or the logarithm of a specified number in
a specified base.
Round Returns a Double value containing the number nearest the specified value.
Additional round functions are available as methods of the intrinsic types
such as Decimal.Round Method.
Sgn Returns an Integer value indicating the sign of a number.
Sin Returns a Double value specifying the sine of an angle.
Sqr Returns a Double value specifying the square root of a number.
Tan Returns a Double value containing the tangent of an angle.
^ Exponential 2^4=16
* Multiplication 4*3=12,
/ Division 12/4=3
Mod Modulus (returns the remainder from an integer division) 15 Mod 4=3
= Equal to
21
Visual Basic Programming
22
Visual Basic Programming
23
Visual Basic Programming
Arithmetic Operators
Conditional or relational >= More than or equal Operators
To control the VB program flow, we can use various conditional
operators
<= Less than or equal
Operator Meaning
24