Вы находитесь на странице: 1из 7

August 2008

Subject Code: BT0040-1


Subject Name: Visual Programming with VB
Course Name: BSc IT New
Semester: II Credits: 4
Marks: 40

Q.1 Write about the Visual Basic Application Development Life cycle with a sample Forms
development for performing integer arithmetic operations.

Ans. Visual Basic Application Development Life cycle: These are the necessary steps to
create a visual basic program. Programmers call these steps as ‘development cycle’.

• Decide what you want the computer to do.

• Decide how you want your program to look on the screen. (The appearance of your
program is called the user interface)

• Draw your user interface by using common components, such as windows, menus and
command buttons. (The components of user interface are called objects or controls).

• Define the name, color, size and appearance of each user interface object. (An object’s
characteristics are called properties).

• Write instructions in BASIC to make each part of your program do something. (BASIC
instructions are called commands).

• Run your program to see whether it works.

• Fix any errors (or bugs) in your program.

Q.2 Discuss the following:


• Form Modules
• Standard Modules
• Class Modules

Ans. Form modules: Form modules (.FRM extension) are the foundation of any VB application.
They can contain graphical descriptions of the form and its controls, including their property,
settings. They can also contain form level declarations of type constants, variables and external
procedures, procedures that handle events and general procedures. Virtually everything that
applies to class module applies to form module. Forms are just class modules that can have
controls placed on them and display a form window. Forms are part of our application that are
visible to users at run time.
Standard modules: Standard modules (.BAS extension) are containers for procedures
and declarations, commonly used by other parts of our application. They can contain
global or module level declarations of types, constant, variables, external procedures
and global procedures.

Class modules: Class modules (.CLS extension) are foundation of object oriented
programming in VB. We can write code in class modules to create new objects. These
new objects can include our own customized properties and methods, although custom
objects can not have their own events. All the properties and method we create can also
be used by other objects, in our application. We can also use the keyword, New to
create multiple copies of our objects.

Q.3 Create a Menu Interface in Visual Basic which performs the same functionality of MS – Word
File menu.

Ans.

Q.4 Develop a University Database using MS – Access. Create appropriate form based interfaces to
access the data using controls in the tool box.
Subject Code: BT0040-2
Subject Name: Visual Programming with VB
Course Name: BSc IT New
Semester: II Credits: 4
Marks: 40

Q.1 Discuss the following:


• Visual Basic Editions
• Object Naming Conventions
• Event Procedures

Ans. Visual Basic Editions: Visual Basic software comes in three editions:

• Learning Edition: which includes the Visual Basic development environment and use of
standard tools to develop applications
• Professional Edition: It is used by computer professionals as it supports the tools to
develop ActiveX and internet controls.
• Enterprise Edition: which includes all the features of professional edition as well as MS
Visual Source safe for source code control and Automation and Component manager?

Object Naming Conventions: When we create an object, VB sets its name property to a
default value. It is good practice to change their Name properties to something more
descriptive, when there are several controls of the same type. The following naming
convention for VB objects is a common practice.
Object Prefix Example
Form Frm frmFileOpen
Checkbox Chk chkVeg
Combo box Cbo cboLanguage
Command Button Cmd cmdCancel
Data Dat datBibilio
Directory list box Dir dirSource
Drive list box Drv drvTarget
File list box Fil filSource
Frame Fra fraCourse
Horizontal scroll bar Hsb hsbVolume
Image Img imgIcon
Label Lbl lblName
Line Lin linVertical
List box Lst lstInstitutes
Menu Mnu mnuFileOpen
Option button Opt optSmile
Picture box Pic picDisk
Shape Shp shpCircle
Textbox Txt txtName
Time Tmr tmrAlarm
Vertical scrollbar Vsb vsbRate
Event Procedures: when an object in VB recognizes that an event has occurred, it
automatically invokes the event procedure with the name corresponding to the event.
Because the name establishes an association between the object and the code, event
procedures are attached to forms and functions.

• An event procedure for control combines the control’s actual name, an


underscore, and the event name. For instance if we want a command button
named cmdQuit to invoke an event procedure when it is clicked, use the
procedure cmdQuit_Click.
• An event procedure for a form combines the word Form and underscore and the
event name. If we want a form to invoke an event procedure when it is clicked,
we use the procedure Form_Click. Like controls forms do have unique names,
but they are not use in the names of event procedure. If we are using the MDI
form, the event procedure combines the word MDIForm, an underscore, and the
event name as in MDIForm_Load.

Q.2 Discuss the following control structures of Visual Basic with suitable programming examples for
each:
• If Statements
• Case Statements
• Do While Loop
• For…Next Loop

Ans. IF statements:

If … Then
We can use either single line syntax or multiple line block syntax.
If <condition> Then <statements>
It <condition> Then
<Statements>

End If

If … Then … Else

If <condition1> Then
[Statements block 1]
[Else If <condition2> Then
[Statements block 2]
[Else
[Statement block n]]

End If
Example:

Dim marks as integer


Marks = val(text1.txt)
If marks > 90 then
Text2.txt = “Excellent”
Else if marks > 80 then
Text2.txt= “Very good”
Else if marks > 70 then
Text2.txt= “Good”
Else
Text2.txt = “Average”
End if

Case Statements: A select case statement provides capability similar to the If … then …. Else but it
makes code more efficient and readable.

Select case text expression


[Case expression list 1
[Statement block 1]]
[Case expression list 2
[Statement block 2]]

…….

…….

…….

[Case Else
[Statement block n]]
End Select

Example:

Dim marks as integer


Marks = val(text1.txt)
Select case marks
Case is > 90
Text2.txt = “Excellent”
Case is > 80 then
Text2.txt= “Very good”
Case is > 70 then
Text2.txt= “Good”
Case Else
Text2.txt = “Average”

End Select

Do While ….. Loop: Loop structures allow us to execute one or more lines of code repetitively.

DO While <condition>
Statements
Loop
Example:
Dim k as integer
K=5
Do while k<10
Text1.txt=k
K=k+1
Loop

For…Next Loop: this loop structure is used to execute the statements a specific number of times. For
loop uses a counter variable that increases or decreases in value during each repetition of the loop.

For [counter] = start to End [step increment]

Statements

Next [counter]
Example:
Dim k as integer
For k=1 to 10
Text1.txt=k
Next k

Q.3 Create an MDI Application of your own in Visual Basic with at least 3 child forms under the
Parent Form.

Ans.

Q.4 Discuss with the help of a programming example all the features of Data Access Objects
(DAOs) in Visual Basic

Ans. Data Access Objects: one of the tools available in VB to access databases programmatically is
data access objects (DAO) programming interface. Using data access objects we can create
databases and build full featured applications that access existing databases in many popular
formats, including MS- access, Btrieve, dBASE, MS- foxpro, Paradox as well as ODBC client/
server databases like MS SQL server.

Example:

Dim myWs As Workspace


Dim myDb As Database
Dim myTd As TableDef
Dim myFields(5) As Field
Dim mySet As Recordset
Dim Total As Long

Sub Form_Load()
Set myWs = DbEngine.Workspaces(0)
Set myDb = myWs.CreateDatabase (“D:\VB\Mahe\employee.mdb”, dbLangGeneral)
Set myTd = MyDb.CreateTableDef(“Empmast”)
Set myFields(0) = myTd.CreateField(“emp_no”, dbingeter)
Set myFields(1) = myTd.CreateField(“emp_name”, dbText,20)
Set myFields(2) = myTd.CreateField(“dept_no”, dbingeter)
Set myFields(3) = myTd.CreateField(“salary”, dbSingle)
Set myFields(4) = myTd.CreateField(“Jjoin_date”, dbDate)
myTd.Fields.Append myFields(0)
myTd.Fields.Append myFields(1)
myTd.Fields.Append myFields(2)
myTd.Fields.Append myFields(3)
myTd.Fields.Append myFields(4)
MyDb.TableDefs.Append myTd
MsgBox “DataBase Created”
End Sub

Private Sub cmdEdit_Click()


If Val(txtNo.Text) > 0 Then
mySet.Edit
framove.Visible = False
fraOther.Visible = False
cmdEdit.Visible = False
cmdAdd.Visible = False
Else
MsgBox(“nothing to edit”)
End if
End Sub

Private Sub cmdEnd_Click()


mySet.Close
myDb.close
Set myDb = nothing
End
End Sub

Private Sub Form_Load()


Set myDb = OpenDatabase(“D:\VB\Mahe\employee.mdb”)
Set mySet = myDb.OpenRecordset(“Empmast”, dbOpenDybaset)
End Sub

Вам также может понравиться