You are on page 1of 43

# Acharya Polytechnic, Department of Computer Science

## Program No. 1 Date of Experiment……………….

Aim: Program to input two different integers using the function input box to
compare two numbers

## Design the Form:

Procedure:

1. Open Visual Basic 6.0. On the File menu, choose New Project.
2. In the New Project dialog box, choose Standard EXE, and click OK.
3. Select the first Label, and set the Name property to lbldisplay1 and the Caption
property to Clear.
4. Select the Second Label, and set the Name property to lbldisplay2 and the Caption
property to Clear.
5. Select the Third Label, and set the Name property to lbldisplay3 and the Caption
property to Clear.
6. Select the first CommandButton, and set the Name property to CmdEnternumbers and
the Caption property to Enter Numbers.
7. Select the Second CommandButton, and set the Name property to CmdExit and the
Caption property to Exit.
8. Double-click the form to open the Code Editor, and enter the following code.

## Private Sub cmdEnterNumbers_Click()

Dim num1 As Integer, num2 As Integer

## G.U.I LAB MANUAL

Page 1
Acharya Polytechnic, Department of Computer Science

## ' Clear Labels

lblDisplay1.Caption = ""
lblDisplay2.Caption = ""
lblDisplay3.Caption = ""
lblDisplay4.Caption = ""

## ' Get values from user

num1 = InputBox("Enter first integer", "Input")
num2 = InputBox("Enter second integer", "Input")

## ' Test the relationships between the numbers

If num1 = num2 Then
lblDisplay1.Caption = num1 & " is equal to " & num2
End If
If num1 <> num2 Then
lblDisplay1.Caption = num1 & " is not equal to " & num2
End If
If num1 > num2 Then
lblDisplay2.Caption = num1 & " is greater than " & num2
End If
If num1 < num2 Then
lblDisplay2.Caption = num1 & " is less than " & num2
End If
If num1 >= num2 Then
lblDisplay3.Caption = num1 & _
" is greater than or equal to " _
& num2
End If
If num1 <= num2 Then
lblDisplay4.Caption = num1 & _
" is less than or equal to " & num2
End If
End Sub

## Private Sub cmdExit_Click()

End
End Sub

9. Press F5 to run the application or Click Run button form the tool bar.
10. First input dialog displedy for user input. Input a value before press ok
11. Second input dialog displayed for user input. Input a value before press ok
12. GUI after second input dialog box is closed as shown in figure 2
13. On the File menu, choose Save Project As.
14. In the Save File As dialog box, save the form as compare.frm and save the project as
comparetwonumbers.vbp.

## G.U.I LAB MANUAL

Page 2
Acharya Polytechnic, Department of Computer Science

Result in GUI

## G.U.I LAB MANUAL

Page 3
Acharya Polytechnic, Department of Computer Science

## Program No. 2 Date of Experiment……………….

Aim: Develop a class average program that will process an arbitrary number of
grades, each time the program is run.

Procedure:

1. Open Visual Basic 6.0. On the File menu, choose New Project.
2. In the New Project dialog box, choose Standard EXE, and click OK.
3. Select the first Label, and set the Name property to lbldisplay1 and the Caption
property to Clear.
4. Select the first CommandButton, and set the Name property to CmdEnterData and the
5. Select the Second CommandButton, and set the Name property to CmdExit and the
Caption property to Exit.
6. Double-click the form to open the Code Editor, and enter the following code.

## ' Class average program '

Option Explicit ' General declaration
Private Sub cmdEnterData_Click()
Dim total As Integer ' Sum of all grades input
Dim counter As Integer ' Number of grades input
Dim average As Single ' Floating-point average
Dim message As String ' Text displayed in Label

total = 0
counter = 0

## G.U.I LAB MANUAL

Page 4
Acharya Polytechnic, Department of Computer Science

## ' Loop until grade has a -1 value

counter = counter + 1 ' Increment counter
' Input the next grade. When -1 is assigned,
' the loop continuation condition becomes True
Loop

## ' Termination phase

If counter <> 0 Then ' Prevent division by zero
average = total / counter ' Floating-point division
message = "Class average is "

## ' Format average and concatenate to message

message = message & average
lblAverage.Caption = message

## Else ' counter is 0

lblAverage.Caption = "No grades were entered."
End If
End Sub

## Private Sub cmdExit_Click()

End
End Sub

7. Press F5 to run the application or Click Run button form the tool bar.
8. Input dialog displayed for user input. Input a value before press ok
9. Again Input dialog displayed for user input. Input a value before press ok and to exit
from Input dialog box enter value -1.
10. GUI after enter -1 and press ok , input dialog box is closed as shown in figure 2
11. On the File menu, choose Save Project As.
12. In the Save File As dialog box, save the form as classavg.frm and save the project as
classaverage.vbp.

## G.U.I LAB MANUAL

Page 5
Acharya Polytechnic, Department of Computer Science

## G.U.I LAB MANUAL

Page 6
Acharya Polytechnic, Department of Computer Science

## Program No. 3 Date of Experiment……………….

Aim: Program to find the minimum of three numbers using sub procedures

Procedure:

1. Open Visual Basic 6.0. On the File menu, choose New Project.
2. In the New Project dialog box, choose Standard EXE, and click OK.
3. Select the first Label, and set the Name property to lbldisplay1 and the Caption
property to Enter first value:. And Select next to label TextBox, and set the Name
property to Txtone and the Text property to Clear.
4. Select the Second Label, and set the Name property to lbldisplay2 and the Caption
property to Enter Second value:. And Select next to label TextBox, and set the Name
property to Txttwo and the Text property to clear.
5. Select the Third Label, and set the Name property to lbldisplay3 and the Text property
to Enter third value:. And Select next to label TextBox, and set the Name property
to Txtthree and the Text property to clear.
6. Select the first CommandButton, and set the Name property to cmdsmallest and the
Caption property to Enter Numbers.
7. Select the Second CommandButton, and set the Name property to CmdExit and the
Caption property to Exit.
8. Double-click the form to open the Code Editor, and enter the following code.

## ' Program finds the minimum of three numbers input

Option Explicit ' General declaration

## G.U.I LAB MANUAL

Page 7
Acharya Polytechnic, Department of Computer Science

## Dim value1 As Long, value2 As Long, value3 As Long

value1 = txtOne.Text
value2 = txtTwo.Text
value3 = txtThree.Text

End Sub

min = y
End If

min = z
End If

End Sub

## Private Sub CmdExit_Click()

End
End Sub

9. Press F5 to run the application or Click Run button form the tool bar.
10. Enter a number in first textbox.
11. Enter a number in Second Textbox
12. Enter a number in Third Textbox and Click on command button Smallest and see the
output on GUI as shown in Figure.
13. On the File menu, choose Save Project As.
14. In the Save File As dialog box, save the form as smallest.frm and save the project as
smallestno.vbp.

RESULT IN GUI:

## G.U.I LAB MANUAL

Page 8
Acharya Polytechnic, Department of Computer Science

## Program No. 4 Date of Experiment……………….

Procedure:

1. Open Visual Basic 6.0. On the File menu, choose New Project.
2. In the New Project dialog box, choose Standard EXE, and click OK.
3. Select the first Label, and set the Name property to lbldisplay and the Caption
property to Enter a Number.
4. Select the first CommandButton, and set the Name property to cmdrun and the Caption
property to Rum
5. Select the first CommandButton, and set the Name property to cmdclear and the
Caption property to Clear
6. Select the Second CommandButton, and set the Name property to CmdExit and the
Caption property to Exit.
7. Double-click the form to open the Code Editor, and enter the following code.

Option Explicit

## Private Sub cmdClear_Click()

Cls
Lbldisplay.Caption = "Enter a number"

End Sub

## Private Sub cmdExit_Click()

G.U.I LAB MANUAL
Page 9
Acharya Polytechnic, Department of Computer Science

End
End Sub

## intNum = Val(InputBox("Enter a number:", "IsOdd Test"))

Lbldisplay.Caption = ""
If IsOdd(intNumIn) Then
Print "The number that you entered is odd."
Else
Print "The number that you entered is not odd."
End If
End Sub

## If (Num Mod 2) = 0 Then

IsOdd = False
Else
IsOdd = True
End If
End Function

8. Press F5 to run the application or Click Run button form the tool bar.
9. Click on command button Run. A InputBox dialogue appear on the screen to input a
number.
10. Enter a number and press Ok to accept the number.
11. See the result in GUI as shown in Figure.
12. On the File menu, choose Save Project As.
13. In the Save File As dialog box, save the form as funproc.frm and save the project as
oddnotest.vbp.

GUI Output:

## G.U.I LAB MANUAL

Page 10
Acharya Polytechnic, Department of Computer Science

## Program No.5 Date of

Experiment……………….

## Aim: Program to demonstrate ctrl array

Procedure:

1. Open Visual Basic 6.0. On the File menu, choose New Project.
2. In the New Project dialog box, choose Standard EXE, and click OK.
3. Select the first CommandButton, and set the Name property to cmdTest and the
Caption property to First
4. Copy the first CommandButton, and paste it on the form; the Caption property to
Second
5. Copy the first CommandButton, and paste it on the form; the Caption property to
Third
6. Copy the first CommandButton, and paste it on the form; the Caption property to
Fourth
7. Double-click the form to open the Code Editor, and enter the following code.

## Private Sub CmdTest_Click(Index As Integer)

Print " You have Clicked Command Button " & CmdTest(Index).Caption
End Sub

8. Press F5 to run the application or Click Run button from the tool bar.
9. See the result in GUI as shown in Figure.
10. On the File menu, choose Save Project As.

## G.U.I LAB MANUAL

Page 11
Acharya Polytechnic, Department of Computer Science

11. In the Save File As dialog box, save the form as controlarray.frm and save the project
as crltarray.vbp.

GUI Output:

## G.U.I LAB MANUAL

Page 12
Acharya Polytechnic, Department of Computer Science

## Program No.6 Date of

Experiment……………….

## Aim: Program to demonstrate dynamic array

Form Design

Procedure:

1. Open Visual Basic 6.0. On the File menu, choose New Project.
2. In the New Project dialog box, choose Standard EXE, and click OK.
3. Select the first Label, and set the Name property to lbldisplay1 and the Caption
property to DEMONSTRATION OF DYNAMIC ARRAY.
4. Select the ListBox and set the Name property to Listarray
5. Select the CommandButton, and set the Name property to Cmdrun and the Caption
property to RUN.
6. Select the CommandButton, and set the Name property to CmdErase and the Caption
property to ERASE
7. Select the CommandButton, and set the Name property to CmdExit and the Caption
property to EXIT
8. Double-click the form to open the Code Editor, and enter the following code.

Option Explicit
-----------------------------------------------------------------------------------------------------
Dim myArray() As String

## Private Sub CmdErase_Click()

Erase myArray
G.U.I LAB MANUAL
Page 13
Acharya Polytechnic, Department of Computer Science

Call Listarray.Clear
CmdErase.Enabled = False
End Sub
------------------------------------------------------------------------------------------------------
Private Sub Cmdrun_Click()
Dim values As Integer
Dim range As Integer
Dim x As Integer

## values = InputBox("How many elements?")

range = values - 1
ReDim myArray(range)

For x = 0 To range
myArray(x) = InputBox("Enter Element")
Next x
CmdErase.Enabled = True
End Sub
--------------------------------------------------------------------------------------------------------
Private Sub Exit_Click()
End
End Sub
-------------------------------------------------------------------------------------------------------

12. Press F5 to run the application or Click Run button from the tool bar.
13. See the result in GUI as shown in Figure.
14. On the File menu, choose Save Project As. In the Save File As dialog box, save the form
as with suitable name.

GUI Output:

## G.U.I LAB MANUAL

Page 14
Acharya Polytechnic, Department of Computer Science

## Program No.7 Date of

Experiment……………….

## Aim: Program to demonstrate param array

Form Design:

Procedure:

1. Open Visual Basic 6.0. On the File menu, choose New Project.
2. In the New Project dialog box, choose Standard EXE, and click OK..
3. Select the first CommandButton, and set the Name property to Cmddisp and the
Caption property to Display.
4. Double-click the form to open the Code Editor, and enter the following code.

Option Explicit
---------------------------------------------------------------------------------------------
Private Sub Cmddisp_Click()
Call parray
Call parray(1)
Call parray(2, 3)
Call parray(4, 5, 6)
Call parray(7, 8, 9, 10, 11, 12)
End Sub
------------------------------------------------------------------------------------------------
Private Sub parray(ParamArray x() As Variant)
Dim y As Integer

## G.U.I LAB MANUAL

Page 15
Acharya Polytechnic, Department of Computer Science

## Print "Procedure AnyNumberArguments received "

For y = LBound(x) To UBound(x)
Print x(y) & Space\$(4);
Next y

Print
End Sub
----------------------------------------------------------------------------------------------------

5. Press F5 to run the application or Click Run button from the tool bar.
6. See the result in GUI as shown in Figure.
7. On the File menu, choose Save Project As. In the Save File As dialog box, save the form
as with suitable name.

GUI Output:

## G.U.I LAB MANUAL

Page 16
Acharya Polytechnic, Department of Computer Science

## Program No.8 Date of

Experiment……………….

## Aim: Program to demonstrate function array

Design Form:

Procedure:

1. Open Visual Basic 6.0. On the File menu, choose New Project.
2. In the New Project dialog box, choose Standard EXE, and click OK..
3. Select the first CommandButton, and set the Name property to Cmddisp and the
Caption property to Display.
4. Double-click the form to open the Code Editor, and enter the following code.

Option Explicit
---------------------------------------------------------------------------------------------
Private Sub cmdPrint_Click()
Dim v As Variant, x As Integer

v = Array(7, 5, 6, 9, 3, 0)
Print "Variant array values are: ";
For x = LBound(v) To UBound(v)
Print v(x) & Space\$(2);
Next x
G.U.I LAB MANUAL
Page 17
Acharya Polytechnic, Department of Computer Science

Print
v = Array("hello", "bye", "hi")
Print "Variant array values are: ";
For x = LBound(v) To UBound(v)
Print v(x) & Space\$(2);
Next x

Print
v = Array(1.1, 2.2, 3.3, 4.4)
Print "Variant array values are: ";
For x = LBound(v) To UBound(v)
Print v(x) & Space\$(2);
Next x
cmdPrint.Enabled = False
End Sub
--------------------------------------------------------------------------------------------------------

5. Press F5 to run the application or Click Run button from the tool bar.
6. See the result in GUI as shown in Figure.
7. On the File menu, choose Save Project As. In the Save File As dialog box, save the form
as with suitable name.

GUI Output:

## G.U.I LAB MANUAL

Page 18
Acharya Polytechnic, Department of Computer Science

## Program No.9 Date of

Experiment……………….

## Aim: Program to demonstrate string functions

Design Form

Procedure:

1. Open Visual Basic 6.0. On the File menu, choose New Project.
2. In the New Project dialog box, choose Standard EXE, and click OK.
3. Select the first CommandButton, and set the Name property to Cmddisp and the
Caption property to Display.
4. Double-click the form to open the Code Editor, and enter the following code.

Option Explicit
------------------------------------------------------
Dim stringl As String, string2 As String
Dim result As Integer

## Private Sub Cmddisp_Click()

stringl = "It was the best of times,"
string2 = "best of times"

result = Len(string2)

## G.U.I LAB MANUAL

Page 19
Acharya Polytechnic, Department of Computer Science

Print result
Print
Print
Print
Print
result = InStr(stringl, string2)
Print result
Print
Print
End Sub
----------------------------------------------------------------------------------------------------

8. Press F5 to run the application or Click Run button from the tool bar.
9. See the result in GUI as shown in Figure.
10. On the File menu, choose Save Project As. In the Save File As dialog box, save the form
as with suitable name.

GUI Output:

## G.U.I LAB MANUAL

Page 20
Acharya Polytechnic, Department of Computer Science

## Program No.10 Date of Experiment……………….

Aim: Design an application to validate the user name & password & display
appropriate msg using msg box ctrl

Design Form:

Procedure:

1. Open Visual Basic 6.0. On the File menu, choose New Project.
2. In the New Project dialog box, choose Standard EXE, and click OK.
3. Select TextBox and set the Name Property to Text1
4. Select TextBox and set the Name Property to Text2 and set PasswordChar to *
5. Select the first CommandButton, and set the Name property to Cmdlogin and the
6. Select the Second CommandButton, and set the Name property to Cmdcancel and the
Caption property to Cancel.
7. Double-click the form to open the Code Editor, and enter the following code.

Option Explicit
--------------------------------------------------------------------------------------------------------------
Dim a, b As Integer

## Private Sub Cmdcancel_Click()

End
End Sub
--------------------------------------------------------------------------------------------------------------

## G.U.I LAB MANUAL

Page 21
Acharya Polytechnic, Department of Computer Science

If Text1.Text = "AAA" And Text2.Text = "BBB" Then
Else
End If
End Sub

8. Press F5 to run the application or Click Run button from the tool bar.
9. See the result in GUI as shown in Figure.

On the File menu, choose Save Project As. In the Save File As dialog box, save the form as
with suitable name
GUI Output:

## G.U.I LAB MANUAL

Page 22
Acharya Polytechnic, Department of Computer Science

## Aim: Program to demonstrate date and time functions

DEGIGN FORM:

Procedure:

1. Open Visual Basic 6.0. On the File menu, choose New Project.
2. In the New Project dialog box, choose Standard EXE, and click OK.
3. Select the first Label, and set the Name property to lbldisplay1 and the Caption
property to Clear.
4. Select the first CommandButton, and set the Name property to CmdEnterData and the
5. Select the Second CommandButton, and set the Name property to CmdExit and the
Caption property to Exit.
6. Select the Second CommandButton, and set the Name property to CmdExit and the
Caption property to Exit
7. Double-click the form to open the Code Editor, and enter the following code.

Option Explicit

Call lstOutput.AddItem("Current date and time: " & Now)
G.U.I LAB MANUAL
Page 23
Acharya Polytechnic, Department of Computer Science

## Call lstOutput.AddItem("Year: " & Year(Date))

End Sub
----------------------------------------------------------------------------------------------------

8. Press F5 to run the application or Click Run button from the tool bar.
9. See the result in GUI as shown in Figure.
10. On the File menu, choose Save Project As. In the Save File As dialog box, save the form
as with suitable name

GUI Output:

## G.U.I LAB MANUAL

Page 24
Acharya Polytechnic, Department of Computer Science

## Program No.12 Date of Experiment……………….

Aim: Program to demonstrate adding and subtracting dates with date add and date diff

Form Design:

Procedure:

1. Open Visual Basic 6.0. On the File menu, choose New Project.
2. In the New Project dialog box, choose Standard EXE, and click OK.
3. Select the Listbox, and set the Name property to Lstoutput
4. Double-click the form to open the Code Editor, and enter the following code.

Option Explicit
----------------------------------------------------------------------------------------------------------------

Call lstOutput.AddItem("Days between 1/1/98 and " & "12/31/98: " & DateDiff("d",
"1/1/98", "12/31/98"))
End Sub
---------------------------------------------------------------------------------------------------------------------

5. Press F5 to run the application or Click Run button from the tool bar.
6. See the result in GUI as shown in Figure.
7. On the File menu, choose Save Project As. In the Save File As dialog box, save the form
as with suitable name

GUI Output:

## G.U.I LAB MANUAL

Page 25
Acharya Polytechnic, Department of Computer Science

## Aim: Program to demonstrate function filter & split

Procedure:

1. Open Visual Basic 6.0. On the File menu, choose New Project.
2. In the New Project dialog box, choose Standard EXE, and click OK.
3. Select the first CommandButton, and set the Name property to Cmdfilter and the
4. Select the Second CommandButton, and set the Name property to Cmdsplit and the
Caption property to Exit.
5. Double-click the form to open the Code Editor, and enter the following code.

Option Explicit
-----------------------------------------------------------------------------------------------------------
Private Sub Cmdfilter_Click()
Dim a(9) As String, b() As String

a(0) = "Java"
a(1) = "Visual Basic"
a(2) = "C"
a(3) = "C++"
a(4) = "Visual Basic"
a(5) = "HTML"
a(6) = "Visual Basic"
a(7) = "Visual C++ "
a(8) = "Visual J++ "
a(9) = "Visual Basic"
Call Cls
Print "Filtering for the string: " & "Visual Basic 6"
G.U.I LAB MANUAL
Page 26
Acharya Polytechnic, Department of Computer Science

## b = Filter(a, "Visual Basic")

Call PrintStrings(b)
Print
Erase b

Print "Filtering for strings other than: " & "Visual Basic 6"
b = Filter(a, "Visual Basic", False)
Call PrintStrings(b)
End Sub
---------------------------------------------------------------------------------------------------------------------
Private Sub PrintStrings(c() As String)
Dim z As Integer

For z = 0 To UBound(c)
Print c(z)
Next z

End Sub
-------------------------------------------------------------------------------------------------------------
Private Sub Cmdsplit_Click()
Dim x() As String, y As String
Dim z As Integer
Call Cls
y = "This is a sentence with 7 words"
x = Split(y)

## For z = LBound(x) To UBound(x)

Print x(z)
Next z
End Sub
-------------------------------------------------------------------------------------------------------------------

6. Press F5 to run the application or Click Run button from the tool bar.
7. See the result in GUI as shown in Figure.
8. On the File menu, choose Save Project As. In the Save File As dialog box, save the form
as with suitable name

## G.U.I LAB MANUAL

Page 27
Acharya Polytechnic, Department of Computer Science

GUI Output:

## G.U.I LAB MANUAL

Page 28
Acharya Polytechnic, Department of Computer Science

## Aim: Program to demonstrate timer ctrl

Procedure:

1. Open Visual Basic 6.0. On the File menu, choose New Project.
2. In the New Project dialog box, choose Standard EXE, and click OK.
3. Select the first CommandButton, and set the Name property to CmdStart and the
Caption property to Start Timer..
4. Select the Second CommandButton, and set the Name property to CmdStop and the
Caption property Stop Timer.
5. Select the TimerButton and set the Name property to tmrTest and set the Interval
property to 250
6. Double-click the form to open the Code Editor, and enter the following code.

Option Explicit
-------------------------------------------------------------------------------------------------
Private mintCount As Integer

## Private Sub cmdStart_Click()

mintCount = 0
Cls
tmrTest.Enabled = True

End Sub
-------------------------------------------------------------------------------------------------

## G.U.I LAB MANUAL

Page 29
Acharya Polytechnic, Department of Computer Science

## Private Sub cmdStop_Click()

tmrTest.Enabled = False

End Sub
---------------------------------------------------------------------------------------------------

## Private Sub tmrTest_Timer()

mintCount = mintCount + 1

## Print "Timer fired again. Count = " & mintCount

End Sub

7. Press F5 to run the application or Click Run button from the tool bar.
8. See the result in GUI as shown in Figure.
9. On the File menu, choose Save Project As. In the Save File As dialog box, save the form
as with suitable name

GUI Output:

## G.U.I LAB MANUAL

Page 30
Acharya Polytechnic, Department of Computer Science

## Aim: Program to demonstrate combo box ctrl

GUI Design:

Procedure:

1. Open Visual Basic 6.0. On the File menu, choose New Project.
2. In the New Project dialog box, choose Standard EXE, and click OK.
3. Select the ComboBox , and set the Name property to Combo1
4. Select the CommandButton, and set the Name property to cmdAdd and the Caption
5. Select theCommandButton and set the Name property to cmdClear and the Caption
Property to Clear
6. Select the ListBox and set the Name property to List1
7. Double-click the form to open the Code Editor, and enter the following code.

End Sub

## Private Sub Cmdclear_Click()

List1.Clear
End Sub

G.U.I LAB MANUAL
Page 31
Acharya Polytechnic, Department of Computer Science

End Sub

8. Press F5 to run the application or Click Run button from the tool bar.
9. See the result in GUI as shown in Figure.
10. On the File menu, choose Save Project As. In the Save File As dialog box, save the form
as with suitable name

GUI Output:

## G.U.I LAB MANUAL

Page 32
Acharya Polytechnic, Department of Computer Science

## Aim: Program to demonstrate pop-up menu

GUI Design:

Procedure

1. Start a new VB project and invoke the Menu Editor by select the Menu Editor option from the Tools

## 2. For "Caption", type &File For "Name", type mnuFile.

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 (below "File").

4. For "Caption", type &New; for "Name", type mnuNew, and for "Shortcut", select Ctrl+N. By
specifying a shortcut

5. For "Caption", type &Open; for "Name", type mnuOpen, and for "Shortcut", select Ctrl+O.

## 6. For "Caption", type - (a hyphen), and for "Name", type mnuFileBar1.

7. For "Caption", type Save &As ..., and for "Name", type mnuSaveAs.

## G.U.I LAB MANUAL

Page 33
Acharya Polytechnic, Department of Computer Science

8. For "Caption", type &Print;for "Name", type mnuPrint; and for "Shortcut", select Ctrl+P.

## 9. For "Caption", type -; and for "Name", type mnuFileBar3.

10. For "Caption", type E&xit, and for "Name", type mnuExit.

11. Click the "left-arrow" button (The ellipsis (...) no longer appears, meaning we are back to the top-
level items.

12. For "Caption", type &Help; and for "Name", type mnuHelp.

13. Click the "right-arrow" button to create a level-two item below "Help". For "Caption", type &About;

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

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

16. Double-click the form to open the Code Editor, and enter the following code.

Option Explicit
-------------------------------------------------------------------------------------------------
Private Sub mnuFileNew_Click()

## MsgBox "Code for 'New' goes here."

End Sub
--------------------------------------------------------------------------------------------------
Private Sub mnuFileOpen_Click()

## MsgBox "Code for 'Open' goes here."

End Sub
--------------------------------------------------------------------------------------------------
Private Sub mnuFileSave_Click()

End Sub

## G.U.I LAB MANUAL

Page 34
Acharya Polytechnic, Department of Computer Science

--------------------------------------------------------------------------------------------------

## MsgBox "Code for 'Save As' goes here."

End Sub
-------------------------------------------------------------------------------------------------
Private Sub mnuFilePrint_Click()

## MsgBox "Code for 'Print' goes here."

End Sub
--------------------------------------------------------------------------------------------------
Private Sub mnuFileExit_Click()

End Sub
--------------------------------------------------------------------------------------------------

End Sub
--------------------------------------------------------------------------------------------------

## G.U.I LAB MANUAL

Page 35
Acharya Polytechnic, Department of Computer Science

## Aim: Program to demonstrate Pull down menu

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

2. Open the Menu Editor, and create a top-level item with a Caption value of PopUpFormat and the
Name mnuPopuUpFormat. Also importantly uncheck the Visible checkbox (see the circled item in
figure). In order for a menu to be a pop-up menu, it must be invisible.

## G.U.I LAB MANUAL

Page 36
Acharya Polytechnic, Department of Computer Science

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

4.

Caption Name
Bold mnuBold
Italic mnuItalic
Underline mnuUnderline
- (hyphen) mnuFormatSep
Cancel mnuCancel

form (remember it's a pop-up menu, and it will only be visible when invoked through code).

6. Code the lblTestText_MouseDown event as shown below. Note that the Button parameter is tested
for 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. It is this
statement that makes the pop-up menu app

Option Explicit
----------------------------------------------------------------------------------------------------------------
Private Sub lblTestText_MouseDown(Button As Integer, _
Shift As Integer, _
X As Single, _
Y As Single)

## If Button = vbRightButton Then

End If

End Sub
--------------------------------------------------------------------------------------------------------------
Private Sub mnuBold_Click()

If mnuBold.Checked Then
lblTestText.FontBold = False
mnuBold.Checked = False
Else
lblTestText.FontBold = True
mnuBold.Checked = True
End If

## G.U.I LAB MANUAL

Page 37
Acharya Polytechnic, Department of Computer Science

End Sub
---------------------------------------------------------------------------------------------------------------
Private Sub mnuItalic_Click()

If mnuItalic.Checked Then
lblTestText.FontItalic = False
mnuItalic.Checked = False
Else
lblTestText.FontItalic = True
mnuItalic.Checked = True
End If

End Sub
---------------------------------------------------------------------------------------------------------------
Private Sub mnuUnderline_Click()

If mnuUnderline.Checked Then
lblTestText.FontUnderline = False
mnuUnderline.Checked = False
Else
lblTestText.FontUnderline = True
mnuUnderline.Checked = True
End If

End Sub
----------------------------------------------------------------------------------------------------------------

GUI Output:

## G.U.I LAB MANUAL

Page 38
Acharya Polytechnic, Department of Computer Science

## Aim: Program to demonstrate linear search

GUI Design:

Procedure:

1. Open Visual Basic 6.0. On the File menu, choose New Project.
2. In the New Project dialog box, choose Standard EXE, and click OK.
3. Select the Label and set the Caption to Enter numbers of Elements.
4. Select the Textbox and set the Name Property to Text1.
5. Select the Commandbutton and set the Name Property to CmdEnter and set the
Caption Property to Accept Numbers.
6. Select the Commandbutton and set the Name Property to Cmdsearch and set the
Caption Property to Search.
7. Select the Commandbutton and set the Name Property to Cmdexit and set the
Caption Property to Exit.
8. Double-click the form to open the Code Editor, and enter the following code.

## Dim A(10) As Integer

Dim N As Integer
-----------------------------------------------------------------------------------------------
Private Sub cmdenter_Click()
N = Val(Text1.Text)
For I = 0 To N - 1
B = InputBox(" Enter the Numbers:")
A(I) = B
Next I
End Sub
------------------------------------------------------------------------------------------------
Private Sub Cmdsearch_Click()
G.U.I LAB MANUAL
Page 39
Acharya Polytechnic, Department of Computer Science

## Dim FLAG As Integer

FLAG = 0
Key = InputBox("Enter the number to search in a List:")
For I = 0 To N - 1
If A(I) = Key Then
B = MsgBox("Search Sucessful ……..and elements is found at position" & I + 1)
FLAG = 1
End If
Next I
If FLAG = 0 Then
B = MsgBox("Search Sucessful ……..")
End If
End Sub
-------------------------------------------------------------------------------------------------------
Private Sub Command3_Click()
End
End Sub
----------------------------------------------------------------------------------------------------

9. Press F5 to run the application or Click Run button from the tool bar.
10. See the result in GUI as shown in Figure.
11. On the File menu, choose Save Project As. In the Save File As dialog box, save the form
as with suitable name

## G.U.I LAB MANUAL

Page 40
Acharya Polytechnic, Department of Computer Science

## Program No.19 Date of Experiment……………….

Aim: Design an application which performs the following operations on the database
the

Procedure:

## 1. Start – Program – Ms office – click Ms Access.

2. create a table as shown in figure
3. Save the table as table1. and save the database as db1.mdb

## Creating an ADO Data Control

dialog box, as in Figure 8.13. The ADO Data Control icon should now appear in the VB
toolbox.

## 2. Place an instance of the ADO Data Control on the form

3. Change the control's Name and Caption from their default values. Set the
ConnectionString property using steps 5–9.
4. Click the ellipsis next to the ConnectionString property in the ADO Data Control's
Properties window to bring up the Property Page dialog box for this property
ConnectionString property.
5. As Source of Connection, choose one of the following three options:

## G.U.I LAB MANUAL

Page 41
Acharya Polytechnic, Department of Computer Science

• Use Data Link File. If you choose this option, you will be able to click the Browse On
the Provider tab of the Data Link Properties tabbed dialog box, choose an OLE DB data
provider, such as Microsoft Jet 4.0 OLE DB

## 6. Click OK to accept the ConnectionString options you have built.

7. Still in the ADO Data Control's Properties window, navigate to the RecordSource
property and click the ellipsis button.
8. On the RecordSource tab (see Figure 8.18) of the resulting Property Page dialog box,

• If you chose adCmdTable fill in the appropriate table or stored procedure name in the
Table or Stored Procedure Name drop-down list.

## 9. Click OK to end the RecordSource dialog box.

10. 10 Place the textbox in form set the name property to text1, set the datasource to adodc1
and set the datafield to slno.
11. Place the textbox in form set the name property to text2, set the datasource to adodc1 and
set the datafield to name
12. Place the textbox in form set the name property to text3, set the datasource to adodc1 and
set the datafield to phoneno.
13. Place the command button, set the name property to cmdadd, and set the Caption
14. Place the command button, set the name property to cmdupdate, and set the Caption
property to UPDATE.
15. Place the command button, set the name property to cmdelete, and set the Caption
property to Delete.

End Sub
--------------------------------------------------------------------------
Private Sub Command1_Click()
End Sub
-------------------------------------------------------------------------
Private Sub Command2_Click()
End Sub

16. Press F5 to run the application or Click Run button from the tool bar.
17. See the result in GUI as shown in Figure.

## G.U.I LAB MANUAL

Page 42
Acharya Polytechnic, Department of Computer Science

18. On the File menu, choose Save Project As. In the Save File As dialog box, save the form
as with suitable name

Page 43