0% found this document useful (0 votes)
12 views24 pages

1 104704

The document provides an overview of Visual Basic programming, covering key concepts such as properties of controls, variable and constant declarations, built-in functions, arrays, and control structures. It explains the use of various controls like text boxes, labels, and command buttons, as well as the Integrated Development Environment (IDE) components. Additionally, it discusses conditional statements, looping constructs, and the syntax for functions like InStr and MsgBox.

Uploaded by

caleyafoe
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views24 pages

1 104704

The document provides an overview of Visual Basic programming, covering key concepts such as properties of controls, variable and constant declarations, built-in functions, arrays, and control structures. It explains the use of various controls like text boxes, labels, and command buttons, as well as the Integrated Development Environment (IDE) components. Additionally, it discusses conditional statements, looping constructs, and the syntax for functions like InStr and MsgBox.

Uploaded by

caleyafoe
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 24

Visual Basic Programming

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

9. What are image controls?


The Image Box is another control that handles images and pictures. It functions almost identically to the
picture box.
Image1.Picture=LoadPicture ("C:\VBprogram\Images\grape.gif")
10. What are labels?
The label is a very useful control for Visual Basic, as it is not only used to provide instructions and
guides to the users, it can also be used to display outputs. One of its most important properties is
Caption.
11. Write note on variant data type.
A Variant is a special data type that can contain any kind of data except fixed-lengthString data. Dim
a
12. Explain about the Text Box
The text box is the standard control for accepting input from the user as well as to display the output.
It can handle string (text) and numeric data but not images or pictures. Text1.text=”hai”.
13. List the relational operator in VB.
Operator Meaning
= Equal to
> More than
< Less Than
>= More than or equal
<= Less than or equal
<> Not Equal to
_____________________________________________________________________________________

1. Write the six form properties.


Resize the form according to the setting of AutoSizeMode.
AutoSize

Gets or sets the background color for the control.


BackColor

Gets or sets the font of the text displayed by the control.


Font

Gets or sets the name of the control.


Name

Gets or sets a value indicating whether the control redraws itself when resized.
ResizeRedraw

2
Visual Basic Programming

2. Write the short notes on VB Data Types

3. Write the properties of textbox control.


Text Gets or sets the current text in the TextBox.

4. Explain about the form with its properties and methods.

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

Border style :- the border dstyle value ranges from 0 to 5.

• -> 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.

Reseize :- respond to when the user resize the form.

Click :- respond to a mouse click.

Double click :- respond to a mouse double click

Change :- respond to when change is made on the controls.

Got focus :- fired when the controls received the input focus

Los focus :- fires when the control leaves the passes to another control

Key press :- respond when the user press a key

Key down :- respond when the user translate the key ansi numeric code

Key up :- respond when the user releases the key.

Mouse down :- fires when the user click the mouse

Mouse up :- fires when the user release the mouse

Mouse move :- fires when the user move the control

___________________________________________________________________________________

1. Explain the VB controls and their uses with example.

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.

Pointer :- pointer is uded to interact with the controls on the form.

Picture box :- picture box is used to display images.

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

Frame:- it is uded to group other controls

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

H scroll & v scroll :- it is used to place scroll box in form Timer

:- timer is used to perform task in specified intervals Drived list

box:- it is used to access the system drives.

Drilist box:- used to display the directory on the system.

File list box:- used to access the files in the directory Shape

:- used to draw circle, rectangle ,square ,oval.

Line :- used to draw line.

Image :- used to display images but less capacity than the picture box.

Data :- used to connect the data base.

Ole :- [object link embaded] used to interact with other windows application.

7
Visual Basic Programming

2. Explain about the IDE of VB indetail.

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

File :- Contains The Command For Opening And Saving Projects

Edit :- Contains Editing Commands And Other Formatting Tools

View :- Contains Command For Showing Or Hiding Components Of Hide

Project: - Contains Commands That Add Components To The Current Project

Format:- Contains commands for aligning the control on the form

Debug :- contains debugging tools

Run :- contains commands start, break and end execution

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.

Pointer :- pointer is uded to interact with the controls on10


the form.
Visual Basic Programming

Picture box :- picture box is used to display images.

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

Frame:- it is uded to group other controls

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

H scroll & v scroll :- it is used to place scroll box in form Timer

:- timer is used to perform task in specified intervals Drived list

box:- it is used to access the system drives.

Drilist box:- used to display the directory on the system.

File list box:- used to access the files in the directory Shape

:- used to draw circle, rectangle ,square ,oval.

Line :- used to draw line.

Image :- used to display images but less capacity than the picture box.

Data :- used to connect the data base.

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)

1. Give the syntax of Instr function.


InStr([start,]string1,string2[,compare])
Parameter Description
start Optional. Numeric expression that sets the starting
position for each search. Default 1.
string1 Required. String expression being searched.
string2 Required. String expression searched for.
compare Optional. Numeric value indicating the kind of comparison
to use when evaluating substrings.

2. How to display information on a form?


Print method is used to display information in a form.
Formname.print”string expression”
Form1.print”welcome”

3. Illustrate the concept of with statement.


Executes a series of statements that repeatedly refer to a single object or structure so that the statements can
use a simplified syntax when accessing members of the object or structure.
With objectExpression
[ statements ]
End Wit h

4. What are determinate loops?discuss with example.


The For...Next construction performs the loop a set number of times. It uses a loop control variable, also
called a counter or determinate lops, to keep track of the repetitions.

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

6. What are the two types of array?


a. Fixed
Dim a(5) as integer
b. Dynamic
Dimb() as integer

7. What are public variables?


Public variable can be accessed globally in a project.
Public con as string
15
Visual Basic Programming

Unit II

16
Visual Basic Programming

1. Explain the conditional statements in Visula Basic with Exmaple.

If.....Then.....Else Statements with Operators


To effectively control the VB program flow, we shall use If...Then...Elsestatement together with the
conditional operators and logical operators.
Syntax:
If conditions Then
VB expressions
Else
VB expressions
End If Example
:
If (a>b) then
Print “a is big”
Else
Print “b is big”
End if
Select Case
The Select Case control structure is slightly different from the If....ElseIf control structure .The
difference is that the Select Case control structure can handle conditions with multiple outcomes in an easier
manner than the If...Then...ElseIf control structure.
Syntax :
Select Case expression
Case value1
Block of one or more VB statements

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

2. Write note on looping statement in visual basic.


Visual Basic allows a procedure to be repeated many times until a condition or a set of conditions is fulfilled.
This is generally called looping . Looping is a very useful feature of Visual Basic because it makes repetitive
works easier. There are two kinds of loops in Visual Basic, the Do...Loop and the For.......Next loop.
Do Loop
The Do Loop statements have three different forms, as shown below: a)
Do While condition
Block of one or more VB statements
Loop

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:

For counter=startNumber to endNumber (Step increment)


One or more VB statements
Next Example:
For counter=1 to 10 display.Text=counter
Next
The While….Wend Loop
The structure of a While….Wend Loop is very similar to the Do Loop. it takes the following form:
While condition
Statements
Wend
3. Write a short note on messagebox.

19
Visual Basic Programming

button before he /she can continues. This format is as follows:


yourMsg=MsgBox(Prompt, Style Value, Title)
The first argument, Prompt, will display the message in the message box. The Style Value will determine

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.

Operator Mathematical function Example

^ 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

\ Integer Division(discards the decimal places) 19\4=4

+ or & String concatenation "Visual"&"Basic"="Visual Basic"


Operator Meaning

= Equal to

> More than

21
Visual Basic Programming

< Less Than

22
Visual Basic Programming

5. What are the Operators in Visual Basic?

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

<> Not Equal to

Operator Meaning

And Both sides must be true

Or One side or other must be true

Xor One side or other must be true but not both

Not Negates truth

24

You might also like