1) Aim: To Develop A Visual Basic Application To Demonstrate Different Types of MSG Boxes. Description
1) Aim: To Develop A Visual Basic Application To Demonstrate Different Types of MSG Boxes. Description
1) Aim: To develop a Visual basic application to demonstrate different types of Msg Boxes. Description :
This form Operations with six commands which demonstrates different types of Msg Boxes. The Syntax of Msg Box is MsgVox prompt,Style,Title
Properties Name Caption Name Caption Name Caption Name Caption Name Caption Name Caption Name Caption Name Caption Form1
Event
MsgBox Demo Command1 VBOKOnly Command2 VBOKCancel Command3 VBAbortRetryIgnore Command4 VBYesNoCancel Command5 VBYesNo Command6 VBRetryCancel Label1 Demonstration Of MagBoxes
Code :
Private Sub Command1_Click() MsgBox "VbOkOnly", 0, "VbOkOnly" End Sub Private Sub Command2_Click() MsgBox "VbOkCancle", 1, "VbOkCancle" End Sub Private Sub Command3_Click()
Page 1
MCA IV Semester
MsgBox "VbAbortRetryIgnore", 2, "VbAbortRetryIgnore" End Sub Private Sub Command4_Click() MsgBox "VbYesNoCancle", 3, "VbTesNoCancle" End Sub
Private Sub Command5_Click() MsgBox "VbYesNo", 4, "VbYesNo" End Sub Private Sub Command6_Click() MsgBox "VbRetryCancle", 5, "VbRetryCancle" End Sub
Output:
Page 2
MCA IV Semester
Description:
This program is used to check the given user is valid or not. Control Form Label1 Label2 Label3 Command1 Command2 Frame Optoin1 Option2 Option3 TextBox1 Properties Name Caption Name Caption Name Caption Name Caption Name Caption Name Caption Name Caption Name Caption Name Caption Name Caption Name Values Form1 Form1 Label1 Login Form Label2 User Name
Label3
Event Load
Click Click
Page 3
MCA IV Semester
TextBox2 Caption Name Caption Empty
Text2
Empty
Code :
Private Sub Command1_Click() If Trim(UCase(Text1.Text)) = UCase(Trim("ANISH")) And Trim(UCase(Text2.Text)) = UCase(Trim("ANISH")) Then If Option1 = True Then MsgBox "Login With Read Permission Only" ElseIf Option2 = True Then MsgBox "Login With Write Permission Only" ElseIf Option3 = True Then MsgBox "Login With Read And Write Permissions" End If Else MsgBox "Unauthorized User" End If End Sub Private Sub Command2_Click () Unload Me End Sub
Output:
Page 4
MCA IV Semester
Page 5
MCA IV Semester
3) Aim: Develop a Visual Basic Application to find biggest of three numbers. Description:
This program is used to check the biggest of three numbers. Control Form Label1 Label2 Label3 Label4 Label5 Command1 TextBox1 TextBox2 TextBox3 TextBox4 Properties Name Caption Name Caption Name Caption Name Caption Name Caption Name Caption Name Caption Name Caption Name Caption Name Caption Name Caption Values Form1 Form1 Label1 Biggest Of 3 Numbers Label2 First Number
Label3
Event Load
Second Number Label4 Third Number Label5 Biggest Number Is Command1 Result Text1 Empty Text2 Empty Text3 Empty
Text4
Click
Empty
Code:
Private Sub Command1_Click() Dim a, b, c As Integer a = Val(Text1.Text) b = Val(Text2.Text) c = Val(Text3.Text) If a > b And a > c Then Text4.Text = a MsgBox "First Number Is Big" ElseIf b > c Then Text4.Text = b MsgBox "Second Number Is Big" Else Text4.Text = c MsgBox "Third Number Is Big" End If End Sub
Page 6
MCA IV Semester
Output:
Page 7
MCA IV Semester
4) Aim : To develop a Visual Basic Application to do basic arithmetic operations. Daescription : This program is used to perform the basic arithmetic operations.
Control Form Label1 Label2 Label3 Label4 Label5 Label6 Label7 TextBox1 TextBox2 TextBox3 TextBox4 TextBox5 TextBox6 Command1 Properties Name Caption Name Caption Name Caption Name Caption Name Caption Name Caption Name Caption Name Caption Name Caption Name Caption Name Caption Name Caption Name Caption Name Caption Name Caption Values Form1 Form1 Label1 Arithmetic Operations Label2 1st Number
Label3
Event Load
2nd Number Label4 Sum Label5 Sub Label6 Mul Label7 Div A Empty B Empty Text1 Empty Text2 Empty Text3 Empty Text4 Empty Command1 Result
Click
Code:
Private Sub Command1_Click() c = Val(a.Text) + Val(b.Text) Text1 = Val(a.Text) - Val(b.Text) Text2 = Val(a.Text) * Val(b.Text) Text3 = Val(a.Text) / Val(b.Text) End Sub
Page 8
MCA IV Semester
Output:
Page 9
MCA IV Semester
Description:
This program is used to check the student information pass or fail. Control Properties Values Form Name Form1 Load Caption Form1 Label1 Name Label1 Caption Student Information Label2 Name Label2 Caption Student Number Label3 Label3 Name Caption Student Name Label4 Name Label4 Caption Marks And Percentage Label5 Name Label5 Caption PPL Label6 Label6 Name Caption UML Label7 Name Label7 Caption WT Label8 Name Label8 Caption SE Label9 Name Label9 Caption C And N Name Text1 TextBox1 Text Empty Name Text2 TextBox2 Text Empty Name Text3 TextBox3 Text Empty Name Text4 TextBox4 Text Empty Name Text5 TextBox5 Text Empty Name Text6 TextBox6 Text Empty Name Text7 TextBox7 Text Empty Name Text8 TextBox8 Text Empty Name Text9 TextBox9 Text Empty Name Text10 TextBox10 Text Empty Event
Page 10
MCA IV Semester
Name Caption Name Caption Name Caption Name Caption Command1 Show Result TOTAL Total Percentages Average GRADES Grade
Code:
Private Sub Command1_Click() Total_Click Persentage_Click GREADS_Click End Sub Private Sub GREADS_Click () Dim t t = (Val (Text8.Text) / 500) * 100 If (Text3.Text < 40) or (Text4.Text < 40) or (Text5.Text < 40) or (Text6.Text < 40) Or (Text7.Text < 40) Then Text10.Text = "FAIL" Else If t < 40 Then Text10.Text = "FAIL" ElseIf (t > 40) And (t < 50) Then Text10.Text = "THIRD CLASS" ElseIf (t > 59) And (t < 40) Then Text10.Text = "SECOND CLASS" ElseIf (t >= 60) Then Text10.Text = "FIRST CLASS" End If End If End Sub Private Sub Total_Click() Text8.Text = Val(Text3.Text) + Val(Text4.Text) + Val(Text5.Text) + Val(Text6.Text) + Val(Text7.Text) End Sub Private Sub Persentage_Click() Text9.Text = (Val(Text8.Text) / 500) * 100 End Sub
Page 11
MCA IV Semester
Output:
Page 12
MCA IV Semester
6) Aim: Develop a Visual Basic Application to read details of the candidate based on following conditions.
i) ii) iii) iv) Read name, fathers name, address, qualification respective percentages & experience if any. Candidate may choose any two Operating Systems (Max). It may choose any three databases (Min). It may choose any five programming languages (Min). This program is used to fill an application form Control Form1 Label1 Label2 Label3 Label4 Label5 Label6 Label7 Frame1 Frame2 Frame2 CheckBox1 CheckBox2 CheckBox3 CheckBox4 CheckBox5 CheckBox6 CheckBox7 CheckBox8 Properties Name Caption Name Caption Name Caption Name Caption Name Caption Name Caption Name Caption Name Caption Name Caption Name Caption Name Caption Nmae1 Caption Nmae1 Caption Nmae1 Caption Nmae1 Caption Nmae1 Caption Nmae1 Caption Nmae1 Caption Nmae1 Caption Values Form1 Form1 Label1 Application Form Label2 Full Name
Label3
Description:
Event Load
Percentage Label7 Experience Frame1 Operating Systems Frame2 Databases Frame3 Programming Languages Check1 Windows XP Check1 Windows Vista Check1 Windows 7 Check1 Linux Check1 Ms Access Check1 Oracle 11g Check1 PL/SQL Check1 SQL
Page 13
MCA IV Semester
CheckBox9 Nmae1 Caption CheckBox10 Nmae1 Caption CheckBox11 Nmae1 Caption CheckBox12 Nmae1 Caption CheckBox13 Nmae1 Caption CheckBox14 Nmae1 Caption Command1 Name Caption Command2 Name Caption Name TextBox1 Text Name TextBox2 Text Name TextBox3 Text Name TextBox4 Text Name TextBox5 Text Name TextBox6 Text Check1 C Check1 C++ Check1 Java Check1 .Net Check1 VC++ Check1 VB 6.0 Command1 Submit Command2 Exit Text1 Empty Text2 Empty Text3 Empty Text4 Empty Text5 Empty Text6 Empty
Code:
Private Sub Command1_Click() Dim count, count1, count2 As Integer count1 = 0 count2 = 0 count = 0 If Text1.Text = " " Or Text2.Text = " " Or Text3.Text = " " Or Text4.Text = " " Or Text5.Text = "" Or Text6.Text = "" Then MsgBox "NO COLUMN IS EMPTY. FILL ALL THE COLUMNS" End If If Check1.Value = 1 Then count = count + 1 End If If Check2.Value = 1 Then count = count + 1 End If If Check3.Value = 1 Then count = count + 1 End If If Check4.Value = 1 Then count = count + 1 End If
Page 14
MCA IV Semester
If count < 2 Then MsgBox " u must Select Atleast 2 OS " End If If Check5.Value = 1 Then count1 = count1 + 1 End If If Check6.Value = 1 Then count1 = count1 + 1 End If If Check7.Value = 1 Then count1 = count1 + 1 End If If Check8.Value = 1 Then count1 = count + 1 End If If count1 < 3 Then MsgBox " u must Select At least 3 DB " End If If Check9.Value = 1 Then count2 = count2 + 1 End If If Check10.Value = 1 Then count2 = count2 + 1 End If If Check11.Value = 1 Then count2 = count2 + 1 End If If Check12.Value = 1 Then count2 = count2 + 1 End If If Check13.Value = 1 Then count2 = count2 + 1 End If If Check14.Value = 1 Then count2 = count2 + 1 End If If count2 < 5 Then MsgBox " u must Select Atleast 5 PL " End If If count >= 2 And count1 >= 3 And count2 >= 5 Then MsgBox "Submitted Successfully!!!!!!!!!!!!" End If End Sub Private Sub Command2_Click () Unload Me End Sub
Page 15
MCA IV Semester
Output:
Page 16
MCA IV Semester
7) Aim: To Develop a Visual Basic Application to perform arithmetic operations using multiple forms.
Form 1: Read A,B from User & Check Form 2: Perform integer arithmetic operations. Form 3: Perform real arithmetic operations. Form 4: Display the result. This program is used to perform the Integer and Real Arithmetic Operations.
Description: Form1:
Control Form1 Label1 Label2 Label3 Command1 Command2 Command3 Command4 TextBox1 TextBox2 Properties Name Caption Name Caption Name Caption Name Caption Name Caption Name Caption Name Caption Name Caption Name Text Name Text Values Form1 Form1 Label1 Arithmetic Operations Label2 Enter A Value Label3 Enter B value Command1 Integer Arithmetic Command2 Real Arithmetic Command3 Display Command4 Exit Text1 Empty Text2 Empty Event
Form2:
Control Command1 Command2 Command3 Command4 Command5 Properties Name Caption Name Caption Name Caption Name Caption Name Caption Values Command1 Add Command2 Sub Command3 Mul Command4 Div Command5 Back Event Click Click Click Click Click
Page 17
MCA IV Semester
Form3:
Control Command1 Command2 Command3 Command4 Command5 Properties Name Caption Name Caption Name Caption Name Caption Name Caption Values Command1 Add Command2 Sub Command3 Mul Command4 Div Command5 Back Event Click Click Click Click Click
Form4:
Control Command1 TextBox1 Command2 Properties Name Caption Name Text Name Caption Values Command1 Result Text1 Empty Command2 Back Event
Click
Code:
Form1:
Private Sub Command1_Click() Form2.Show End Sub Private Sub Command2_Click() Form3.Show End Sub Private Sub Command3_Click() Form4.Show End Sub Private Sub Command4_Click() End End Sub
Form2:
Private Sub Command1_Click() Form4.Text1 = Val(Form1.Text1) + Val(Form1.Text2) Form4.Show End Sub Private Sub Command2_Click() Form4.Text1 = Val(Form1.Text1) - Val(Form1.Text2) Form4.Show End Sub
Page 18
MCA IV Semester
Form3:
Private Sub Command1_Click() Form4.Text1 = Val(Form1.Text1) + Val(Form1.Text2) Form4.Show End Sub Private Sub Command2_Click() Form4.Text1 = Val(Form1.Text1) - Val(Form1.Text2) Form4.Show End Sub Private Sub Command3_Click() Form4.Text1 = Val(Form1.Text1) * Val(Form1.Text2) Form4.Show End Sub Private Sub Command4_Click() Form4.Text1 = Val(Form1.Text1) / Val(Form1.Text2) Form4.Show End Sub Private Sub Command5_Click() Form1.Show End Sub
Form4:
Private Sub Command2_Click() Form1.Show End Sub
Page 19
MCA IV Semester
Output:
Page 20
MCA IV Semester
Page 21
MCA IV Semester
8) Aim: To Develop a Visual Basic Application to sort given list of numbers. Description:
This program is used to sort the given numbers Control Form Label1 List Box Command1 Command2 Command3 Properties Name Caption Name Caption Name Name Caption Name Caption Name Caption Values Form1 Form1 Label1 Sorting Technique List1 Command1 Insert Command2 Sort The List Command3 Exit Event Load
Code:
Private Sub INSERT_Click() Dim I I = InputBox("ENTER ITEM INTO LIST") List1.AddItem I, 0 End Sub Private Sub Sort_Click() Dim I, J, TEMP, K K = List1.ListCount For I = 0 To K - 1 Step 1 For J = I + 1 To K - 1 Step 1 If Val(List1.List(I)) > Val(List1.List(J)) Then TEMP = List1.List(I) List1.List(I) = List1.List(J) List1.List(J) = TEMP End If Next Next End Sub Private Sub Command3_Click() End End Sub
Page 22
MCA IV Semester
Output:
Page 23
MCA IV Semester
9) Aim: Develop a Visual Basic Application to search an item from the list of items using binary search. Description:
This program is used to searching an element in the list of elements. Control Properties Values Form Name Form1 Caption Form1 Label1 Name Label1 Caption Searching Technique List Box Name List1 Command1 Command2 Command3 Name Caption Name Caption Name Caption Command1 Insert Command2 Search Command3 Exit Event Load
Code:
Private Sub INSERT _Click() Dim i i = Input Box("ENTER ITEM INTO LIST") List1.AddItem i, 0 End Sub Private Sub SEARCH_Click () Dim i, item, flag, top, bott, mid, count flag = 0 top = List1.ListCount - 1 bott = 0 item = Input Box("Enter item for Search") Do While (top >= bott) mid = CInt((bott + top) / 2) If (item = List1.List(mid)) Then flag = 1 Exit Do ElseIf (item > List1.List (mid)) Then top = mid - 1 Else bott = mid + 1 End If Loop If flag = 1 Then MsgBox "Element found" Else MsgBox "Element not found." End If End Sub Private Sub Command3_Click() End End Sub
Page 24
MCA IV Semester
Output:
Page 25
MCA IV Semester
10) Aim: To Develop a Visual Basic Application to demonstrate list box properties like adding, removing, & displaying the elements of list box. Description:
This program is used to perform adding, removing& displaying the elements in the list box. Control Form Command1 Command2 Command3 Command4 Properties Name Caption Name Caption Name Caption Name Caption Name Caption Values Form1 Form1 Command1 Add Command2 Remove Command3 Display Command4 Exit Event Load Click Click Click Click
Code:
Private Sub Command1_Click() Dim i If List1.ListCount < 5 Then i = InputBox("ENTER ITEM NAME", 5) List1.AddItem i, 0 Else MsgBox "List is Full" End If End Sub Private Sub Command2_Click() If List1.ListCount > 0 Then List1.RemoveItem (List1.ListCount - 1) Else MsgBox "List Is Empty" End If End Sub Private Sub Command3_Click() Dim i, j If List1.ListCount > 0 Then For i = 0 To List1.ListCount Step 1 j = j + " " + List1.List(i) Next MsgBox j, , "List Elements Are" Else MsgBox "List Is Empty" End If End Sub Private Sub Command4_Click() Unload Me End Sub
Page 26
MCA IV Semester
Output:
Page 27
MCA IV Semester
11) Aim: To Develop a Visual Basic Application to demonstrate stack operations. Description:
The program is used perform the stack operations. Control Form List Box Command1 Command2 Command3 Command4 Properties Name Caption Name Name Caption Name Caption Name Caption Name Caption Values Form1 Form1 List1 Command1 Push Command2 Pop Command3 Display Command4 Exit Event Load Click Click Click Click
Code :
Private Sub Command1_Click() Dim i If List1.ListCount <> 5 Then i = InputBox("ENTER ITEM", 5) List1.AddItem i, 0 Else MsgBox "Stack Is Full & Overflow" End If End Sub Private Sub Command2_Click() If List1.ListCount > 0 Then List1.RemoveItem 0 Else MsgBox "Stack Is Empty & Underflow" End If End Sub Private Sub Command3_Click() Dim i, j If List1.ListCount > 0 Then For i = 0 To List1.ListCount Step 1 j = j + " " + List1.List (i) Next MsgBox j, , "Stack Elements Are" Else MsgBox "Stack Is Empty", "Stack" End If End Sub Private Sub Command4_Click() UnloadMe End Sub
Page 28
MCA IV Semester
Output:
Page 29
MCA IV Semester
12) Aim: To Develop a Visual Basic Application to demonstrate queue operations. Description:
This program is used to perform the queue operations. Control Form Command1 Command2 Command3 Command4 Label List Box Properties Name Caption Name Caption Name Caption Name Caption Name Caption Name Caption Name Values Form1 Form1 Command1 Insert Command2 Delete Command3 Display Command4 Exit Label1 Queue Operations List1 Event Load Click Click Click Click
Code:
Private Sub Command1_Click() Dim i If List1.ListCount < 5 Then i = InputBox("ENTER ITEM NAME", 5) List1.AddItem i, 0 Else MsgBox "Queue is full " End If End Sub Private Sub Command2_Click() If List1.ListCount > 0 Then List1.RemoveItem (List1.ListCount - 1) Else MsgBox "Queue is empty " End If End Sub Private Sub Command3_Click() Dim i, j If List1.ListCount > 0 Then For i = 0 To List1.ListCount Step 1 j = j + " " + List1.List(i) Next MsgBox j, , "Queue Elements Are" Else MsgBox "Queue Is Empty" End If End Sub
MCA IV Semester
Unload Me End Sub
Output:
Page 31
MCA IV Semester
13) Aim: To Develop a Visual Basic Application to check whether the given string is palindrome string (or) not. Description:
This program is used to check the given string is palindrome or not. Control Form Label Label2 Command1 Properties Name Caption Name Caption Name Caption Name Caption Values Form1 Form1 Label1 Palindrome String Label2 String Command1 Result Event Load
Click
Code:
Private Sub Command1_Click() Dim S, N As String Dim I S = Text1.Text N = StrReverse(S) I = StrComp(S, N, vbBinaryCompare) If I = 0 Then MsgBox "GIVEN STRING IS PALINDROME" Else MsgBox "GIVEN STRING IS NOT PALINDROME" End If End Sub
Output:
Page 32
MCA IV Semester
14) Aim: To Develop a Visual Basic Application to check whether the given numbers one of the categories like
1) Strong Number 2) Perfect Number 3) Palindrome Number
Description:
This Program is used to check whether the given number is Strong Number (or) Perfect Number (or) Palindrome Number.
Properties Name Caption Name Caption Name Caption Name Caption Name Caption Name Caption Name Caption Name Caption
Values Form1 Form1 Label1 Check The Given Number Label2 Enter A Number Command1 Strong Number Command2 Perfect Number Command3 Palindrome Number Command4 Exit Text1 Empty Load
Event
Code:
Private Sub Command1_Click() Dim no, s, r, i, temp As Integer s=0 no = Val(Text1.Text) temp = Val(no) While (temp > 0) r = temp Mod 10 f=1 For i = 1 To r Step 1 f=f*i Next s=s+f temp = temp / 10 Wend If no = s Then MsgBox "It Is Strong Number" Else MsgBox "It Is Not A Strong Number " End If End Sub
Page 33
MCA IV Semester
Private Sub Command2_Click() Dim no, r As Integer no = Val(Text1.Text) For i = 1 To no - 1 Step 1 If no Mod i = 0 Then r=r+i End If Next If no = r Then MsgBox "It Is Perfect Number" Else MsgBox "It Is Not A Perfect Number" End If End Sub Private Sub Command3_Click() Dim no, n1, r, temp As Integer no = Val(Text1.Text) n1 = 0 temp = Val(no) While (temp > 0) r = temp Mod 10 n1 = n1 * 10 + r temp = temp / 10 Wend If no = n1 Then MsgBox "It Is Palindrome Number " Else MsgBox "It Is Not A Palindrome Number " End If End Sub Private Sub Command4_Click() Unload Me End Sub Output:
Page 34
MCA IV Semester
Page 35
MCA IV Semester
15) Aim: To Develop a Visual Basic Application for coping the elements from one list to other list and Vice versa. Description:
This program is used to copy the elements from one list to another list. Control Form Label Label2 Labe3 Command1 Command2 Command3 Command4 Command5 Command6 ListBox1 istBox2 Properties Name Caption Name Caption Name Caption Name Caption Name Caption Name Caption Name Caption Name Caption Name Caption Name Caption Name Name Values Form1 Form1 Label1 List1 Label2 List2 Label3 Copy From One List To Another List Command1 > Command2 >> Command3 < Command4 << Command5 Insert To List1 Command6 Insert To List2 List1 List2 Event Load
Code:
Private Sub Command1_Click() Dim i For i = 0 To List1.ListCount - 1 Step 1 If List1.ListIndex >= 0 Then List2.AddItem List1.List(List1.ListIndex) List1.RemoveItem List1.ListIndex End If Next End Sub Private Sub Command2_Click() Dim i, j, k If List1.ListCount > 0 Then For i = 0 To List1.ListCount - 1 Step 1 k=i j = List1.List(i) List2.AddItem j, List2.ListCount Next Dept. Of Computer Science & Engg Page 36
MCA IV Semester
End If For i = List1.ListCount - 1 To 0 Step -1 List1.RemoveItem i Next End Sub Private Sub Command3_Click() Dim i For i = 0 To List2.ListCount - 1 Step 1 If List2.ListIndex >= 0 Then List1.AddItem List2.List(List2.ListIndex) List2.RemoveItem List2.ListIndex End If Next End Sub Private Sub Command4_Click() Dim i, j If List2.ListCount > 0 Then For i = 0 To List2.ListCount - 1 Step 1 j = List2.List(i) List1.AddItem j, List1.ListCount Next End If For i = List2.ListCount - 1 To 0 Step -1 List2.RemoveItem i Next End Sub Private Sub Command5_Click() Dim i i = InputBox("ENTER ITEM NAME", 5) List1.AddItem i, 0 End Sub Private Sub Command6_Click() Dim i i = InputBox("ENTER ITEM NAME", 5) List2.AddItem i, 0 End Sub Private Sub Command9_Click() Unload Me End Sub
Page 37
MCA IV Semester
Output:
Page 38
MCA IV Semester
16) Aim: To develop a Visual Basic Application to read & Print User data by using input box And Msg Box. Description:
This program is used to perform the read And Print the User Data by using inputBox And Msg Box. Control Form Label Label2 Labe3 Label4 Label5 Label6 Properties Name Caption Name Caption Name Caption Name Caption Name Caption Name Caption Name Caption Values Form1 Form1 Label1 Read And Print User Data Label2 Name Label3 Gender Label4 Qualification Label5 Experience Label6 Age Load Event
Code:
Private Sub Form_Load() Dim N As String Dim G As String Dim Q As String Dim E As String Dim A As Integer N = InputBox("ENTER YOUR NAME:") MsgBox N G = InputBox("ENTER GENDER : MALE/FEMALE") MsgBox G Q = InputBox("ENTER QUALIFICATION:") MsgBox Q E = InputBox("ENTER EXPERIENCE:") MsgBox E A = InputBox("ENTER AGE:") MsgBox A Text1.Text = N Text2.Text = G Text3.Text = Q Text4.Text = E Text5.Text = A End Sub
Page 39
MCA IV Semester
Output:
Page 40
MCA IV Semester
17) Aim: To Develop a Visual Basic Application a calculator using VB Controls. Description:
This Program is used to perform the Arithmetic Operations. Control Properties Values Form Name Form1 Caption Form1 Label Name Label1 Caption Calculator Frame Name Frame1 Caption Calculator(100) Checks TextBox1 Name Text1 Caption Empty TextBox2 Name Text2 Caption Empty TextBox3 Name Text3 Caption display Command1 Name Command1 Caption 7 Command2 Name Command2 Caption 8 Command3 Name Command3 Caption 9 Command4 Name Command4 Caption / Command5 Name Command5 Caption 4 Command6 Name Command6 Caption 5 Command7 Name Command7 Caption 6 Command8 Name Command8 Caption * Command9 Name Command9 Caption 1 Command10 Name Command10 Caption 2 Command11 Name Command11 Caption 3 Command12 Name Command12 Caption + Command13 Name Command13 Caption OFF Command14 Name Command14 Caption 0 Command15 Name Command15 Caption . Command16 Name Command16 Caption = Event Load
Click Click Click Click Click Click Click Click Click Click Click Click Click Click Click Click
Page 41
MCA IV Semester
Command17 Command18 Command19 Command20 Command21 Command22 Name Caption Name Caption Name Caption Name Caption Name Caption Name Caption Command17 Sqrt Command18 square Command19 Check=> Command20 Corrent00..0 Command21 ON Command22 AC
Code:
Dim j As Integer Dim flag As Integer Dim temp As Integer Dim operator As String Dim op As String Dim a As Double Dim b As Double Dim result As Double Dim i As Integer Dim s(50) As String Dim c(100) As Integer Private Sub clear_Click() i=0 j=0 Text1 = " " display.Text = "0" op = "" flag = "0" Text2 = "on " Command1.Enabled = True Command2.Enabled = True Command3.Enabled = True Command4.Enabled = True Command5.Enabled = True Command6.Enabled = True Command7.Enabled = True Command8.Enabled = True Command9.Enabled = True Command10.Enabled = True Command11.Enabled = True Command12.Enabled = True Command13.Enabled = True Command14.Enabled = True Command15.Enabled = True Command16.Enabled = True Command17.Enabled = True Command18.Enabled = True Command19.Enabled = True Command20.Enabled = False Dept. Of Computer Science & Engg Page 42
MCA IV Semester
Command22.Enabled = True Command21.Enabled = True clear.Enabled = False End Sub Private Sub Command1_Click() If display.Text = "0" Then display.Text = "7" Else display.Text = display.Text + "7" End If End Sub Private Sub Command10_Click() If display.Text = "0" Then display.Text = "2" Else display.Text = display.Text + "2" End If End Sub Private Sub Command11_Click() If display.Text = "0" Then display.Text = "3" Else display.Text = display.Text + "3" End If End Sub Private Sub Command12_Click() operator = "+" c(i) = Val(display.Text) s(i) = "+" a = Val(display.Text) display = "0" Text2 = "+" i=i+1 End Sub Private Sub Command13_Click() Command1.Enabled = False Command2.Enabled = False Command3.Enabled = False Command4.Enabled = False Command5.Enabled = False Command6.Enabled = False Command7.Enabled = False Command8.Enabled = False Command9.Enabled = False Command10.Enabled = False Command11.Enabled = False Command12.Enabled = False Command13.Enabled = False Command14.Enabled = False Command15.Enabled = False Command16.Enabled = False Command17.Enabled = False Command18.Enabled = False Dept. Of Computer Science & Engg
Page 43
MCA IV Semester
Command19.Enabled = False Command20.Enabled = False Command21.Enabled = False Command22.Enabled = False clear.Enabled = True display = "Thank you..." End Sub Private Sub Command14_Click() If display.Text = "0" Then display.Text = "0" Else display.Text = display.Text + "0" End If End Sub Private Sub Command15_Click() If InStr(display.Text, ".") Then Exit Sub Else display.Text = display.Text + "." End If End Sub Private Sub Command16_Click() b = Val(display.Text) c(i) = Val(display.Text) s(i) = "=" If operator = "+" Then result = a + b If operator = "-" Then result = a - b If operator = "*" Then result = a * b If operator = "/" And b <> "0" Then result = a / b display.Text = result op = "=" Text2 = "=" i=i+1 End Sub Private Sub Command17_Click() If display.Text <> "0" Then temp = Val(display.Text) display = Sqr(temp) c(i) = Sqr(temp) c(i) = "Sqrt" temp = "0" Text2 = "Sqrt" i=i+1 End If End Sub Private Sub Command18_Click() If display.Text <> "0" Then temp = Val(display.Text) display = temp * temp temp = "0" Text2 = "Sqare" c(i) = temp * temp Dept. Of Computer Science & Engg
Page 44
MCA IV Semester
s(i) = "Sqare" i=i+1 End If End Sub Private Sub Command19_Click() If i >= j Then display = c(j) Text2 = s(j) Else Command1.Enabled = False Command2.Enabled = False Command3.Enabled = False Command4.Enabled = False Command5.Enabled = False Command6.Enabled = False Command7.Enabled = False Command8.Enabled = False Command9.Enabled = False Command10.Enabled = False Command11.Enabled = False Command12.Enabled = False Command13.Enabled = False Command14.Enabled = False Command15.Enabled = False Command16.Enabled = False Command17.Enabled = False Command18.Enabled = False Command19.Enabled = False clear.Enabled = True Command20.Enabled = False Command21.Enabled = False display = "" Text1 = "" Text2 = "" End If Text1 = j + 1 Text2 = s(i) j=j+1 End Sub Private Sub Command2_Click() If display.Text = "0" Then display.Text = "8" Else display.Text = display.Text + "8" End If End Sub Private Sub Command20_Click() Exit Sub End Sub
MCA IV Semester
display = "Thank you..." Text2 = "" Text1 = "" End Sub Private Sub Command22_Click() i=0 j=0 Text1 = " " display.Text = "0" op = "" flag = "0" Text2 = "AC" End Sub Private Sub Command3_Click() If display.Text = "0" Then display.Text = "9" Else display.Text = display.Text + "9" End If End Sub Private Sub Command4_Click() operator = "/" c(i) = Val(display.Text) s(i) = "/" a = Val(display.Text) display = "0" Text2 = "/" i=i+1 End Sub Private Sub Command5_Click() If display.Text = "0" Then display.Text = "4" Else display.Text = display.Text + "4" End If End Sub Private Sub Command6_Click() If display.Text = "0" Then display.Text = "5" Else display.Text = display.Text + "5" End If End Sub Private Sub Command7_Click() If display.Text = "0" Then display.Text = "6" Else display.Text = display.Text + "6" End If End Sub Private Sub Command8_Click() Dept. Of Computer Science & Engg
Page 46
MCA IV Semester
a = Val(display.Text) operator = "*" c(i) = Val(display.Text) s(i) = "X" a = Val(display.Text) display = "0" Text2 = "X" i=i+1 End Sub Private Sub Command9_Click() If display.Text = "0" Then display.Text = "1" Else display.Text = display.Text + "1" End If End Sub
Output:
Page 47
MCA IV Semester
Page 48
MCA IV Semester
Page 49
MCA IV Semester
19) Aim: To Develop a Visual Basic Application to manage the following operations.
i) Insert an employee into database table. ii) Delete an employee from the database table. iii) Update the employee salary with respect to the employee number. iv) Display the employee details.
Description:
This program is used to perform the insert And Delete And Update Quires on database . Control Form Label1 Label2 Label3 Label4 Command1 Command2 Command3 Command4 Command5 Command6 TextBox1 TrxtBox2 TextBox3 Properties Name Caption Name Caption Name Caption Name Caption Name Caption Name Caption Name Caption Name Caption Name Caption Name Caption Name Caption Name Caption Name Caption Name Caption Values Form1 Form1 Label1 Employee Information Label2 Employee No Label3 Employee Name Label4 Salary Command1 Insert Command2 Delete Command3 Update Command4 Display Command5 Clear Command6 Exit Text1 Empty Text2 Empty Text3 Empty Load Event
Code:
Dim cn As ADODB.Connection Dim rs As ADODB.Recordset Private Sub Command1_Click() rs.AddNew rs(0) = Text1.Text rs(1) = Text2.Text rs(2) = Text3.Text rs.Update MsgBox "U r Record Inserted" End Sub
Page 50
MCA IV Semester
Private Sub Command2_Click() Dim n As Integer n = Val(InputBox("Enter the emp number:")) While (rs.EOF <> True) If n = rs(0) Then rs.Delete Exit Sub Else rs.MoveNext End If Wend MsgBox "U r Record Deleted" End Sub Private Sub Command3_Click() n = Val(InputBox("Enter the emp number:")) While (rs.EOF <> True) If n = rs(0) Then rs(0) = Text1.Text rs(1) = Text2.Text rs(2) = Text3.Text rs.Update MsgBox "One record updated...", vbQuestion Else rs.MoveNext End If Wend MsgBox "U r Record Updated" End Sub Private Sub Command4_Click() Dim n As Integer n = Val(InputBox("Enter the emp number:")) While (rs.EOF <> True) If n = rs(0) Then Text1.Text = rs(0) Text2.Text = rs(1) Text3.Text = rs(2) Exit Sub Else rs.MoveNext End If Wend End Sub Private Sub Command5_Click() Text1.Text = "" Text2.Text = "" Text3.Text = "" End Sub Private Sub Command6_Click() Unload Me End Sub
Page 51
MCA IV Semester
Output:
Page 52
MCA IV Semester
Page 53
MCA IV Semester
Page 54
MCA IV Semester
20) Aim: To Develop a Visual Basic Application which perform record navigations
i) First. ii) Last. iii) Previous. iv) Next.
Description:
This Program is used to perform the record navigations Control Form Label1 Label2 Label3 Label4 Command1 Command2 Command3 Command4 Command5 Command6 TextBox1 TrxtBox2 TextBox3 Properties Name Caption Name Caption Name Caption Name Caption Name Caption Name Caption Name Caption Name Caption Name Caption Name Caption Name Caption Name Caption Name Caption Name Caption Values Form1 Form1 Label1 Employee Information Label2 Employee No Label3 Employee Name Label4 Salary Command1 First Command2 Last Command3 Previous Command4 Next Command5 Clear Command6 Exit Text1 Empty Text2 Empty Text3 Empty Event Load
Code:
Dim RS As ADODB.Recordset Dim cn As ADODB.Connection Private Sub Command1_Click() RS.MoveFirst Text1.Text = RS(0) Text2.Text = RS(1) Text3.Text = RS(2) End Sub
Page 55
MCA IV Semester
Private Sub Command2_Click() RS.MoveLast Text1.Text = RS(0) Text2.Text = RS(1) Text3.Text = RS(2) End Sub Private Sub Command3_Click() If Text1.Text <> Empty Then RS.MovePrevious If RS.EOF <> True Then Text1.Text = RS(0) Text2.Text = RS(1) Text3.Text = RS(2) Else MsgBox "No Records", vbCritical End If Else MsgBox "Nothing", vbExclamation End If End Sub Private Sub Command4_Click() If Text1.Text <> Empty Then RS.MoveNext If RS.EOF <> True Then Text1.Text = RS(0) Text2.Text = RS(1) Text3.Text = RS(2) Else MsgBox "No Records", vbCritical End If Else MsgBox "Nothing", vbExclamation End If End Sub Private Sub Command5_Click() Text1.Text = "" Text2.Text = "" Text3.Text = "" End Sub Private Sub Command6_Click() Unload Me End Sub Private Sub Form_Load() Set cn = New ADODB.Connection cn.Open "dsn=murali;uid=internal;pwd=oracle" MsgBox "connection established" Set RS = New ADODB.Recordset RS.Open "select * from emp", cn, adOpenDynamic, adLockOptimistic End Sub
Page 56
MCA IV Semester
Output:
Page 57
MCA IV Semester
Page 58