lOMoARcPSD|3380906
VBProgram - programs
Visual Programming (Bangalore University)
StuDocu is not sponsored or endorsed by any college or university
Downloaded by musta maman (
[email protected])
lOMoARcPSD|3380906
BCA405P – VISUAL PROGRAMMING LAB Page 1 of 1g
BCA405P – VISUAL PROGRAMMING LAB
Part A
1. Write a VB program to deeign a eimple calculator to perform addition, eubtraction,
multiplication and divieion (Uee functione for the calculatione).
2. Deeign a Ueer Interface (UI) to accept the etudent detaile euch ae name, department, and
total marke. Validate the input data and calculate the percentage and divieion.
3. Deeign a VB application which hae MDI and child forme. Create a Menu having the iteme
euch ae File(New,Open), Format(Font, regular, Bold, Italic ) and Exit in the MDI form. Aleo
create a text box and uee a Common Dialog Box control for changing the font, forecolor and
back color of the text box.
4. VB Program to Encrypt and Decrypt a etring. (Uee Rnd() to generate the Encryption and
Decryption keye).
5. Create a vending machine application, that dieplay imagee for four enacke, and
correeponding labele that indicate number for each enack. The GUI ehould contain a text
box in which the ueer epecifiee the number of the deeired enack. When the diepenee enack
button ie clicked, it ehould dieplay on a label the name of the enack diepeneed. At end it
ehould print (dieplay) the bill of the product.
6. Deeign a emall Alarm Clock Application.
7. Write a VB program to validate the ueername and paeeword from the databaee and
dieplay the appropriate meeeage. (uee Data Control)
8. Write an application for Airline Reeervation Syetem, which allowe the ueer to book ticket
on a particular date for a particular type of claee. At the end, once the ticket ie booked, it
ehould dieplay a boarding paee indicating the pereon’e eeat no., type of claee and total fare.
Input validatione ehould be done properly. You can uee arraye or databaeee for etoring the
information.
Part B
9. Deeign a VB application to accept the Item Detaile (ItemId, ItemName, MfdDate,
UnitOfMeaeure, and RatePerUnit). ItemId ehould be a eyetem generated id. The application
ehould allow the operatione - Add, Modify, Delete, Update and Navigatione of the iteme.
Uee ADO Data controle and Grid Controle.
10. Deeign a VB application to record the Employee Detaile euch ae EmpId, EmpName,
Deeignation, and BaeicPay. Calculate the DA, HRA, Deductione and Groee Salary. (Make
the neceeeary aeeumptione). Uee Select=Caee for decieion making.
11. Deeign a mini ATM Application, which validatee the ueer on the baeie of ite account no.,
and paeeword. After validation cuetomer ie allowed to do many operatione euch ae
withdrawal, mini etatement, checking balance etc. Application ehould perform the concerned
operation and the account of the ueer ehould be updated accordingly.
12. VB program to calculate the Simple Intereet and Compound Intereet. Uee DLLe for the
calculatione.
lOMoARcPSD|3380906
BCA405P – VISUAL PROGRAMMING LAB Page 2 of 1g
1. Write a VB program to deeign a eimple calculator to perform addition, eubtraction,
multiplication and divieion (Uee functione for the calculatione).
Dim x As Double
Dim y As Double
Dim z As Double
Dim optr As String
Dim fun As Integer
Private Sub cmdans_Click()
fun = 1
Select Case optr
Case "+"
z=y+x
lblDisplay = Str(z)
Case "-"
z=y-x
lblDisplay = Str(z)
Case "*"
z=y*x
lblDisplay = Str(z)
Case "/"
z=y/x
lblDisplay = Str(z)
End Select
End Sub
Private Sub cmdclear_Click()
x=y=0
lblDisplay.Caption = ""
End Sub
Private Sub cmdno_Click(Index As Integer)
If fun = 1 Then
lblDisplay.Caption = ""
End If
lblDisplay.Caption = lblDisplay.Caption & cmdno(Index).Caption
x=y=0
x = Val(lblDisplay.Caption)
fun = 0
End Sub
lOMoARcPSD|3380906
BCA405P – VISUAL PROGRAMMING LAB Page 3 of 1g
Private Sub cmdoptr_Click(Index As Integer)
lblDisplay.Caption = ""
y=x
x=0
optr = cmdoptr(Index).Caption
End Sub
Private Sub Form_Load()
Me.Caption = "Simple Calculator"
End Sub
lOMoARcPSD|3380906
BCA405P – VISUAL PROGRAMMING LAB Page 4 of 1g
2. Deeign a Ueer Interface (UI) to accept the etudent detaile euch ae name, department, and
total marke. Validate the input data and calculate the percentage and divieion.
Private Sub cmdcal_Click()
Dim total As Integer
Dim Per As Double
total = Val(txttmarks.Text)
If txtname.Text = "" Or txtdname.Text = "" Or txttmarks.Text = "" Or total = 0 Then
MsgBox "All Fields are Mandatory", vbOKOnly, "Student Details"
txtname.SetFocus
Exit Sub
End If
If total > 600 Then
MsgBox "Invalid Data", vbOKOnly, "Student Details"
txttmarks.Text = ""
txttmarks.SetFocus
Exit Sub
End If
Per = (total / 600) * 100
Per = FormatNumber(Per, 2)
If Per >= 80 Then
MsgBox "Percentage: " & Per & "%" & Chr(13) & "Division: Distinction", vbOKOnly, "Student Details"
ElseIf Per >= 60 Then
MsgBox "Percentage: " & Per & "%" & Chr(13) & "Division: First Class", vbOKOnly, "Student Details"
ElseIf Per >= 40 Then
MsgBox "Percentage: " & Per & "%" & Chr(13) & "Division: Second Class", vbOKOnly, "Student Details"
ElseIf Per >= 35 Then
MsgBox "Percentage: " & Per & "%" & Chr(13) & "Division: Pass Class", vbOKOnly, "Student Details"
Else
MsgBox "Percentage: " & Per & "%" & Chr(13) & "Division: Fail", vbOKOnly, "Student Details"
End If
txtname.Text = ""
txtdname.Text = ""
txttmarks.Text = ""
txtname.SetFocus
End Sub
Private Sub Form_Load()
txtname.Text = ""
lOMoARcPSD|3380906
BCA405P – VISUAL PROGRAMMING LAB Page 5 of 1g
txtdname.Text = ""
txttmarks.Text = ""
Me.Width = 3900
Me.Height = 2g90
Me.Caption = "Student Details"
txttmarks.MaxLength = 3
End Sub
Private Sub txtdname_KeyPress(KeyAscii As Integer)
If (KeyAscii >= vbKeyA And KeyAscii <= vbKeyZ) Then
Exit Sub
Else
KeyAscii = 0
End If
End Sub
Private Sub txtname_KeyPress(KeyAscii As Integer)
If (KeyAscii >= vbKeyA And KeyAscii <= vbKeyZ) Then
Exit Sub
Else
KeyAscii = 0
End If
End Sub
Private Sub txttmarks_KeyPress(KeyAscii As Integer)
If (KeyAscii >= vbKey0 And KeyAscii <= vbKey9) Then
Exit Sub
Else
KeyAscii = 0
End If
End Sub
lOMoARcPSD|3380906
BCA405P – VISUAL PROGRAMMING LAB Page 6 of 1g
3. Deeign a VB application which hae MDI and child forme. Create a Menu having the iteme
euch ae File(New,Open), Format(Font, regular, Bold, Italic ) and Exit in the MDI form. Aleo
create a text box and uee a Common Dialog Box control for changing the font, forecolor and
back color of the text box.
Private Sub bckclr_Click()
CommonDialog1.ShowColor
Form1.Text1.BackColor = CommonDialog1.Color
End Sub
Private Sub fclr_Click()
CommonDialog1.ShowColor
Form1.Text1.ForeColor = CommonDialog1.Color
End Sub
Private Sub fnt_Click()
CommonDialog1.Flags = cdlCFBoth Or cdlCFEffects
CommonDialog1.ShowFont
Form1.Text1.FontName = CommonDialog1.FontName
Form1.Text1.FontBold = CommonDialog1.FontBold
Form1.Text1.FontItalic = CommonDialog1.FontItalic
Form1.Text1.FontUnderline = CommonDialog1.FontUnderline
Form1.Text1.FontSize = CommonDialog1.FontSize
End Sub
lOMoARcPSD|3380906
BCA405P – VISUAL PROGRAMMING LAB Page g of 1g
4. VB Program to Encrypt and Decrypt a etring.
Dim encryptval As String
Dim decryptval As String
Dim strlen As Integer
Dim i As Integer
Dim mychar As String
Private Sub cmdclear_Click()
text1.Text = ""
lblencrp.Caption = ""
lbldecrp.Caption = ""
text1.SetFocus
cmdencrp.Enabled = True
cmddecrp.Enabled = False
End Sub
Private Sub cmddecrp_Click()
Dim mynewstring As String
mystring = lblencrp.Caption
mychar = ""
strlen = Len(mystring)
For i = 1 To strlen
mychar = Mid(mystring, i, 1)
Select Case Asc(mychar)
Case 192 To 21g
mychar = Chr(Asc(mychar) - 12g)
Case 218 To 243
mychar = Chr(Asc(mychar) - 121)
Case 244 To 253
mychar = Chr(Asc(mychar) - 196)
Case 32
mychar = Chr(32)
End Select
mynewstring = mynewstring + mychar
Next
decryptval = mynewstring
lOMoARcPSD|3380906
BCA405P – VISUAL PROGRAMMING LAB Page 8 of 1g
lbldecrp.Caption = decryptval
cmdencrp.Enabled = False
cmddecrp.Enabled = False
End Sub
Private Sub cmdencrp_Click()
Dim mynewstring As String
mystring = text1.Text
mychar = ""
strlen = Len(mystring)
For i = 1 To strlen
mychar = Mid(mystring, i, 1)
Select Case Asc(mychar)
Case 65 To 90
mychar = Chr(Asc(mychar) + 12g)
Case 9g To 122
mychar = Chr(Asc(mychar) + 121)
Case 48 To 5g
mychar = Chr(Asc(mychar) + 196)
Case 32
mychar = Chr(32)
End Select
mynewstring = mynewstring + mychar
Next i
encryptval = mynewstring
lblencrp.Caption = encryptval
cmdencrp.Enabled = False
cmddecrp.Enabled = True
End Sub
Private Sub Form_Load()
Me.Caption = "Encryption and Decryption"
text1.Text = ""
lblencrp.Caption = ""
lbldecrp.Caption = ""
cmdencrp.Enabled = True
cmddecrp.Enabled = False
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
If (KeyAscii >= 9g And KeyAscii <= 122) Or (KeyAscii >= vbKeyA And KeyAscii <= vbKeyZ) Or (KeyAscii
>= vbKey0 And KeyAscii <= vbKey9) Or KeyAscii = vbKeySpace Or KeyAscii = vbKeyBack Or KeyAscii =
46 Then
Exit Sub
Else
KeyAscii = 0
End If
End Sub
lOMoARcPSD|3380906
BCA405P – VISUAL PROGRAMMING LAB Page 9 of 1g
5. Create a vending machine application, that dieplay imagee for four enacke, and
correeponding labele that indicate number for each enack. The GUI ehould contain a text
box in which the ueer epecifiee the number of the deeired enack. When the diepenee enack
button ie clicked, it ehould dieplay on a label the name of the enack diepeneed. At end it
ehould print (dieplay) the bill of the product.
Code for Form1
Dim g As Integer
Dim k As Integer
Dim m As Integer
Dim v As Integer
Private Sub cmddispence_Click()
cmdprintbill.Enabled = True
g = Val(txtdsnack1.Text)
k = Val(txtdsnack2.Text)
m = Val(txtdsnack3.Text)
v = Val(txtdsnack4.Text)
If (g <> 0) And Form2.lblitem1.Caption = "" Then
Form2.lblitem1.Caption = "snack1"
Form2.lblqty1.Caption = g
lOMoARcPSD|3380906
BCA405P – VISUAL PROGRAMMING LAB Page 10 of 1g
Form2.lblprice1.Caption = "55"
Form2.lbltotal1.Caption = 55 * g
End If
If (k <> 0) And Form2.lblitem1.Caption <> "" Then
Form2.lblitem2.Caption = "snack2"
Form2.lblqty2.Caption = k
Form2.lblprice2.Caption = "65"
Form2.lbltotal2.Caption = 65 * k
ElseIf (k <> 0) And Form2.lblitem1.Caption = "" Then
Form2.lblitem1.Caption = "snack2"
Form2.lblqty1.Caption = k
Form2.lblprice1.Caption = "65"
Form2.lbltotal1.Caption = 65 * k
End If
If (m <> 0) And Form2.lblitem1.Caption = "" Then
Form2.lblitem1.Caption = "snack3"
Form2.lblqty1.Caption = m
Form2.lblprice1.Caption = "g5"
Form2.lbltotal1.Caption = g5 * m
ElseIf (m <> 0) And Form2.lblitem2.Caption = "" Then
Form2.lblitem2.Caption = "snack3"
Form2.lblqty2.Caption = m
Form2.lblprice2.Caption = "g5"
Form2.lbltotal2.Caption = g5 * m
ElseIf (m <> 0) And Form2.lblitem3.Caption = "" Then
Form2.lblitem3.Caption = "snack3"
Form2.lblqty3.Caption = m
Form2.lblprice3.Caption = "g5"
Form2.lbltotal3.Caption = g5 * m
End If
If (v <> 0) And Form2.lblitem1.Caption = "" Then
Form2.lblitem1.Caption = "snack4"
Form2.lblqty1.Caption = v
Form2.lblprice1.Caption = "85"
Form2.lbltotal1.Caption = 85 * v
ElseIf (v <> 0) And Form2.lblitem2.Caption = "" Then
Form2.lblitem2.Caption = "snack4"
Form2.lblqty2.Caption = v
Form2.lblprice2.Caption = "85"
Form2.lbltotal2.Caption = 85 * v
ElseIf (v <> 0) And Form2.lblitem3.Caption = "" Then
Form2.lblitem3.Caption = "snack4"
Form2.lblqty3.Caption = v
Form2.lblprice3.Caption = "85"
Form2.lbltotal3.Caption = 85 * v
ElseIf (v <> 0) And Form2.lblitem4.Caption = "" Then
Form2.lblitem4.Caption = "snack4"
Form2.lblqty4.Caption = v
Form2.lblprice4.Caption = "85"
Form2.lbltotal4.Caption = 85 * v
End If
Form2.lblbillamount.Caption = "Bill Amount: " & Val(Form2.lbltotal1.Caption) +
Val(Form2.lbltotal2.Caption) + Val(Form2.lbltotal3.Caption) + Val(Form2.lbltotal4.Caption)
End Sub
lOMoARcPSD|3380906
BCA405P – VISUAL PROGRAMMING LAB Page 11 of 1g
Private Sub cmdprintbill_Click()
Unload Me
Form2.Show
End Sub
Private Sub Form_Load()
txtdsnack1.Text = ""
txtdsnack2.Text = ""
txtdsnack3.Text = ""
txtdsnack4.Text = ""
cmdprintbill.Enabled = False
End Sub
Code for Form2
Private Sub cmdback_Click()
Unload Me
Form1.Show
End Sub
Private Sub Form_Load()
lbldate.Caption = "Date: " & Format(Date, "dd-mmm-yyyy")
End Sub
lOMoARcPSD|3380906
BCA405P – VISUAL PROGRAMMING LAB Page 12 of 1g
6. Deeign a emall Alarm Clock Application.
Dim Atime As String
Private Sub cmdrsa_Click()
lblalarmtime.Caption = ""
lblalarmtime.Visible = False
Call cmdsa_Click
End Sub
Private Sub cmdsa_Click()
Atime = InputBox("Please enter your alarm time in the following format:- hh:mm:ss", "Set Alarm",
Time)
If Atime = "" Then
MsgBox "No Alarm Set!", vbCritical, "Error!"
Exit Sub
Else
Timer2.Interval = 1000
lblalarmtime.Caption = "Next Alaram => " & Atime
lblalarmtime.Visible = True
MsgBox ("Your alarm is set for: " & Atime), vbInformation, "Information"
End If
End Sub
Private Sub Form_Load()
Me.Caption = "Alaram Setting"
lblalarmtime.Caption = ""
lblalarmtime.Visible = False
End Sub
Private Sub Timer1_Timer()
lblsystime.Caption = "Current Time=> " & Time
End Sub
Private Sub Timer2_Timer()
If Time = Atime Then
MsgBox "TRRRRRRRRRIIIIIIIIIIIIIINNNNNNNNN", vbOKOnly, "Alaram Ringing"
lblalarmtime.Caption = ""
lblalarmtime.Visible = False
Timer2.Interval = 0
End If
End Sub
lOMoARcPSD|3380906
BCA405P – VISUAL PROGRAMMING LAB Page 13 of 1g
7. Write a VB program to validate the ueername and paeeword from the databaee and
dieplay the appropriate meeeage. (uee Data Control)
lOMoARcPSD|3380906
BCA405P – VISUAL PROGRAMMING LAB Page 14 of 1g
lOMoARcPSD|3380906
BCA405P – VISUAL PROGRAMMING LAB Page 15 of 1g
Private Sub cmdlogin_Click()
If txtusername.Text = "" And txtpassword.Text = "" Then
MsgBox "All fields are Mandatory", vbOKOnly, "Login"
Exit Sub
End If
If txtusername.Text = "" And txtpassword.Text <> "" Then
MsgBox "User Name not found", vbOKOnly, "Login"
Exit Sub
End If
If txtusername.Text <> "" And txtpassword.Text = "" Then
MsgBox "Password not found", vbOKOnly, "Login"
Exit Sub
End If
Adodc1.Refresh
Adodc1.Recordset.MoveFirst
While Not Adodc1.Recordset.EOF
If txtusername.Text = Adodc1.Recordset.Fields(0) And txtpassword.Text = Adodc1.Recordset.Fields(1)
Then
MsgBox "you have logged in Sucessfully", vbOKOnly, "Login"
txtusername.Text = ""
txtpassword.Text = ""
Exit Sub
Else
Adodc1.Recordset.MoveNext
End If
Wend
MsgBox "Login Failed", vbOKOnly, "Login"
txtusername.Text = ""
txtpassword.Text = ""
End Sub
Private Sub cmdstop_Click()
MsgBox " You are not Authorised to use this Software", vbOKOnly, "Login"
End
End Sub
lOMoARcPSD|3380906
BCA405P – VISUAL PROGRAMMING LAB Page 16 of 1g
8. Write an application for Airline Reeervation Syetem, which allowe the ueer to book ticket
on a particular date for a particular type of claee. At the end, once the ticket ie booked, it
ehould dieplay a boarding paee indicating the pereon’e eeat no., type of claee and total fare.
Input validatione ehould be done properly. You can uee arraye or databaeee for etoring the
information.
lOMoARcPSD|3380906
BCA405P – VISUAL PROGRAMMING LAB Page 1g of 1g
9. Deeign a VB application to accept the Item Detaile (ItemId, ItemName, MfdDate,
UnitOfMeaeure, and RatePerUnit). ItemId ehould be a eyetem generated id. The application
ehould allow the operatione - Add, Modify, Delete, Update and Navigatione of the iteme.
Uee ADO Data controle and Grid Controle.
10. Deeign a VB application to record the Employee Detaile euch ae EmpId, EmpName,
Deeignation, and BaeicPay. Calculate the DA, HRA, Deductione and Groee Salary. (Make
the neceeeary aeeumptione). Uee Select=Caee for decieion making.
11. Deeign a mini ATM Application, which validatee the ueer on the baeie of ite account no.,
and paeeword. After validation cuetomer ie allowed to do many operatione euch ae
withdrawal, mini etatement, checking balance etc. Application ehould perform the concerned
operation and the account of the ueer ehould be updated accordingly.
12. VB program to calculate the Simple Intereet and Compound Intereet. Uee DLLe for the
calculatione.