Lab Programs GUI
Lab Programs GUI
Lab Programs GUI
Aim: Program to input two different integers using the function input box to
compare two numbers
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.
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.
Result in GUI
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
Caption property to Enter Grades.
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.
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.
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.
value1 = txtOne.Text
value2 = txtTwo.Text
value3 = txtThree.Text
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:
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
End Sub
End
End Sub
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:
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.
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.
11. In the Save File As dialog box, save the form as controlarray.frm and save the project
as crltarray.vbp.
GUI Output:
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
Call Listarray.Clear
CmdErase.Enabled = False
End Sub
------------------------------------------------------------------------------------------------------
Private Sub Cmdrun_Click()
Dim values As Integer
Dim range As Integer
Dim x As Integer
For x = 0 To range
myArray(x) = InputBox("Enter Element")
Listarray.AddItem myArray(x)
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:
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
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:
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:
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 answer As String
Dim result As Integer
result = Len(string2)
Print result
Print
answer = Left$(stringl, 6)
Print answer;
Print
answer = Right$(stringl, 6)
Print answer;
Print
answer = Mid$(stringl, 8, 8)
Print answer;
Print
result = InStr(stringl, string2)
Print result
Print
answer = UCase$(string2)
Print answer
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:
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
Caption property to Login
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
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:
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
Caption property to Enter Grades.
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
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:
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
----------------------------------------------------------------------------------------------------------------
Private Sub Form_Load()
Call lstOutput.AddItem("Now: " & Now)
Call lstOutput.AddItem("Now + 3 years: " & DateAdd("yyyy", 3, Now))
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:
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
Caption property to Enter Grades.
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
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)
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
GUI Output:
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
mintCount = 0
Cls
tmrTest.Enabled = True
End Sub
-------------------------------------------------------------------------------------------------
End Sub
---------------------------------------------------------------------------------------------------
mintCount = mintCount + 1
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:
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
property to ADD
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
Combo1.AddItem "Tuesday"
Combo1.AddItem "Wednesday"
Combo1.AddItem "Thursday"
Combo1.AddItem "Friday"
Combo1.AddItem "Saturday"
Combo1.AddItem "Sunday"
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:
Procedure
1. Start a new VB project and invoke the Menu Editor by select the Menu Editor option from the Tools
menu. The Menu Editor screen appears, as shown in figure:
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.
7. For "Caption", type Save &As ..., and for "Name", type mnuSaveAs.
8. For "Caption", type &Print;for "Name", type mnuPrint; and for "Shortcut", select Ctrl+P.
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;
and for "Name", type mnuAbout.
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()
End Sub
--------------------------------------------------------------------------------------------------
Private Sub mnuFileOpen_Click()
End Sub
--------------------------------------------------------------------------------------------------
Private Sub mnuFileSave_Click()
End Sub
--------------------------------------------------------------------------------------------------
End Sub
-------------------------------------------------------------------------------------------------
Private Sub mnuFilePrint_Click()
End Sub
--------------------------------------------------------------------------------------------------
Private Sub mnuFileExit_Click()
Unload Me
End Sub
--------------------------------------------------------------------------------------------------
Private Sub mnuHelpAbout_Click()
End Sub
--------------------------------------------------------------------------------------------------
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.
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
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).
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)
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
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:
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.
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
Aim: Design an application which performs the following operations on the database
the
form using ADO a) add b) update c) delete
Procedure:
1. Add the Microsoft ADO DataControl 6.0 (OLEDB) from the Project, Components menu
dialog box, as in Figure 8.13. The ADO Data Control icon should now appear in the VB
toolbox.
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:
• 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
• If you chose adCmdTable fill in the appropriate table or stored procedure name in the
Table or Stored Procedure Name drop-down list.
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.
18. On the File menu, choose Save Project As. In the Save File As dialog box, save the form
as with suitable name