You are on page 1of 47

Government Polytechnic Karwar

Department of Computer Science & Engineering

Graphical User Interface Lab Manual


for
Third Semester

Department of Computer Science & Engineering


Page No:

Government Polytechnic Karwar


III sem GUI Lab
Date:

Program 1:Program to input two different integers using the function input box to compare
two numbers.
Source code:
Dim n1%, n2%
Private Sub cmdinput_Click( )
n1 = InputBox("Enter the first number", "first no")
Label1.Caption = "The First number is = " & n1
n2 = InputBox("Enter the Second number", "second no")
Label2.Caption = "The Second number is = " & n2
End Sub

Private Sub cmdcompare_Click( )


If (n1 = n2) Then
Label3.Caption = n1 & " is equal to " & n2
End If
If (n1 > n2) Then
Label3.Caption = n1 & " is smaller than "& n2
End If
If (n1 < n2) Then
Label3.Caption = n1 & " is smaller than "& n2
End If
End Sub

Private Sub cmdclear_Click()


Label1.Caption = ""
Label2.Caption = ""
Label3.Caption = ""
End Sub

Private Sub cmdexit_Click()


End
End Sub

Department of Computer Science & Engineering


Government Polytechnic Karwar
III sem GUI Lab
Date:

Page No:
OUTPUT:-

Properties Used:Control Used

Control Name

4 Commands
buttons

Cmd INPUT
Cmd COMPARE
Cmd CLEAR
Cmd EXIT

3 labels

Label 1
Label 2
Label3

1 Form

Form 1

Properties

Event

Name
Caption

Click

Caption
Caption

Department of Computer Science & Engineering


Page No:

Government Polytechnic Karwar


III sem GUI Lab
Date:

Program 2:Develop a class average program that will process an arbitrary number of
grades, each time the program is run.
Source code:
Option Explicit
Dim marks%, counter%, sum%
Dim aver As String

Private Sub cmdread_Click( )


marks = InputBox("Enter the Marks one by one(to end input-1)")
Print "Entered Marks are"
Print marks
sum = 0
counter = 0
Do Until (marks = -1)
sum = sum + marks
counter = counter + 1
marks = InputBox("Enter the marks one by one(to end input-1)")
Print marks
Loop
End Sub

Private Sub cmdaverage_Click( )


If (counter <> 0) Then
aver = sum / counter
Label1.Caption = "Average of Grade = " & aver
Else
Label1.Caption = "Average is Zero"
End If
End Sub
Private Sub cmdclear_Click( )
Label1.Caption = ""
Form1.Cls
End Sub
Private Sub cmdexit_Click( )
End
End Sub

Department of Computer Science & Engineering


Government Polytechnic Karwar
III sem GUI Lab

Page No:

Date:

OUTPUT:-

Properties Used:Control Used

Control Name

Properties

Event

4 Commands
buttons

cmd READ
cmd AVERAGE
cmd CLEAR
cmd EXIT

Name
Caption

Click

1 Label

Label 1

Caption

1 Form

Form 1

Caption

Department of Computer Science & Engineering


Page No:

Government Polytechnic Karwar


III sem GUI Lab
Date:

Program 3:Program to find the maximum of three numbers using Sub procedure.
Source code:
Option Explicit
Dim a%, b%, c%
Private Sub cmdminimum_Click( )
a = (Text1.Text)
b = (Text2.Text)
c = (Text3.Text)
Call minimum(a, b, c)
End Sub

Public Sub minimum(min%, y%, z%)


If (y < min) Then
min = y
End If
If (z < min) Then
min = z
End If
Label4.Caption = "Smallest Value is " & min
End Sub

Private Sub cmdclear_Click( )


Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Label4.Caption = ""
End Sub

Private Sub cmdexit_Click( )


End
End Sub

Department of Computer Science & Engineering


Page No:

Government Polytechnic Karwar


III sem GUI Lab
Date:

OUTPUT:-

Properties Used:Control Used


3 Commands
buttons
3 Text box

4 Labels

1 Form

Control Name
Cmd SMALLEST
Cmd CLEAR
Cmd EXIT
Text 1
Text 2
Text 3
Label 1
Label 2
Label 3
Label 4
Form 1

Properties

Events

Name
Caption

Click

Text

Caption

Caption

Department of Computer Science & Engineering


Page No:

Government Polytechnic Karwar


III sem GUI Lab
Date:

Program 4:Program to demonstrate function procedure.


Source code:
Option Explicit
Dim num As Integer
Dim i%

Private Sub cmdfactorial_Click( )


num = Val(Text1.Text)
Label2.Caption = "Factorial of " & num & " is " & fact(num)
End Sub

Public Function fact(ByVal m%) As Long


fact = 1
For i = 1 To m
fact = fact * i
Next i
End Function

Private Sub cmdclear_Click( )


Label2.Caption = ""
Text1.Text = ""
End Sub

Private Sub cmdexit_Click( )


End
End Sub

Department of Computer Science & Engineering


Government Polytechnic Karwar
III sem GUI Lab
Date:

Page No:
OUTPUT:-

Properties Used:Control Used


3 Commands
buttons
1 Text box
2 Labels
1 Form

Control Name
Cmd FACTORIAL
Cmd CLEAR
Cmd EXIT
Text 1
Label 1
Label 2
Form 1

Properties

Events

Name
Caption

Click

Text

Caption

Caption

Department of Computer Science & Engineering


Page No:

Government Polytechnic Karwar


III sem GUI Lab
Date:

Program 5:Program to demonstrate control array.


Source code:
Dim accesscode

Private Sub cmdENTER_Click( )


Dim msg As String
accesscode = Text1.Text
Select Case accesscode
Case Is < 1000
msg = "Access Denied"
Case 1645 To 1689
msg = "Technical Personal"
Case 8345
msg = "Custodial Services"
Case 1000006 To 1000008
msg = "Scientific Personal"
Case 55875
msg = "Special Services"
Case Else
msg = "Access Denied"
End Select
List1.AddItem (Now & Space$(3) & msg)
End Sub

Private Sub Command1_Click(Index As Integer)


Text1.Text = Text1.Text & Index
End Sub

Private Sub cmdCLEAR_Click()


Text1.Text = ""
End Sub

Private Sub cmdEXIT_Click()


End
End Sub

Department of Computer Science & Engineering


Government Polytechnic Karwar
III sem GUI Lab
Date:

Page No:
OUTPUT:-

Properties Used:Control Used


4 Commands
buttons
1 Text box
1 List box
1 Form

Control Name

Properties

Cmd ENTER
Cmd CLEAR
Cmd EXIT
Command 1
Text 1
List 1
Form 1

Name
Caption
Index
Text
List
Caption

Events
Click
-

Department of Computer Science & Engineering


Page No:

Government Polytechnic Karwar


III sem GUI Lab
Date:

Program 6:Program to demonstrate dynamic array.


Source code:
Option Explicit
Option Base 1
Dim a() As Integer
Dim n%, i%
Private Sub cmddisplay_Click()
Call List1.Clear
n = Val(Text1.Text)
If Check1.Value = vbUnchecked Then
ReDim a(n)
Call display_array
ElseIf Check1.Value = vbChecked Then
n = Val(Text1.Text)
ReDim Preserve a(n)
For i = LBound(a) To UBound(a)
List1.AddItem a(i)
Next i
End If
End Sub

Private Sub display_array()


For i = LBound(a) To UBound(a)
a(i) = Int(45 * Rnd(10))
List1.AddItem a(i)
Next i
End Sub

Private Sub cmdclear_Click()


List1.Clear
Text1.Text = ""
End Sub

Private Sub cmdexit_Click()


End
End Sub

Department of Computer Science & Engineering


Government Polytechnic Karwar
III sem GUI Lab
Date:

Page No:
OUTPUT:-

Properties Used:Control Used

Control Name

Properties

Events

3 Command buttons

cmd DISPLAY
cmd CLEAR
cmd EXIT

Name
Caption

Click

2 Labels

Label 1
Label 2

Caption

1 Text box

Text 1

Text

1 List box

List

List

1 Check box

Check 1

Value

Department of Computer Science & Engineering


Page No:

Government Polytechnic Karwar


III sem GUI Lab
Date:

Program 7:Program to demonstrate Param Array.


Source code:
Option Explicit
Private Sub Form_click( )
Call numarg
Call numarg(1)
Call numarg(2, 3)
Call numarg(4, 5, 6)
Call numarg(7, 8, 9, 10, 11, 12)
End Sub
Private Sub numarg(ParamArray x( ) As Variant)
Dim y As Integer
Print "Procedure NumArg Received:- ";
For y = LBound(x) To UBound(x)
Print x(y) & Space$(3);
Next y
Print
End Sub

Private Sub cmdexit_Click( )


End
End Sub

Private Sub cmdclear_Click( )


Form1.Cls
End Sub

Department of Computer Science & Engineering


Government Polytechnic Karwar
III sem GUI Lab
Date:

Page No:
OUTPUT:-

Properties Used:Control Used

Control Name

Properties

Event

2 Commands
buttons

cmd EXIT
cmd CLEAR

Name
Caption

Click

1 Form

Form 1

Caption

Department of Computer Science & Engineering


Page No:

Government Polytechnic Karwar


III sem GUI Lab
Date:

Program 8:Program to demonstrate Function Array.


Source code:
Option Base 1

Private Sub cmdprint_Click( )


Dim v As Variant, x As Integer
v = Array(3, 4, 7, 8, 9)
Print "Variant array values are ";
For x = LBound(v) To UBound(v)
Print v(x) & Space$(2);
Next x
Print
v = Array(4.5, 5.3, 6.4, 8.2)
Print "Variant array values are ";
For x = LBound(v) To UBound(v)
Print v(x) & Space$(2);
Next x
Print
v = Array("Hi", "Hello", "Bye")
Print "Variant array values are ";
For x = LBound(v) To UBound(v)
Print v(x) & Space$(2);
Next x
cmdprint.Enabled = False
End Sub

Private Sub cmdclear_Click( )


Form1.Cls
End Sub

Private Sub cmdexit_Click( )


End
End Sub

Department of Computer Science & Engineering


Government Polytechnic Karwar
III sem GUI Lab
Date:

Page No:
OUTPUT:-

Properties Used:Control Used

Control Name

Property

Event

3 Commands
buttons

cmd PRINT
cmd CLEAR
cmd EXIT

Name
Caption

Click

1 Form

Form 1

Caption

Department of Computer Science & Engineering


Page No:

Government Polytechnic Karwar


III sem GUI Lab
Date:

Program 9:Program to demonstrate String Functions.


Source code:
Private Sub List1_DblClick( )
If (List1.List(List1.ListIndex) = "STRCOMP") Then
n = StrComp(Text1.Text, Text2.Text)
If (n = 0) Then
Label4.Caption = "Strings are identical"
ElseIf (n = -1) Then
Label4.Caption = Text1.Text & " is less than " & Text2.Text
Else
Label4.Caption = Text1.Text & " is greater than " & Text2.Text
End If
ElseIf (List1.List(List1.ListIndex) = "STRREV") Then
Text2.Text = StrReverse(Text1.Text)
ElseIf (List1.List(List1.ListIndex) = "UCASE") Then
Text2.Text = UCase(Text1.Text)
ElseIf (List1.List(List1.ListIndex) = "LCASE") Then
Text2.Text = LCase(Text1.Text)
ElseIf (List1.List(List1.ListIndex) = "INSTR") Then
i = InStr(1, Text1.Text, Text2.Text)
If i = 0 Then
Label4.Caption = " Second String Not Found "
Else
Label4.Caption = " Second String Found At Position " & i
End If
End If
End Sub

Private Sub cmdclear_Click( )


Text1.Text = ""
Text2.Text = ""
Label4.Caption = ""
End Sub

Private Sub cmdexit_Click( )


End
End Sub

Department of Computer Science & Engineering


Page No:
OUTPUT:-

Government Polytechnic Karwar


III sem GUI Lab
Date:

Department of Computer Science & Engineering


Government Polytechnic Karwar
III sem GUI Lab
Date:

Page No:

Properties Used:Control Used


2 Command
button
4 Labels

2 Text box
1 List box
1 Form

Control Name
Cmd EXIT
Cmd Clear
Label 1
Label 2
Label 3
Label 4(Result)
Text 1
Text 2
List 1
Form 1

Properties
Name
Caption

Events

Caption

Caption

List
Caption

Db/Click
-

Click

Department of Computer Science & Engineering


Page No:

Government Polytechnic Karwar


III sem GUI Lab
Date:

Program 10:Design an application to change the color, font size, type of the form using Scroll
Bar.
Source code:
Private Sub VScroll1_Change()
Text1.ForeColor = QBColor(VScroll1.Value)
End Sub

Private Sub VScroll2_Change()


Text1.FontSize = VScroll2.Value
End Sub

Private Sub cmdCLEAR_Click()


Text1.Text = ""
End Sub

Private Sub cmdEXIT_Click()


End
End Sub

Department of Computer Science & Engineering


Government Polytechnic Karwar
III sem GUI Lab
Date:

Page No:

OUTPUT:-

Properties Used:Control Used

Control Name

Properties

Events

2 Commands
buttons

Cmd CLEAR
Cmd EXIT

Name
Caption

Click

1 Form

Form 1

Caption

2 Labels

Label 1
Label 2

Caption

2 Vscroll

Vscroll 1
Vscroll 2

Max,min
Max,min

Change

Department of Computer Science & Engineering


Page No:

Government Polytechnic Karwar


III sem GUI Lab
Date:

Program 11:Program to demonstrate Date and Time function.


Source code:
Private Sub cmddate_Click( )
Print "DATE FUNCTION "
Print "Current Date and Time : " & Now
Print "Date :" & Date
Print "Day :"; Day(Date)
Print "Weekday : "; Weekday(Date)
Print "Weekday Name : "; WeekdayName(Weekday(Date))
Print "Month : " & Month(Date)
Print "Month Name : "; MonthName(Month(Date))
Print "Month Name : abbreviated " & MonthName(Month(Date), True)
Print "...................................................................."
cmddate.Enabled = False
End Sub

Private Sub cmdtime_Click( )


Print "TIME FUNCTION"
Print "Time :" & Time
Print "Hour Time : " & Hour(Time)
Print "Minute Time :" & Minute(Time)
Print "Second Time :" & Second(Time)
Print "Time Serial (0,0,135) : " & TimeSerial(0, 0, 135)
Print "Time Serial (13,0,90) : " & TimeSerial(13, 0, 90)
Print "Time Serial (0,90,135) : " & TimeSerial(0, 90, 135)
Print "14.40 as a time is : " & TimeValue("14.40")
Print "...................................................................."
cmdtime.Enabled = False
End Sub

Private Sub cmdclear_Click( )


Form1.Cls
End Sub

Private Sub cmdexit_Click( )


End
End Sub

Department of Computer Science & Engineering


Government Polytechnic Karwar
III sem GUI Lab
Date:

Page No:

OUTPUT:-

Properties Used:Control Used

Control Name

Properties

Events

4 Commands

Cmd DATE
Cmd TIME
Cmd CLEAR
Cmd EXIT

Name
Caption

Click

1 Form

Form

Caption

Department of Computer Science & Engineering


Page No:

Government Polytechnic Karwar


III sem GUI Lab
Date:

Program 12:Program to demonstrate Adding and Subtracting dates with date and date
difference.
Source code:
Private Sub cmdaddsub_Click( )
Print "Date and Time :" & Now
Print "Date is :" & Date
Print "now+4 years :" & DateAdd("yyyy", 4, Now)
Print "now+130days : " & DateAdd("d", 130, Now)
Print "Days between 06/20/2013 and now :" & DateDiff("d", "06/20/2013", Now)
cmdaddsub.Enabled = False
End Sub

Private Sub cmdclear_Click( )


Form1.Cls
End Sub

Private Sub cmdexit_Click( )


End
End Sub

Department of Computer Science & Engineering


Government Polytechnic Karwar
III sem GUI Lab
Date:

Page No:

OUTPUT:-

Properties Used:Control Used

Control Name

Properties

Events

3 Commands

Cmd ADD SUBTRACT


Cmd CLEAR
Cmd EXIT

Name
Caption

Click

1 Form

Form

Caption

Department of Computer Science & Engineering


Page No:

Government Polytechnic Karwar


III sem GUI Lab
Date:

Program 13:Program to demonstrate Function Filter and Split.


Source code:
Private Sub cmdFILTER_Click( )
Dim a(6) As String, b() As String
a(0) = "JAVA"
a(1) = "VB6"
a(2) = "C++"
a(3) = "VB6"
a(4) = "C"
a(5) = "VB6"
Print "FILTER FUNCTION"
Print "Filtering for the string" & Space$(2) & "VB6"
b = Filter(a, "VB6")
Call display_array(b)
Print "--------------------------------------------------------"
Erase b
Print "Filtering for string after the " & Space$(2) & "VB6"
b = Filter(a, "VB6", False)
Call display_array(b)
Print "--------------------------------------------------------"
cmdFILTER.Enabled = False
End Sub
Private Sub display_array(c() As String)
Dim x%
For x = 0 To UBound(c)
Print c(x)
Next x
End Sub
Private Sub cmdSPLIT_Click( )
Dim z() As String, x As String, k%
Print "SPLIT FUNCTION"
x = "There is a sentence with 7 tokens"
z = Split(x)
For k = LBound(z) To UBound(z)
Print z(k)
Next k
Print "---------------------------------------------------------"
cmdSPLIT.Enabled = False
End Sub
Private Sub cmdCLEAR_Click( )
Form1.Cls
End Sub
Private Sub cmdEXIT_Click( )
Unload Me
End Sub

Department of Computer Science & Engineering


Government Polytechnic Karwar
III sem GUI Lab
Date:

Page No:

OUTPUT:-

Properties Used:Control Used

Control Name

Properties

Events

4 Commands

Cmd FILTER
Cmd SPLIT
Cmd CLEAR
Cmd EXIT

Name
Caption

Click

1 Form

Form

Caption

Department of Computer Science & Engineering


Page No:

Government Polytechnic Karwar


III sem GUI Lab
Date:

Program 14:Program to demonstrate timer control.


Source code:
Option Explicit

Dim x, y, r As Integer
Private Sub Form_Load()
Timer1.Interval = 1000
End Sub

Private Sub Timer1_Timer()


Call Randomize
x = 8000 - Rnd() * 8000
y = 8000 - Rnd() * 8000
r = 2000 - Rnd() * 1500
Form1.Circle (x, y), r
End Sub

Department of Computer Science & Engineering


Government Polytechnic Karwar
III sem GUI Lab
Date:

Page No:
OUTPUT:-

Properties Used:-

Control Used

Control Name

Properties

Events

1 Timer

Timer 1

Caption

Load

1 Form

Form

Caption

Department of Computer Science & Engineering


Page No:

Government Polytechnic Karwar


III sem GUI Lab
Date:

Program 15:Program to demonstrate Combobox Control.


Source code:
Dim str As String
Private Sub Combo1_Change ( )
Text1.Text = Combo1.List(Combo1.ListIndex)
End Sub

Private Sub Command1_Click ( )


str = InputBox("Enter String")
Combo1.AddItem (str)
Combo1.Text = str
Label1.Caption = "No. of items in combobox " & Combo1.ListCount
End Sub

Private Sub Command2_Click ( )


Text1.Text = "The Last Item Removed is " & Combo1.List(Combo1.ListIndex)
Combo1.RemoveItem (Combo1.ListIndex)
Label1.Caption = "No. of items in combobox " & Combo1.ListCount
End Sub

Private Sub Command3_Click ( )


Text1.Text = ""
End Sub
Private Sub Command4_Click()
End
End Sub

Department of Computer Science & Engineering


Page No:

Government Polytechnic Karwar


III sem GUI Lab
Date:

OUTPUT:-

Properties Used:Control Used


4 Command
buttons
1 Labels
1 Text box
1 Combo box
1 Form

Control Name
cmd ADDITEM
cmd REMOVEITEM
cmd CLEAR
cmd EXIT
Label 1
Text 1
Combo 1
Form 1

Properties

Events

Name
Caption

Click

Caption
Text
Text
Caption

Department of Computer Science & Engineering


Page No:

Government Polytechnic Karwar


III sem GUI Lab
Date:

Program 16:Design an application to validate the User Name and Password and display
appropriate message using msgbox ctrl.
Source code:
Dim username, password As String
Private Sub cmdin_Click ( )
username = Text1.Text
password = Text2.Text
If username = "COMPUTER" And password = "ASDF123" Then
MsgBox "WELCOME TO THE WORLD OF VISUAL BASIC "
Else
MsgBox "ACCESS DENIED"
End If
End Sub

Private Sub cmdclear_Click ( )


Text1.Text = ""
Text2.Text = ""
End Sub

Private Sub cmdout_Click ( )


End
End Sub

Department of Computer Science & Engineering


Government Polytechnic Karwar
III sem GUI Lab
Date:

Page No:
OUTPUT:-

Properties Used:Control Used

Control Name

Properties

Events

3 Command
buttons

cmd LOG-IN
cmd CLEAR
cmd LOG-OUT

Name
Caption

Click

2 Labels

Label 1
Label 2

Caption

2 Text box

Text 1
Text 2

Text
Password char

2 Form

Form 1
Form 2

Caption

Department of Computer Science & Engineering


Page No:

Government Polytechnic Karwar


III sem GUI Lab
Date:

Program 17 a:Program to demonstrate Pull-Down menu.


Source code:
Private Sub mnured_Click( )
Text1.ForeColor = vbRed
End Sub
Private Sub mnugreen_Click( )
Text1.ForeColor = vbGreen
End Sub
Private Sub mnuleft_Click( )
Text1.Alignment = 0
End Sub
Private Sub mnuright_Click( )
Text1.Alignment = 1
End Sub
Private Sub mnucenter_Click( )
Text1.Alignment = 2
End Sub
Private Sub mnubold_Click( )
Text1.FontBold = True
End Sub
Private Sub mnuitalics_Click( )
Text1.FontItalic = True
End Sub
Private Sub mnuunder_Click()
Text1.FontUnderline = True
End Sub
Private Sub mnudefault_Click()
Text1.ForeColor = vbBlack
Text1.FontBold = False
Text1.FontItalic = False
Text1.FontUnderline = False
Text1.Alignment = 2
End Sub
Private Sub cmdclear_Click( )
Text1.Text = ""
End Sub
Private Sub cmdexit_Click( )
End
End Sub

Department of Computer Science & Engineering


Page No:

Government Polytechnic Karwar


III sem GUI Lab
Date:

OUTPUT:-

Properties Used:-

2 Command
buttons

Control
Name
cmd CLEAR
cmd EXIT

1 Form

Form 1

Caption

Text

Alignment- 0 1 2
Font -BIU/D
Color-RGB
All should be visible

Menu Editor

Control Used

1 Text

Properties

Events

Name
Caption

Click

Department of Computer Science & Engineering


Page No:

Government Polytechnic Karwar


III sem GUI Lab
Date:

Procedure:
STEP 1: Start a new VB project and invoke the Menu Editor by select the Menu Editor option from the
Tools menu.
GO to tools Click on menu Editor a Menu Editor window will appear
OR
Right click on formSelect Menu Editor
STEP 2: For "Caption", type &ALIGNMENT For "Name", type mnuAlign.
STEP 3: Click the "right-arrow" button A ellipsis (...) will appear as the next item in the menu list,
indicating that this item is a level-two item (within "ALIGNMENT").
STEP 4: For "Caption", type LEFT; for "Name", type mnuLeft, and for "Shortcut", select Ctrl+L. By
specifying a shortcut.
STEP 5: For "Caption", type &CENTER; for "Name", type mnuCenter, and for "Shortcut", select
Ctrl+C.
STEP 6: Again For "Caption", type &RIGHT; for "Name", type mnuRight, and for "Shortcut", select
Ctrl+R.

STEP 7: Follow the same procedure for COLOR(GREEN, RED, BLUE) and for FONT (BOLD,
ITALIC, UNDERLINE , - and DEFAULT).
STEP 8: At this point, we are done creating our menu entries, so click the OK button. That will dismiss
the menu editor and return focus to the VB IDE.
STEP 9: Back in the VB IDE, your form will now have a menu, based on what we have set up in the
Menu Editor. If we click on a top-level menu item
STEP 10: Double-click the form to open the Code Editor, and write the program code.

Department of Computer Science & Engineering


Page No:

Government Polytechnic Karwar


III sem GUI Lab
Date:

Program 17 b:Program to demonstrate POP-UP menu.


Source code:
Private Sub Label1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = vbRightButton Then
PopupMenu mnupop, vbPopupMenuRightButton
End If
End Sub
Private Sub mnubold_Click()
If mnuBold.Checked Then
Label1.FontBold = False
mnuBold.Checked = False
Else
Label1.FontBold = True
mnuBold.Checked = True
End If
End Sub
Private Sub mnuitalic_Click()
If mnuItalic.Checked Then
Label1.FontItalic = False
mnuItalic.Checked = False
Else
Label1.FontItalic = True
mnuItalic.Checked = True
End If
End Sub
Private Sub mnuunderline_Click()
If mnuUnderline.Checked Then
Label1.FontUnderline = False
mnuUnderline.Checked = False
Else
Label1.FontUnderline = True
mnuUnderline.Checked = True
End If
End Sub

Department of Computer Science & Engineering


Page No:

Government Polytechnic Karwar


III sem GUI Lab
Date:

OUTPUT:-

Properties Used:Control Used

Control
Name

Properties

Events

1 Label

Label1

Name
Caption (Visual Basics)

1 Form

Form 1

Caption

Text

Font BOLD
Font ITALIC
FONT UNDERLINE
All should be visible
(Except POP)

Menu Editor

1 Text

Department of Computer Science & Engineering


Page No:

Government Polytechnic Karwar


III sem GUI Lab
Date:

Procedure:
STEP 1: Start a new VB project and place a label on the form. Name the label lblTestText. Set the
Caption to VISUAL BASICS

STEP 2: Open the Menu Editor, and create a top-level item with a Caption value of POP and the Name
mnuPop. Also importantly uncheck the Visible checkbox. In order for a menu to be a pop-up menu, it
must be invisible.

STEP 3: Create the following level-two menu items below the POP top-level menu. (When creating
these level-two items, keep the Visible box checked.)

STEP 4:

STEP 5: Click OK to save your changes. Note: When you return to the IDE, we will NOT see this
menu on the form (remember it's a pop-up menu, and it will only be visible when invoked through
code).

STEP 6: Double-click the form to open the Code Editor, and write the program code.

STEP 7: Button parameter is testedfor vbRightButton as is conventional, we only want to pop up the
menu if the user right-clicks on the label. If the user clicks the right mouse button, the PopupMenu
statement is executed.

Department of Computer Science & Engineering


Page No:

Government Polytechnic Karwar


III sem GUI Lab
Date:

Program 18:Program to demonstrate Nested on Error Statement.


Source code:
Private Sub cmddivide_Click ( )
Dim n%, d%
On Error GoTo input_handle
n = Text1.Text
d = Text2.Text
On Error GoTo divide_by_zero_handle
Label3.Caption = "Result is=" & n / d
Exit Sub
divide_by_zero_handle:
Label3.Caption = "Attempted Divide By zero"
Exit Sub
input_handle:
Label3.Caption = "Attempted Non-Numeric Output"
Exit Sub
End Sub

Private Sub cmdclear_Click ( )


Text1.Text = ""
Text2.Text = ""
Label3.Caption = ""
End Sub

Private Sub cmdexit_Click ( )


End
End Sub

Department of Computer Science & Engineering


Page No:

Government Polytechnic Karwar


III sem GUI Lab
Date:

Output:

Properties Used:Control Used

Control Name

Properties

Events

3 Commands
buttons

Cmd DIVIDE
Cmd CLEAR
Cmd EXIT

Name
Caption

Click

3 Label

Label 1
Label 2
Label 3

Caption

2 Text box

Text 1
Text 2

Text

1 Form

Form 1

Caption

Department of Computer Science & Engineering


Page No:

Government Polytechnic Karwar


III sem GUI Lab
Date:

Program 19:Program to demonstrate Linear Search.


Source code:
Dim a(10) As Integer
Dim key%, n%, i%

Private Sub cmdsearch_Click ( )


key = Val(Text1.Text)
For i = 1 To n
If (a(i) = key) Then
MsgBox ("Key Element found at position " & i)
Exit Sub
End If
Next i
MsgBox ("Key Element not found")
End Sub

Private Sub cmdread_Click ( )


n = InputBox("Enter the Size of an Array")
For i = 1 To n
a(i) = InputBox("Enter the Array Elements")
List1.AddItem (a(i))
Next i
End Sub
Private Sub cmdclear_Click()
Text1.Text = ""
End Sub
Private Sub cmdexit_Click ( )
Unload Me
End Sub

Department of Computer Science & Engineering


Government Polytechnic Karwar
III sem GUI Lab
Date:

Page No:
Output:

Properties Used:Control Used


4Command
buttons
2 Labels

Control Name
cmd READ
cmd SEARCH
cmd CLEAR
cmd EXIT
Label 1
Label 2

Properties

Events

Name
Caption

Click

Caption

1 Text box

Text 1

Text

1 List box

List

List

1 Form

Form 1

Caption

Department of Computer Science & Engineering


Page No:

Government Polytechnic Karwar


III sem GUI Lab
Date:

Program 20:Design an application which performs the following operations on the data base
the form using ADO 1.ADD 2.UPDATE 3.DELETE
Source code:
Private Sub cmdadd_Click()
Data1.Recordset.AddNew
cmdadd.Visible = False
cmdupdate.Visible = True
End Sub

Private Sub cmddelete_Click()


If Data1.Recordset.RecordCount > 0 Then
If MsgBox("do you want to delete?press yes or no", vbYesNo + vbInformation) = vbYes Then
Data1.Recordset.Delete
Data1.Refresh
End If
End If
End Sub

Private Sub cmdupdate_Click()


Data1.Recordset.Update
cmdadd.Visible = True
cmdupdate.Visible = False
End Sub

Private Sub cmdexit_Click()


End
End Sub

Department of Computer Science & Engineering


Page No:

Government Polytechnic Karwar


III sem GUI Lab
Date:

Output:

Properties Used:Control Used

Control Name

Property

Events

3 Commands
buttons

Cmd UPDATE
Cmd DELETE
Cmd ADD

Name
Caption

Click

2 Text box

Text 1
Text 2

Text
Data Source
Data Field

2 Labels

Label 1
Label 2

Caption

1 ADODC

DATA 1

Caption

Department of Computer Science & Engineering


Government Polytechnic Karwar
III sem GUI Lab
Date:

Page No:

PROCEDURE:
Step 1: Right click on the toolbar
(OLEDB)

apply

components

select the Microsoft ADO data control 6.0

ok.

Step 2: Drag the ADODC tool on the form.


Step 3: Go to ADDINS
Microsoft access

visual data manager. A dialog box will appear. Go to file

version 7.0 MDB

create a file and save.

Step 4: Then a dialog box will appear, right click on the properties
will appear give table name
close

add field

click on build table

new

new table, another dialog box

a dialog box will appear (give Roll No, Name etc)

ok

double click on the table name, then a dialog box will appear,

then click on ADD (To add details click on update. If you want to enter some more details then repeat
step 4. )

close the window.

Step 5: Right click on ADODC button


build

ADODC properties , a dialog box will appear

select Microsoft jet 4.0 OLE DB provider

click on next

select the Microsoft access file which you have saved and open it

click on

enter the database name

click on test connection

click

on ok.
Step 6: Go to Record source
stored procedure name

click on command type

then select the file

apply

select 2-nd cmd table


ok.

Step 7: Draw 4 command buttons for add, update, delete, and exit.
Step 8: Draw 2 labels for student name and roll no.
Step 9: Take 2 text boxes
Step 10: Then write the code.

go to properties and change data source and data field.

click on table or

You might also like