GKSir VBProgram List

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 17

BCA405P – VISUAL PROGRAMMING LAB Page 1 of 17

BCA405P – VISUAL PROGRAMMING LAB

Part A
1. Write a VB program to design a simple calculator to perform addition, subtraction,
multiplication and division (Use functions for the calculations).
2. Design a User Interface (UI) to accept the student details such as name, department, and
total marks. Validate the input data and calculate the percentage and division.
3. Design a VB application which has MDI and child forms. Create a Menu having the items
such as File(New,Open), Format(Font, regular, Bold, Italic ) and Exit in the MDI form. Also
create a text box and use 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 string. (Use Rnd() to generate the Encryption and
Decryption keys).
5. Create a vending machine application, that display images for four snacks, and
corresponding labels that indicate number for each snack. The GUI should contain a text
box in which the user specifies the number of the desired snack. When the dispense snack
button is clicked, it should display on a label the name of the snack dispensed. At end it
should print (display) the bill of the product.
6. Design a small Alarm Clock Application.
7. Write a VB program to validate the username and password from the database and
display the appropriate message. (use Data Control)
8. Write an application for Airline Reservation System, which allows the user to book ticket
on a particular date for a particular type of class. At the end, once the ticket is booked, it
should display a boarding pass indicating the person’s seat no., type of class and total fare.
Input validations should be done properly. You can use arrays or databases for storing the
information.

Part B
9. Design a VB application to accept the Item Details (ItemId, ItemName, MfdDate,
UnitOfMeasure, and RatePerUnit). ItemId should be a system generated id. The application
should allow the operations - Add, Modify, Delete, Update and Navigations of the items.
Use ADO Data controls and Grid Controls.
10. Design a VB application to record the Employee Details such as EmpId, EmpName,
Designation, and BasicPay. Calculate the DA, HRA, Deductions and Gross Salary. (Make
the necessary assumptions). Use Select=Case for decision making.
11. Design a mini ATM Application, which validates the user on the basis of its account no.,
and password. After validation customer is allowed to do many operations such as
withdrawal, mini statement, checking balance etc. Application should perform the concerned
operation and the account of the user should be updated accordingly.
12. VB program to calculate the Simple Interest and Compound Interest. Use DLLs for the
calculations.

www.gkmvkalyan.blogspot.com
BCA405P – VISUAL PROGRAMMING LAB Page 2 of 17

1. Write a VB program to design a simple calculator to perform addition, subtraction,


multiplication and division (Use functions for the calculations).

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

www.gkmvkalyan.blogspot.com
BCA405P – VISUAL PROGRAMMING LAB Page 3 of 17

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

www.gkmvkalyan.blogspot.com
BCA405P – VISUAL PROGRAMMING LAB Page 4 of 17

2. Design a User Interface (UI) to accept the student details such as name, department, and
total marks. Validate the input data and calculate the percentage and division.

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 = ""

www.gkmvkalyan.blogspot.com
BCA405P – VISUAL PROGRAMMING LAB Page 5 of 17

txtdname.Text = ""
txttmarks.Text = ""
Me.Width = 3900
Me.Height = 2790
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

www.gkmvkalyan.blogspot.com
BCA405P – VISUAL PROGRAMMING LAB Page 6 of 17

3. Design a VB application which has MDI and child forms. Create a Menu having the items
such as File(New,Open), Format(Font, regular, Bold, Italic ) and Exit in the MDI form. Also
create a text box and use 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

www.gkmvkalyan.blogspot.com
BCA405P – VISUAL PROGRAMMING LAB Page 7 of 17

4. VB Program to Encrypt and Decrypt a string.

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 217
mychar = Chr(Asc(mychar) - 127)
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

www.gkmvkalyan.blogspot.com
BCA405P – VISUAL PROGRAMMING LAB Page 8 of 17

decryptval = mynewstring
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) + 127)
Case 97 To 122
mychar = Chr(Asc(mychar) + 121)
Case 48 To 57
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 >= 97 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

www.gkmvkalyan.blogspot.com
BCA405P – VISUAL PROGRAMMING LAB Page 9 of 17

5. Create a vending machine application, that display images for four snacks, and
corresponding labels that indicate number for each snack. The GUI should contain a text
box in which the user specifies the number of the desired snack. When the dispense snack
button is clicked, it should display on a label the name of the snack dispensed. At end it
should print (display) 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"

www.gkmvkalyan.blogspot.com
BCA405P – VISUAL PROGRAMMING LAB Page 10 of 17

Form2.lblqty1.Caption = g
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 = "75"
Form2.lbltotal1.Caption = 75 * m
ElseIf (m <> 0) And Form2.lblitem2.Caption = "" Then
Form2.lblitem2.Caption = "snack3"
Form2.lblqty2.Caption = m
Form2.lblprice2.Caption = "75"
Form2.lbltotal2.Caption = 75 * m
ElseIf (m <> 0) And Form2.lblitem3.Caption = "" Then
Form2.lblitem3.Caption = "snack3"
Form2.lblqty3.Caption = m
Form2.lblprice3.Caption = "75"
Form2.lbltotal3.Caption = 75 * 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)

www.gkmvkalyan.blogspot.com
BCA405P – VISUAL PROGRAMMING LAB Page 11 of 17

End Sub
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

www.gkmvkalyan.blogspot.com
BCA405P – VISUAL PROGRAMMING LAB Page 12 of 17

6. Design a small 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

www.gkmvkalyan.blogspot.com
BCA405P – VISUAL PROGRAMMING LAB Page 13 of 17

7. Write a VB program to validate the username and password from the database and
display the appropriate message. (use Data Control)

www.gkmvkalyan.blogspot.com
BCA405P – VISUAL PROGRAMMING LAB Page 14 of 17

www.gkmvkalyan.blogspot.com
BCA405P – VISUAL PROGRAMMING LAB Page 15 of 17

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

www.gkmvkalyan.blogspot.com
BCA405P – VISUAL PROGRAMMING LAB Page 16 of 17

8. Write an application for Airline Reservation System, which allows the user to book ticket
on a particular date for a particular type of class. At the end, once the ticket is booked, it
should display a boarding pass indicating the person’s seat no., type of class and total fare.
Input validations should be done properly. You can use arrays or databases for storing the
information.

www.gkmvkalyan.blogspot.com
BCA405P – VISUAL PROGRAMMING LAB Page 17 of 17

9. Design a VB application to accept the Item Details (ItemId, ItemName, MfdDate,


UnitOfMeasure, and RatePerUnit). ItemId should be a system generated id. The application
should allow the operations - Add, Modify, Delete, Update and Navigations of the items.
Use ADO Data controls and Grid Controls.

10. Design a VB application to record the Employee Details such as EmpId, EmpName,
Designation, and BasicPay. Calculate the DA, HRA, Deductions and Gross Salary. (Make
the necessary assumptions). Use Select=Case for decision making.

11. Design a mini ATM Application, which validates the user on the basis of its account no.,
and password. After validation customer is allowed to do many operations such as
withdrawal, mini statement, checking balance etc. Application should perform the concerned
operation and the account of the user should be updated accordingly.

12. VB program to calculate the Simple Interest and Compound Interest. Use DLLs for the
calculations.

www.gkmvkalyan.blogspot.com

You might also like