Vous êtes sur la page 1sur 84

BAPATLA ENGINEERING COLLEGE: BAPATLA

Department of MCA

1. Develop a visual basic application to search an item from list of items


using Binary search.
/// declaring variables
Dim a(20) As Integer
Dim n As Integer
Dim i As Integer
Dim m As Integer
Dim h As Integer
Dim l As Integer
Dim ele As Integer

Private Sub btn_readn_Click() '/////To read size of array


n = Txt_readsize.Text
MsgBox " n value is loaded ", vbOKOnly
btnreadarray.Visible = True
txt_size.Enabled = False
btn_readsize.Visible = False
End Sub

Private Sub btn_readsize_Click() '/// N value is readed


btn_readsize.Visible = True
txt_size.Visible = True
lbl_readn.Visible = False
btn_readn.Visible = False
End Sub

Private Sub btn_readsearchele_Click() ' /// to read search element


txt_searchelement.Visible = True
btn_readsearchele.Visible = False
btn_search.Visible = True
btn_readarray.Enabled = False
End Sub

Private Sub Btn_search_Click() ' /// code for searching element


Dim f As Integer
f=0
ele = txt_searchelement.Text
l=1
h=n
Do While (l <= h And f = 0)
m = (l + h) / 2
If ele = a(m) Then
f=1
ElseIf ele < a(m) Then
h=m-1
f=0

1
Visual Programming Lab Manual (MCA 407)
BAPATLA ENGINEERING COLLEGE: BAPATLA
Department of MCA
Else
l=m+1
f=0
End If
Loop
If f = 1 Then
MsgBox "element found"
Else
MsgBox "Element not found"
End If
btn_search.Visible = False
btn_serachanother.Visible = True
End Sub

Private Sub btn_readarray_Click() ' /// to read elements into array


For i = 1 To n
a(i) = CInt(InputBox("enter array elements"))
Next
Frame2.Visible = True
btn_readsearchele.Visible = True
btn_searchanother.Visible = False
btn_readn.Enabled = False
MsgBox "array elements loaded successfully"
Frame1.Visible = False
End Sub

Private Sub btn_searchanother_Click() ' /// to search another element


Btn_search.Visible = True
Txt_searchelement.Text = " "
Btn_searchanother.Visible = False
End Sub

Private Sub btn_exit_Click() ' /// exit


End
End Sub

Private Sub Form_Load() ' /// form load


btn_readsize.Visible = False
txt_size.Visible = False
lbl_readn.Visible = False
Frame2.Visible = False
btn_readarray.Visible = False
txt_searchelement.Visible = False
txt_searchelement.Text = " "
lbl_readelement.Visible = False
btn_readsearchele.Visible = False
btn_search.Visible = False
End Sub

2
Visual Programming Lab Manual (MCA 407)
BAPATLA ENGINEERING COLLEGE: BAPATLA
Department of MCA

Design:

Title of the form: Application to Search an Item.


Controls used:

Control Name Caption


Frame1 Frame1
Frame2 Frame2
Label1 lbl_readn Enter N value
Label2 lbl_readelement Enter Search element
Textbox1 txt_size
Textbox2 txt_searchelement
Button1 btn_readsize Read Size
Button2 btn_readn Read N
Button3 btn_readsearchele Read search element
Button4 btn_searchele Search Element
Button5 btn_readarray Read array Elements
Button6 btn_searchanother Search another element
Button7 btn_exit Exit

3
Visual Programming Lab Manual (MCA 407)
BAPATLA ENGINEERING COLLEGE: BAPATLA
Department of MCA

2. Develop a Visual basic application to demonstrate the stack operations.


/// declaring variables
Dim t As Integer
Dim st(10) As Integer
Dim n As Integer
Dim i As Integer
Dim el As Integer

Private Sub btn_readsizeofstack_Click()


txt_readsize.Visible = True
btn_readsizeofstack.Visible = False
btn_readelements.Visible = True
End Sub

Private Sub btn_push_Click()


btn_exit.Visible = True
Frame2.Visible = True
t=t+1
If t > n Then
t=n
lbl_name.ForeColor = &HFF&
lbl_name.Caption = "stack is full"
btn_push.Enabled = False
Else
st(t) = CInt(InputBox("enter elements into stack"))
lbl_name.ForeColor = &HC000&
lbl_name.Caption = st(t) & "is pushed onto the stack"
i=t
lst_name.Clear
Do
lst_name.AddItem st(i)
i=i-1
Loop While (i > 0)
btn_push.Enabled = True
End If
End Sub

Private Sub btn_pop_Click()


btn_push.Enabled = True
Frame2.Visible = True
If t = 0 Then
lst_name.Clear
lbl_name.ForeColor = &HFF&
lbl_name.Caption = "stack is empty"
btn_pop.Enabled = False

4
Visual Programming Lab Manual (MCA 407)
BAPATLA ENGINEERING COLLEGE: BAPATLA
Department of MCA
t=0
Else
el = st(t)
t=t-1
i=t
lst_name.Clear
While (i > 0)
lst_name.AddItem st(i)
i=i-1
Wend
lbl_name.ForeColor = &HC000&
lbl_name.Caption = el & "is poped from stack"
btn_pop.Enabled = True
End If
End Sub

Private Sub btn_readelements_Click()


n = txt_readsize.Text
MsgBox " n vlaue is loaded successfully"
txt_readsize.Visible = False
lst_name.Visible = True
btn_push.Visible = True
btn_readelements.Visible = False
btn_pop.Visible = True
End Sub

Private Sub btn_exit_Click()


End
End Sub

Private Sub Form_Load()


Frame2.Visible = False
btn_push.Visible = False
txt_readsize.Visible = False
btn_readsizeofstack.Visible = True
t=0
lst_name.Visible = False
btn_pop.Visible = False
btn_readelements.Visible = False
btn_exit.Visible = False
End Sub

5
Visual Programming Lab Manual (MCA 407)
BAPATLA ENGINEERING COLLEGE: BAPATLA
Department of MCA

Design:

Title: Application to demonstrate the stack operations.

Controls:

Control Name Caption


Frame1 Frame1
Frame2 Frame2
Label1 Lbl_name
Textbox1 txt_readsize
Button1 btn_readsizeofstack Read Size of stack
Button2 btn_push Push
Button3 btn_pop Pop
Button4 btn_readelements Read Elements
Button5 btn_exit Exit
Listbox1 lst_name

6
Visual Programming Lab Manual (MCA 407)
BAPATLA ENGINEERING COLLEGE: BAPATLA
Department of MCA

3. Develop a visual basic application to demonstrate Queue Operations.


/// Declaring variables

Dim f As Integer
Dim a(10) As Integer
Dim n As Integer
Dim r As Integer
Dim el As Integer
Dim f1 As Integer
Dim t As Integer

Private Sub btn_readsizeofqueue_Click()


txt_size.Visible = True
btn_readsizeofqueue.Visible = False
btn_readelements.Visible = True
End Sub

Private Sub btn_enqueue_Click()


btn_exit.Visible = True
Frame2.Visible = True
btn_dequeue.Enabled = True
r = (r + 1) Mod n
a(r) = CInt(InputBox("enter elements into Queue"))
If f = r Then
'r = n
lbl_text.ForeColor = &H8000&
lst_name.AddItem a(r)
lbl_text.Caption = a(r) & "is inserted into queue and Queue is full"
btn_enqueue.Enabled = False
Else
lbl_text.ForeColor = &HFF&
lbl_text.Caption = a(r) & "is inserted into queue"
lst_name.AddItem a(r)
btn_enqueue.Enabled = True
End If
End Sub

Private Sub btn_dequeue_Click()


btn_enqueue.Enabled = True
Frame2.Visible = True
f = (f + 1) Mod n
el = a(f)
If f = r Then
lst_name.Clear

7
Visual Programming Lab Manual (MCA 407)
BAPATLA ENGINEERING COLLEGE: BAPATLA
Department of MCA
lbl_text.ForeColor = &H8000&
lbl_text.Caption = "Queue is empty"
btn_dequeue.Enabled = False
Else
lst_name.Clear
i=f
'i = (f + 1) Mod n
Do
i = (i + 1) Mod n
lst_name.AddItem a(i)
Loop While (i <> r)
lbl_text.ForeColor = &HFF&
lbl_text.Caption = el & "is deleted from queue"
btn_dequeue.Enabled = True
End If
End Sub

Private Sub btn_readelements_Click()


n = Txt_size.Text
MsgBox " n vlaue is loaded successfully"
Txt_size.Visible = False
lst_name.Visible = True
btn_enqueue.Visible = True
btn_readelements.Visible = False
btn_dequeue.Visible = True
f=0
r=0
t=0
End Sub

Private Sub btn_exit_Click()


End
End Sub

Private Sub Form_Load()


Frame2.Visible = False
btn_enqueue.Visible = False
txt_size.Visible = False
btn_readsizeofqueue.Visible = True
lst_name.Visible = False
btn_dequeue.Visible = False
btn_readelements.Visible = False
btn_exit.Visible = False
End Sub

8
Visual Programming Lab Manual (MCA 407)
BAPATLA ENGINEERING COLLEGE: BAPATLA
Department of MCA

Design:

Title: Application to demonstrate the queue operations.


Controls:

Control Name Caption


Frame1 Frame1
Frame2 Frame2
Label1 Lbl_name
Textbox1 txt_readsize
Button1 btn_readsizeofstack Read Size of stack
Button2 btn_enqueue Enqueue
Button3 btn_dequeue Dequeue
Button4 btn_readelements Read Elements
Button5 btn_exit Exit
Listbox1 lst_name

9
Visual Programming Lab Manual (MCA 407)
BAPATLA ENGINEERING COLLEGE: BAPATLA
Department of MCA

4. Develop a visual basic application to check the given string is palindrome


or not.
'/// declaring variables
Dim s1 As String
Dim i As Integer
Dim j As Integer
Dim n As Integer
Dim c As String
Dim s As String

Private Sub btn_readstring_Click() '// to read a string


s = ""
s1 = ""
If txt_string.Text = "" Then
MsgBox "Enter any String in the Text Box"
txt_string.SetFocus
Else
s = txt_string.Text
btn_readstring.Visible = False
txt_string.Enabled = False
btn_palindrome.Visible = True
End If
End Sub

Private Sub btn_palindrome_Click() ' // to check string is palindrome or not


n = Len(s)
i=n
Do
c = Mid(s, i, 1)
s1 = s1 & c
i=i-1
Loop While i > 0
If (StrComp(s, s1)) = 0 Then
lbl_text.Caption = "The given string is Palindrome"
Else
lbl_text.Caption = s & " is not a Palindrome"
End If
txt_string.Text = ""
txt_string.Enabled = True
btn_palindrome.Visible = False
txt_string.SetFocus
End Sub

Private Sub btn_exit_Click() '// Exit


End
End Sub

10
Visual Programming Lab Manual (MCA 407)
BAPATLA ENGINEERING COLLEGE: BAPATLA
Department of MCA

Private Sub btn_continue_Click() '/// to check another string


btn_readstring.Visible = True
End Sub

Private Sub Form_Load() '/// form load


s = ""
s1 = ""
lbl_text.Caption = "Enter any string in Text Box"
End Sub

Design:
Title: Application to demonstrate the queue operations.
Controls:

Control Name Caption


Label1 lbl_text
Textbox1 txt_string
Button1 btn_readstring Read String
Button2 btn_palindrome Palindrome
Button3 btn_exit Exit
Button4 Btn_continue Continue

11
Visual Programming Lab Manual (MCA 407)
BAPATLA ENGINEERING COLLEGE: BAPATLA
Department of MCA

5. Develop a visual basic application to find the factorial of the given


number by using functions.
'/// Declaring varibles
Dim n As Integer
Dim a As Integer

Private Sub btn_readnumber_Click() '/// to read a number


If txt_number.Text = "" Then
MsgBox "Enter any String in the Text Box"
txt_number.SetFocus
Else
btn_readnumber.Visible = False
txt_number.Enabled = False
btn_findfactorial.Visible = True
End If
End Sub

Public Function factorial(n As Integer) As Integer '/// Factorial code


Dim i As Integer
Dim f As Integer
f=1
For i = 1 To n
f=f*i
Next
factorial = f
End Function

Private Sub btn_findfactorial_Click() '/// to get the factorial of number


lbl_text.Visible = True
n = txt_number.Text
a = factorial(n)
lbl_text.Caption = n & " - Factorial is " & a
btn_findfactorial.Visible = False
btn_continue.Visible = True
txt_number.Enabled = True
txt_number.Text = ""
End Sub

Private Sub btn_exit_Click() ' /// exit code


End
End Sub

Private Sub btn_continue_Click() '/// to calculate factorial of another number ie to continue


btn_readnumber.Visible = True
End Sub

12
Visual Programming Lab Manual (MCA 407)
BAPATLA ENGINEERING COLLEGE: BAPATLA
Department of MCA

Private Sub Form_Load() '/// form load code


lbl_text.Visible = False
btn_continue.Visible = False
End Sub

Design:
Title: Application to find factorial of given number using functions.
Controls:

Control Name Caption


Label1 lbl_text
Textbox1 txt_number
Button1 btn_readnumber Read Number
Button2 btn_findfactorial Find Factorial
Button3 btn_exit Exit
Button4 Btn_continue Continue

13
Visual Programming Lab Manual (MCA 407)
BAPATLA ENGINEERING COLLEGE: BAPATLA
Department of MCA

6. Develop a visual basic application to check the given number in one of the
categories like
i)Strong Number
II) Palindrome
III)Perfect Number
Dim n As Integer
Dim r As Integer
Dim s As Integer
Dim t As Integer
Dim s1 As String
Dim x As Integer

Private Sub btn_readnumber_Click()


lbl_number.Visible = True
lbl_result.Visible = True
txt_number.Visible = True
rdo_strong.Value = False
rdo_perfect.Value = False
rdo_palindrome.Value = False
If txt_number.Text = "" Then
lbl_result.ForeColor = &HFF&
lbl_result.Caption = "enter a number"
txt_number.SetFocus
Else
btn_readnumber.Visible = False
txt_number.Enabled = False
btn_check.Visible = True
Frame1.Visible = True
lbl_select.Visible = True
rdo_strong.Visible = True
rdo_perfect.Visible = True
rdo_palindrome.Visible = True
End If
End Sub

Private Sub btn_check_Click()


btn_readnumber.Visible = False
btn_continue.Visible = True
btn_exit.Visible = True
lbl_result.Visible = True
n = txt_number.Text
Select Case x
Case 1:
strong (n)
lbl_result.ForeColor = &HFF&

14
Visual Programming Lab Manual (MCA 407)
BAPATLA ENGINEERING COLLEGE: BAPATLA
Department of MCA
lbl_result.Caption = n & " - is " & s1
Case 2:
perfect (n)
lbl_result.ForeColor = &HFF00&
lbl_result.Caption = n & " - is " & s1
Case 3:
palindrome (n)
lbl_result.ForeColor = &HFF0000
lbl_result.Caption = n & " - is " & s1
End Select
End Sub

Private Sub btn_continue_Click()


txt_number.Text = ""
btn_readnumber.Visible = True
txt_number.Enabled = True
txt_number.SetFocus
btn_check.Visible = False
btn_continue.Visible = False
btn_exit.Visible = False
rdo_strong.Visible = False
rdo_perfect.Visible = False
rdo_palindrome.Visible = False
Frame1.Visible = False
lbl_select.Visible = False
lbl_result.Visible = False
End Sub
Private Sub btn_exit_Click()
End
End Sub

Private Sub Form_Load()


Frame1.Visible = False
btn_readnumber.Visible = True
btn_check.Visible = False
btn_continue.Visible = False
btn_exit.Visible = False
lbl_select.Visible = False
lbl_result.Visible = False
End Sub

Public Function palindrome (n As Integer)


r=n
s=0
While (n > 0)
d = n Mod 10
s = s * 10 + d
n = n / 10

15
Visual Programming Lab Manual (MCA 407)
BAPATLA ENGINEERING COLLEGE: BAPATLA
Department of MCA
Wend
If s = r Then
s1 = "Palindrome"
Else
s1 = "Not palindrome"
End If
End Function

Public Function strong (n As Integer)


Dim f As Integer
r=n
s=0
While (n > 0)
d = n Mod 10
f=1
While (d > 0)
f=f*d
d=d-1
Wend
s=s+f
n = n / 10
Wend
If s = r Then
s1 = "strong"
Else
s1 = "Not Strong"
End If
End Function

Public Function perfect (n As Integer)


Dim i As Integer
r=n
s=0
i=1
While (i < n)
If (n Mod i = 0) Then
s=s+i
End If
i=i+1
Wend
If s = r Then
s1 = "perfect"
Else
s1 = "Not perfect"
End If
End Function

16
Visual Programming Lab Manual (MCA 407)
BAPATLA ENGINEERING COLLEGE: BAPATLA
Department of MCA
Private Sub rdo_strong_Click()
x=1
End Sub

Private Sub rdo_perfect_Click()


x=2
End Sub

Private Sub rdo_palindrome_Click()


x=3
End Sub

17
Visual Programming Lab Manual (MCA 407)
BAPATLA ENGINEERING COLLEGE: BAPATLA
Department of MCA

7. Develop a visual basic application for copying the elements from one list
to the other list and vice versa (Note: Implement single element, Multiple
elements transfer from lists).

First create node.cls by using class module.


1. Open the project .Right click on form .
2. Click on Add and select class Module.
3. In the properties change the class name as node. Then node.cls file is created and write
following code.

Public key as Integer


Public pnext as node

Write Form code


'object pointer to head of list

Dim head As node


Dim n As Integer
Dim movehead As node
Dim head1 As node
Dim head2 As node
Dim temp As node
Dim elementtt As Integer
Dim pos(20) As Integer

Private Sub btn_refresh_Click()


rdo_movesingle.Enabled = True
rdo_movemultiple.Enabled = True
btn_movel1tol2.Visible = False
btn_moveelements.Enabled = True
rdo_movesingle.Value = False
rdo_movemultiple.Value = False
End Sub

Private Sub btn_exit_Click()


End
End Sub

Private Sub btn_createlist1_Click()


btn_createlist1.Visible = False
Dim curr As node 'object pointer to current pos in
Dim i As Integer 'list used in For loop

'&&&&&&&&&&&&& CREATE LIST &&&&&&&&&&&&&&&&

18
Visual Programming Lab Manual (MCA 407)
BAPATLA ENGINEERING COLLEGE: BAPATLA
Department of MCA
Set head1 = New node 'object pointer to new node
head1.key = 0 'dummy head
Set curr = head1 'keep head pointer here
For i = 1 To 20 'iterate n times to fill list
Set curr.pnext = New node 'insert new node after current
Set curr = curr.pnext 'set current one = new node
curr.key = i 'set new node key value
Next i
Set curr.pnext = New node 'dummy tail
Set curr = curr.pnext 'move current to dummy tail
curr.key = 0 'set value of dummy tail
Set curr.pnext = curr 'points to itself to identify end

'&&&&&&&&&&&&&& ADDING TO LISTBOX &&&&&&&&&&&&&&&&&&

Dim temp As node


Dim k As Integer
k=0
Set temp = head1.pnext
While Not temp.pnext Is temp
k=k+1
lst_one.AddItem ("pos-" & k & "----" & temp.key)
Set temp = temp.pnext
Wend
End Sub

Private Sub btn_createlist2_Click()

btn_createlist2.Visible = False
Frame1.Visible = True
Dim curr As node 'object pointer to current pos in
Dim i As Integer 'list used in For loop

'CREATE LIST
Set head2 = New node 'object pointer to new node
head2.key = 0 'dummy head
Set curr = head2 'keep head pointer here
For i = 1 To 20 'iterate n times to fill list
Set curr.pnext = New node 'insert new node after current
Set curr = curr.pnext 'set current one = new node
curr.key = i + 20 'set new node key value
Next i
Set curr.pnext = New node 'dummy tail
Set curr = curr.pnext 'move current to dummy tail
curr.key = 0 'set value of dummy tail
Set curr.pnext = curr 'points to itself to identify end

19
Visual Programming Lab Manual (MCA 407)
BAPATLA ENGINEERING COLLEGE: BAPATLA
Department of MCA

&&&&&&&&&&&&&&& ADDING TO LISTBOX &&&&&&&&&&&&&&&&&&&

Dim templist As node


Dim j As Integer
j=0
Set templist = head2.pnext
While Not templist.pnext Is templist
j=j+1
lst_two.AddItem ("pos-" & j & "----" & templist.key)
Set templist = templist.pnext
Wend

End Sub

'//////////////////////////////// MOVE FUNCTION ////////////////////////////////

Private Sub List1to2(ByRef head As node, ByVal pos As Integer)


'//////////////////////reading Element to be moved begin //////////////////////////
Set temp = head1
Dim itemp As Integer
itemp = 0
While itemp < pos
itemp = itemp + 1
Set temp = temp.pnext
Wend
'MsgBox "data is " & temp.key
elementtt = temp.key
'////////////////////reading Element to be moved end ////////////////////////
Set movehead = head
btn_movel1tol2.Visible = False
'MsgBox "element " & movehead.key
While Not movehead.pnext Is movehead
Set movehead = movehead.pnext
Wend
movehead.key = elementtt
Dim node1 As node
Set node1 = New node
Set movehead.pnext = node1
node1.key = 0
Set node1.pnext = node1
lst_two.Clear
Dim templist As node
Dim j As Integer
j=0
Set templist = head2.pnext
While Not templist.pnext Is templist
j=j+1

20
Visual Programming Lab Manual (MCA 407)
BAPATLA ENGINEERING COLLEGE: BAPATLA
Department of MCA
lst_two.AddItem ("pos-" & j & "----" & templist.key)
Set templist = templist.pnext
Wend

******************Removing element from List1*****************

Set movehead = head1


Dim k As Integer
k=0
While k < pos - 1
Set movehead = movehead.pnext
k=k+1
'MsgBox "element is " & movehead.key
Wend
Set movehead.pnext = movehead.pnext.pnext
lst_one.Clear
Dim k1 As Integer
k1 = 0
Set temp = head1.pnext
While Not temp.pnext Is temp
k1 = k1 + 1
lst_one.AddItem ("pos-" & k1 & "----" & temp.key)
Set temp = temp.pnext
Wend
End Sub

Private Sub List2to1(ByRef head As node, ByVal pos As Integer)

'////////////////// Reading Element to be moved begin ////////////////////


Set temp = head2
Dim itemp As Integer
itemp = 0
While itemp < pos
itemp = itemp + 1
Set temp = temp.pnext
Wend
elementtt = temp.key
'/////////////////// Reading Element to be moved end //////////////////////
Set movehead = head
btn_movel1tol2.Visible = False
While Not movehead.pnext Is movehead
Set movehead = movehead.pnext
Wend
movehead.key = elementtt
Dim node1 As node
Set node1 = New node
Set movehead.pnext = node1
node1.key = 0

21
Visual Programming Lab Manual (MCA 407)
BAPATLA ENGINEERING COLLEGE: BAPATLA
Department of MCA
Set node1.pnext = node1
lst_one.Clear
Dim templist As node
Dim j As Integer
j=0
Set templist = head1.pnext
While Not templist.pnext Is templist
j=j+1
lst_one.AddItem ("pos-" & j & "----" & templist.key)
Set templist = templist.pnext
Wend

******************Removing element from List1*****************


Set movehead = head2
Dim k As Integer
k=0
While k < pos - 1
Set movehead = movehead.pnext
k=k+1
Wend
Set movehead.pnext = movehead.pnext.pnext
lst_two.Clear

&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&

'Dim temp As node


Dim k1 As Integer
k1 = 0
Set temp = head2.pnext
While Not temp.pnext Is temp
k1 = k1 + 1
lst_two.AddItem ("pos-" & k1 & "----" & temp.key)
Set temp = temp.pnext
Wend
End Sub

Private Sub btn_movel1tol2_Click()


btn_exit.Visible = True
'/////////////////////////SINGLE ELEMENT TRANSFER //////////////////////////
Dim posflag As Integer
posflag = 0
If rdo_movesingle.Value = True Then
List1to2 head2, n
Else
'///////////////MULTIPLE ELEMENT TRANSFER //////////////////////
For i = 1 To n
List1to2 head2, pos(i) - posflag
posflag = posflag + 1

22
Visual Programming Lab Manual (MCA 407)
BAPATLA ENGINEERING COLLEGE: BAPATLA
Department of MCA
Next i
End If
Frame1.Visible = True
End Sub

Private Sub btn_movel2tol1_Click()


btn_exit.Visible = True
'//////////////////////////////////////SINGLE ELEMENT TRANSFER //////////////
Dim posflag As Integer
posflag = 0
If rdo_movesingle.Value = True Then
List2to1 head1, n
Else '////////////////////MULTIPLE ELEMENT TRANSFER //////////////
For i = 1 To n
List2to1 head1, pos(i) - posflag
posflag = posflag + 1
Next i
End If
Frame1.Visible = True
btn_movel2tol1.Visible = False
End Sub

Private Sub btn_moveelements_Click()


rdo_movesingle.Enabled = False
rdo_movemultiple.Enabled = False
If rdo_movesingle.Value = True Then '///////SINGLE ELEMENT MOVE////////
n = CInt(InputBox("Enter the position of the element to be moved"))
Else '/////MULTIPLE ELEMENTS MOVE///////
n = CInt(InputBox("Enter the Number of Elemnets to be Moved"))
For i = 1 To n
pos(i) = CInt(InputBox("Enetr Position of " & i & "Element"))
Next i
End If
btn_movel1tol2.Visible = True
btn_movel2tol1.Visible = True
btn_moveelements.Enabled = False
End Sub

Private Sub Form_Load()


Frame1.Visible = False
btn_movel1tol2.Visible = False
btn_movel2tol1.Visible = False
btn_exit.Visible = False

End Sub

Private Function DumpList(ByRef head As node) As String

23
Visual Programming Lab Manual (MCA 407)
BAPATLA ENGINEERING COLLEGE: BAPATLA
Department of MCA
'walk list and dump to debug window
Dim strOut As String 'temp var to hold string
Dim curr As node 'object pointer to current node
Set curr = head.pnext 'skip dummy head
While Not curr.pnext Is curr 'walk rest of list to end
strOut = strOut & " " & CStr(curr.key)
Set curr = curr.pnext 'current pointer to next node
Wend
DumpList = strOut 'return string
End Function
Design:
Title: Application to copy elements from one list to another vice versa
Controls:

Control Name Caption


Label1 lbl_list1 List1
Label2 Lbl_list2 List2
Button1 btn_createlist1 Create list1
Button2 btn_createlist2 Create list2
Button3 btn_exit Exit
Button4 btn_movel1tol2 Move list1 to list2
Button5 btn_movel2tol1 Move list2 to list1
Radiobutton1 rdo_movesingle Move one element
Radiobutton2 rdo_movemultiple Move Multiple elements
Button6 btn_moveelements Move Elements
List1 lst_one
List2 lst_two
Button7 btn_refresh Refresh

24
Visual Programming Lab Manual (MCA 407)
BAPATLA ENGINEERING COLLEGE: BAPATLA
Department of MCA

8. Develop a Visual Basic application to implement the calculator operations


by using control array.
Dim el, s, a, b, s1, a1 As String
Dim x, y, r, sflag, flag, z As Integer
Dim z1 As Double
Dim t As Integer

Public Function perform(ByVal el As Integer)


If Not txt_res.Text = "invalid option" Then
a1 = a
If flag >= 1 Then
flag = 0
Text1.Text = ""
End If
If s = Nan Then
a = a & el
Text1.Text = a
Else
b = b & el
Text1.Text = b
End If
End If
End Function

Private Sub btn_1_Click() /// code for button1


el = "1"
perform el
End Sub

Private Sub btn_10_Click() /// code for button0


el = "0"
perform el
End Sub

Private Sub btn_add_Click() /// code for button+


s = "+"
a = txt_res.Text
End Sub

Private Sub btn_sub_Click() /// code for button-


s = "-"
a = txt_res.Text
End Sub

Private Sub btn_mul_Click() /// code for button *


s = "*"

25
Visual Programming Lab Manual (MCA 407)
BAPATLA ENGINEERING COLLEGE: BAPATLA
Department of MCA
a = txt_res.Text
End Sub

Private Sub btn_div_Click() /// code for button /


s = "/"
a = txt_res.Text
End Sub

Private Sub btn_percentage_Click() /// code for button %


x = CInt(a)
y = CInt(b)
r = (x * y) / 100
a1 = r
txt_res.Text = r
b = ""
End Sub

Private Sub btn_equal_Click() /// code for =


If Not Text1.Text = "invalid option" Then
flag = flag + 1
If s = Nan And b = Nan Then
b = b1
s = s1
End If
End If
x = CDbl(a)
y = CDbl(b)
b1 = b
s1 = s
Select Case s
Case "+"
r=x+y
a1 = r
txt_res.Text = r
Case "-"
r=x-y
a1 = r
txt_res.Text = r
Case "/"
r=x/y
a1 = r
txt_res.Text = r
Case "*"
r=x*y
a1 = r
txt_res.Text = r
Case "^"
r=x^y

26
Visual Programming Lab Manual (MCA 407)
BAPATLA ENGINEERING COLLEGE: BAPATLA
Department of MCA
a1 = r
txt_res.Text = r
Case Else
Txt_res.Text = "unable"
End Select
b = Nan
s = Nan
temp = r

End Sub

Private Sub btn_invert_Click() /// code for button1 1/x


txt_res.Text = 1 /tzt_res.Text
End Sub

Private Sub btn_sqrt_Click() /// code for sqrt


z = CInt(txt_res.Text)
txt_res.Text = Sqr(z)
End Sub

Private Sub btn_2_Click() /// code for button2


el = "2"
perform el
End Sub

Private Sub btn_backspace_Click() /// code for button1 backspace


Dim t As Integer
z = CInt(txt_res.Text)
t = Int(z / 10)
If t >= 0 Then
txt_res.Text = t
Else
txt_res.Text = 0
End If
End Sub

Private Sub btn_clear_Click() /// code for button clear


txt_res.Text = ""
a = Nan
b = Nan
s = Nan
End Sub

Private Sub btn_ms_Click() /// code for button MS


a = CInt(txt_res.Text)
't = a
End Sub

27
Visual Programming Lab Manual (MCA 407)
BAPATLA ENGINEERING COLLEGE: BAPATLA
Department of MCA
Private Sub btn_mc_Click() /// code for button MC
t=0
MsgBox ("memory is cleared")
End Sub

Private Sub btn_m+_Click() /// code for button M+


t = txt_res.Text
End Sub

Private Sub btn_mr_Click() /// code for button MR


b = CInt(t)
End Sub

Private Sub btn_mr+_Click() /// code for button Mr+


txt_res.Text = temp
End Sub

Private Sub btn_pow_Click() /// code for button ^


s = "^"
a = txt_res.Text
End Sub

Private Sub btn_3_Click() /// code for button 3


el = "3"
perform el
End Sub

Private Sub btn_4_Click() /// code for button 4


el = "4"
perform el
End Sub

Private Sub btn_5_Click() /// code for button 5


el = "5"
perform el
End Sub

Private Sub btn_6_Click() /// code for button6


el = "6"
perform el
End Sub

Private Sub btn_7_Click() /// code for button7


el = "7"
perform el
End Sub

Private Sub btn_8_Click() /// code for button8

28
Visual Programming Lab Manual (MCA 407)
BAPATLA ENGINEERING COLLEGE: BAPATLA
Department of MCA
el = "8"
perform el
End Sub

Private Sub btn_9_Click() /// code for button9


el = "9"
perform el
End Sub

Private Sub Form_Load() /// code for form load


s = Nan
End Sub

Design:
Title: Application to implement calculator
Controls:

Control Name Caption


Textbox1 txt_res
Button1 btn_1 1
Button2 btn_2 2
Button3 btn_3 3
Button4 btn_4 4
Button5 btn_5 5
Button6 btn_4 6
Button7 btn_4 7
Button8 btn_4 8
Button9 btn_4 9
Button10 btn_4 0
Button11 btn_add +
Button12 btn_sub -
Button13 btn_mul *
Button14 btn_div /
Button15 btn_percent %
Button16 btn_equal =
Button17 btn_invert 1/x
Button18 btn_sqrt sqrt
Button19 btn_backspace Backspace
Button20 btn_clear Clear
Button21 btn_ms MS
Button22 btn_mc MC
Button23 btn_m+ M+
Button24 btn_mr Mr
Button25 btn_mr+ Mr+
Button26 btn_pow ^

29
Visual Programming Lab Manual (MCA 407)
BAPATLA ENGINEERING COLLEGE: BAPATLA
Department of MCA

30
Visual Programming Lab Manual (MCA 407)
BAPATLA ENGINEERING COLLEGE: BAPATLA
Department of MCA

9. Develop a visula basic application to implement traffic signal operations


by suing the following conditions.
i. Three traffic signal named RED,GREEN and YELLOW.
ii. Signal flow should be RED YELLOWGREEN.
iii. Time out for Red signal is 10, Green signal is 10 and Yellow
Signal is 5.
iv. Always Yellow signal follows Red and Green.
v. Red and Green signals will not appear one by one.
Private Sub Form_Load()
AutoRedraw = True
DrawWidth = 1
FillStyle = 2
ScaleMode = 1
Dim cout As Integer
lbl_stop.Visible = False
lbl_stop.Visible = False
lbl_go.Visible = False
lbl_go.Visible = False

'&&&&&&&&&&&&& TL LINE &&&&&&&&&&&&&&&&&

Line (0, 4212)-(4742, 4212)


Line (4742, 0)-(4742, 4212)

'TM
Line (8677, 0)-(8677, 3000), &HFF&
Line (8677, 3000)-(8850, 2500), &HFF&
Line (8677, 3000)-(8530, 2500), &HFF&

'&&&&&&&&&&&&&& TR LINE &&&&&&&&&&&&&&&&


Line (14612, 0)-(14612, 4212)
Line (14612, 4212)-(19400, 4212)

'&&&&&&&&&&&&&& BL LINE &&&&&&&&&&&&&&&&

Line (0, 10000)-(4742, 10000)


Line (4742, 10000)-(4742, 14500)

'RM
Line (13900, 6606)-(16400, 6606), &HC000&
Line (13900, 6606)-(14200, 6753), &HC000&
Line (13900, 6606)-(14200, 6433), &HC000&

'BM
Line (8677, 9500)-(8677, 12800), &HFF&
Line (8677, 12800)-(8850, 12500), &HFF&
31
Visual Programming Lab Manual (MCA 407)
BAPATLA ENGINEERING COLLEGE: BAPATLA
Department of MCA
Line (8677, 12800)-(8530, 12500), &HFF&

'&&&&&&&&&&& BR LINE &&&&&&&&&&&&&&&&

Line (14612, 10000)-(19400, 10000)


Line (14612, 10000)-(14612, 14800)
'Line (7677, )-(7677, 10800)

'LM
Line (700, 6606)-(4000, 6606), &HC000&
Line (700, 6606)-(900, 6753), &HC000&
Line (700, 6606)-(900, 6433), &HC000&
End Sub

Private Sub Timer1_Timer()


If lbl_stop.Visible = True Then
If lbl_stop.ForeColor = &HFF& Then
lbl_stop.ForeColor = &HFFFF&
lbl_stop.ForeColor = &HFFFF&
'TM
Line (8677, 0)-(8677, 3000), &HFFFF&
Line (8677, 3000)-(8850, 2500), &HFFFF&
Line (8677, 3000)-(8530, 2500), &HFFFF&

'BM
Line (8677, 9500)-(8677, 12800), &HFFFF&
Line (8677, 12800)-(8850, 12500), &HFFFF&
Line (8677, 12800)-(8530, 12500), &HFFFF&
End If
End If

'&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
If lbl_stop.Visible = True Then
If lbl_stop.ForeColor = &HFF& Then
lbl_stop.ForeColor = &HFFFF&
lbl_stop.ForeColor = &HFFFF&
'RM
Line (13900, 6606)-(16400, 6606), &HFFFF&
Line (13900, 6606)-(14200, 6753), &HFFFF&
Line (13900, 6606)-(14200, 6433), &HFFFF&
Line (700, 6606)-(4000, 6606), &HFFFF&
Line (700, 6606)-(900, 6753), &HFFFF&
Line (700, 6606)-(900, 6433), &HFFFF&
End If
End If
End Sub

32
Visual Programming Lab Manual (MCA 407)
BAPATLA ENGINEERING COLLEGE: BAPATLA
Department of MCA
Private Sub Timer2_Timer()
Timer1.Interval = 5000
If lbl_stop.Visible = True Then
lbl_stop.Visible = False
lbl_go.Visible = True
'TM
Line (8677, 0)-(8677, 3000), &HC000&
Line (8677, 3000)-(8850, 2500), &HC000&
Line (8677, 3000)-(8530, 2500), &HC000&
Else
lbl_stop.Visible = True
lbl_stop.ForeColor = &HFF&
lbl_stop.ForeColor = &HFF&
lbl_go.Visible = False
'TM
Line (8677, 0)-(8677, 3000), &HFF&
Line (8677, 3000)-(8850, 2500), &HFF&
Line (8677, 3000)-(8530, 2500), &HFF&
End If
If lbl_go.Visible = True Then
lbl_go.Visible = False
lbl_stop.Visible = True
lbl_stop.ForeColor = &HFF&
lbl_stop.ForeColor = &HFF&
Line (700, 6606)-(4000, 6606), &HFF&
Line (700, 6606)-(900, 6753), &HFF&
Line (700, 6606)-(900, 6433), &HFF&
Else
lbl_go.Visible = True
lbl_stop.Visible = False
Line (700, 6606)-(4000, 6606), &HC000&
Line (700, 6606)-(900, 6753), &HC000&
Line (700, 6606)-(900, 6433), &HC000&
End If
If lbl_go.Visible = True Then
lbl_go.Visible = False
lbl_stop.Visible = True
Line (13900, 6606)-(16400, 6606), &HFF&
Line (13900, 6606)-(14200, 6753), &HFF&
Line (13900, 6606)-(14200, 6433), &HFF&
Else
lbl_go.Visible = True
lbl_stop.Visible = False
Line (13900, 6606)-(16400, 6606), &HC000&
Line (13900, 6606)-(14200, 6753), &HC000&
Line (13900, 6606)-(14200, 6433), &HC000&
End If
If lbl_stop.Visible = True Then

33
Visual Programming Lab Manual (MCA 407)
BAPATLA ENGINEERING COLLEGE: BAPATLA
Department of MCA
lbl_stop.Visible = False
lbl_go.Visible = True
'BM
Line (8677, 9500)-(8677, 12800), &HC000&
Line (8677, 12800)-(8850, 12500), &HC000&
Line (8677, 12800)-(8530, 12500), &HC000&
Else
lbl_stop.Visible = True
lbl_go.Visible = False
'BM
Line (8677, 9500)-(8677, 12800), &HFF&
Line (8677, 12800)-(8850, 12500), &HFF&
Line (8677, 12800)-(8530, 12500), &HFF&
End If
End Sub

Design:
Title: Application to implement Traffic Signals.
Controls:

Control Name Caption


Label1 lbl_stop Stop
Label2 lbl_stop Stop
Lbl_go lbl_stop Stop
Label4 lbl_stop Stop
Label5 lbl_go Go
Label6 lbl_go Go
Label7 lbl_go Go
Label8 lbl_go Go
Timer Timer1
Timer Timer2

34
Visual Programming Lab Manual (MCA 407)
BAPATLA ENGINEERING COLLEGE: BAPATLA
Department of MCA

35
Visual Programming Lab Manual (MCA 407)
BAPATLA ENGINEERING COLLEGE: BAPATLA
Department of MCA

10.Develop a visual basic application to sort the given list of numbers.(dont


use Sort oprtion of list control).
First create node.cls by using class module.
1. Open the project .Right click on form .
2. Click on Add and select class Module.
3. In the properties change the class name as node. Then node.cls file is created and write
following code.

Public key as Integer


Public pnext as node

Write Form code


Dim head1 As node
Dim n As Integer

Private Sub btn_createlist_Click() //// Create list code


Dim curr As node //// 'object pointer to current pos in
Dim i As Integer ////'list used in For loop
lbl_text2.Caption = "Before Sorting"
'CREATE LIST
Set head1 = New node //// 'object pointer to new node
head1.key = 0 ////'dummy head
Set curr = head1 ////'keep head pointer here
For i = 1 To n ////'iterate n times to fill list
Set curr.pnext = New node ////'insert new node after current
Set curr = curr.pnext ////'set current one = new node
curr.key = InputBox("Enter the Elements ") //// 'set new node key value
Next i
Set curr.pnext = New node /////'dummy tail
Set curr = curr.pnext ///// 'move current to dummy tail
curr.key = 0 /////'set value of dummy tail
Set curr.pnext = curr /////'points to itself to identify end

'&&&&&&&&&&&&& ADDING TO LISTBOX &&&&&&&&&&&&&&&

Dim temp As node


Dim k As Integer
k=0
Set temp = head1.pnext
While Not temp.pnext Is temp
k=k+1
lst_list1.AddItem ("pos-" & k & "----" & temp.key)
Set temp = temp.pnext
Wend
End Sub

36
Visual Programming Lab Manual (MCA 407)
BAPATLA ENGINEERING COLLEGE: BAPATLA
Department of MCA
Private Sub btn_sortlist_Click() /// sorting code
Dim temp1 As node
Dim temp2 As node
Dim curr As node
Dim i As Integer
Dim j As Integer

Set temp1 = head1


Set curr = head1
Set temp2 = head1.pnext
'&&&&&&&&&&&&&&& SORTING ELEMENTS &&&&&&&&&&&&&&&&&
For i = 1 To n
While Not temp2.pnext Is temp2.pnext.pnext
If temp2.key < temp2.pnext.key Then
Set temp2 = temp2.pnext
Set temp1 = temp1.pnext
Set curr = curr.pnext
Else
Set temp1.pnext = temp2.pnext
Set temp2.pnext = temp2.pnext.pnext
Set temp1.pnext.pnext = temp2
Set temp1 = temp1.pnext
Set curr = curr.pnext
End If
lst_list1.Clear
lbl_text2.Caption = "After Sorting"
Dim temp As node
Dim k As Integer
k=0
Set temp = head1.pnext
While Not temp.pnext Is temp
k=k+1
lst_list1.AddItem ("pos-" & k & "----" & temp.key)
Set temp = temp.pnext
Wend
Wend
Set temp1 = head1
Set curr = head1
Set temp2 = head1.pnext
Next i
End Sub

Private Sub btn_exit_Click() //// Exit code


End
End Sub

Private Sub btn_readsize_Click() //// Read size


n = txt_size.Text

37
Visual Programming Lab Manual (MCA 407)
BAPATLA ENGINEERING COLLEGE: BAPATLA
Department of MCA
lst_list1.Visible = True
btn_createlist.Visible = True
btn_sortlist.Visible = True
btn_exit.Visible = True
btn_readsize.Visible = False
lbl_size.Visible = False
txt_size.Visible = False
lbl_text2.Visible = True
End Sub

Private Sub Form_Load() //// Form load


lbl_size.Visible = True
btn_readsize.Visible = True
txt_size.Visible = True
lst_list1.Visible = False
btn_createlist.Visible = False
btn_sortlist.Visible = False
btn_exit.Visible = False
lbl_text2.Visible = False
End Sub

Design:
Title: Application to sort the given list of numbers.
Controls:

Control Name Caption


Label1 lbl_size Enter size
Label2 lbl_text2 Before Sorting
Button1 btn_readsize Read Size
Button2 btn_createlist Create List
Button3 btn_sortlist Sort List
Button4 btn_exit Exit
List1 lst_list1
Textbox1 txt_size

38
Visual Programming Lab Manual (MCA 407)
BAPATLA ENGINEERING COLLEGE: BAPATLA
Department of MCA

39
Visual Programming Lab Manual (MCA 407)
BAPATLA ENGINEERING COLLEGE: BAPATLA
Department of MCA

11.Develop a visual basic application to read and print user data by using
Input Box and Message Box.
Dim ename As String
Dim sal As Double
Dim empno As Integer
Dim dept As String
Dim designation As String

Private Sub btn_read_Click() ////code for reading data


ename = InputBox("enter name of the employee")
sal = InputBox("enter sal of the employee")
empno = InputBox("enter empno of the employee")
dept = InputBox("enter department name of the employee")
designation = InputBox("enter designation of the employee")
btn_display.Enabled = True
btn_exit.Visible = True
btn_read.Enabled = False
End Sub

Private Sub btn_display_Click() //// code for displaying data


MsgBox ("Name of the employee " & ename)
MsgBox ("Salary of the employee " & sal)
MsgBox ("Empno of the employee " & empno)
MsgBox ("Department name of the employee " & dept)
MsgBox ("Designation of the employee " & designation)
Btn_read.Enabled = True
Btn_display.Enabled = False
End Sub

Private Sub btn_exit_Click() //// code for exit


End
End Sub

Private Sub Form_Load() //// code for form load


btn_display.Enabled = False
btn_exit.Visible = False
End Sub

Design:
Title: Application to read and print user data by using Input Box and Message
Box.
Controls:

40
Visual Programming Lab Manual (MCA 407)
BAPATLA ENGINEERING COLLEGE: BAPATLA
Department of MCA
Control Name Caption
Button1 btn_read Read user Details
Button2 btn_display Display User Details
Button3 btn_exit Exit

41
Visual Programming Lab Manual (MCA 407)
BAPATLA ENGINEERING COLLEGE: BAPATLA
Department of MCA

12.Develop a visual basic application to implement arthimetic operations.


i. Project consists of four forms.
ii. Form1 is used to read the numbers and read the operations.
iii. Operations are partitioned into two categories like integer
arthimetic and real arthimentic should follow the
normalization principles.
iv. Choose the appropriate arthimetic operation under Integer
and Real arthimetic under Addition,Subtraction,
Multiplication and Division.
v. Form2 is for doing Integer Arthimetic and Form3 is for doing
Real arthimetic.
vi. Form4 is for display the result.

Private Sub btn_read_Click()


txt_num1.Visible = True
txt_num2.Visible = True
lbl_num1.Visible = True
lbl_num2.Visible = True
btn_read.Visible = False
btn_select.Visible = True
End Sub

Private Sub btn_select_Click()


If txt_num1.Text = "" And txt_num2.Text = "" Then
MsgBox ("Enter Numbers")
txt_num1.SetFocus
Else
lbl_option.Visible = True
Frame1.Visible = True
btn_select.Visible = False
End If
End Sub

Private Sub btn_continue_Click()


txt_num1.Text = ""
txt_num2.Text = ""
txt_num1.SetFocus
btn_read.Visible = True
Frame1.Visible = False
btn_continue.Visible = False
btn_exit.Visible = False
lbl_option.Visible = False
End Sub
42
Visual Programming Lab Manual (MCA 407)
BAPATLA ENGINEERING COLLEGE: BAPATLA
Department of MCA

Private Sub btn_exit_Click()


End
End Sub

Private Sub Form_Load()


btn_read.Visible = True
Frame1.Visible = False
txt_num1.Visible = False
txt_num2.Visible = False
lbl_num1.Visible = False
lbl_num2.Visible = False
lbl_option.Visible = False
btn_select.Visible = False
btn_continue.Visible = False
btn_exit.Visible = False
End Sub

Private Sub rdo_int_Click()


Form1.Hide
Form2.Show
Form3.Hide
End Sub

Private Sub rdo_real_Click()


Form1.Hide
Form3.Show
Form2.Hide
End Sub

Form2:
Dim x As Integer
Dim a As Integer
Dim b As Integer
Dim res As Integer

Private Sub btn_calculate_Click()


a = CInt(Form1.txt_num1.Text)
b = CInt(Form1.txt_num2.Text)
Form2.Hide
Form4.Show
Select Case x
Case 1:
res = a + b
Form4.lbl_res.ForeColor = &HC000&
Form4.lbl_res.Caption = "Addition of " & a & "and " & b & " is " & res

43
Visual Programming Lab Manual (MCA 407)
BAPATLA ENGINEERING COLLEGE: BAPATLA
Department of MCA
Case 2:
res = a - b
Form4. lbl_res.ForeColor = &HC000&
Form4. lbl_res.Caption = "Integer Subtraction of " & a & "and " & b & "
is " & res
Case 3:
res = a * b
Form4. lbl_res.ForeColor = &HC000&
Form4. lbl_res.Caption = "Integer Multiplication of " & a & "and " & b &
" is " & res
Case 4:
res = a / b
Form4. lbl_res.ForeColor = &HC000&
Form4. lbl_res.Caption = "Integer Division of " & a & "and " & b & " is "
& res
End Select
End Sub

Private Sub btn_exit_Click()


End
End Sub

Private Sub btn_back_Click()


Form1.rdo_int.Value = False
Form1.rdo_real.Value = False
Form2.rdo_add.Value = False
Form2.rdo_sub.Value = False
Form2.rdo_mul.Value = False
Form2.rdo_div.Value = False
Form3.rdo_radd.Value = False
Form3.rdo_rsub.Value = False
Form3.rdo_rmul.Value = False
Form3.rdo_rdiv.Value = False
Form2.Hide
Form1.Show
End Sub

Private Sub Form_Load()


rdo_add.Value = False
rdo_sub.Value = False
rdo_mul.Value = False
rdo_div.Value = False
End Sub

Private Sub rdo_sub_Click()


x=2
End Sub

44
Visual Programming Lab Manual (MCA 407)
BAPATLA ENGINEERING COLLEGE: BAPATLA
Department of MCA
Private Subrdo_add_Click()
x=1
End Sub

Private Sub rdo_div_Click()


x=4
End Sub

Private Sub rdo_mul_Click()


x=3
End Sub

Form3:
Dim x As Integer
Dim a As Single
Dim b As Single
Dim res As Single
Private Sub btn_calculate_Click()
a = CDbl(Form1.txt_num1.Text)
b = CDbl(Form1.txt_num2.Text)
Form3.Hide
Form4.Show
Select Case x
Case 1:
res = a + b
Form4. lbl_res.ForeColor = &HC000&
Form4. lbl_res.Caption = " Real Addition of " & a & "and " & b & " is " & res
Case 2:
res = a - b
Form4. lbl_res.ForeColor = &HC000&
Form4. lbl_res.Caption = "Real Subtraction of " & a & "and " & b & " is " & res
Case 3:
res = a * b
Form4. lbl_res.ForeColor = &HC000&
Form4. lbl_res .Caption = "Real Multiplication of " & a & "and " & b & " is " &
res
Case 4:
res = a / b
Form4. lbl_res.ForeColor = &HC000&
Form4. lbl_res.Caption = "Real Division of " & a & "and " & b & " is " & res
End Select
End Sub

Private Sub btn_exit_Click()


End
End Sub

45
Visual Programming Lab Manual (MCA 407)
BAPATLA ENGINEERING COLLEGE: BAPATLA
Department of MCA

Private Sub btn_back_Click()


Form1.rdo_int.Value = False
Form1.rdo_real.Value = False
Form2.rdo_add.Value = False
Form2.rdo_sub.Value = False
Form2.rdo_mul.Value = False
Form2.rdo_div.Value = False
Form3.rdo_radd.Value = False
Form3.rdo_rsub.Value = False
Form3.rdo_rmul.Value = False
Form3.rdo_rdiv.Value = False
Form1.Show
Form3.Hide
End Sub

Private Sub Form_Load()


rdo_radd.Value = False
rdo_rsub.Value = False
rdo_rmul.Value = False
rdo_rdiv.Value = False
End Sub

Private Subrdo_rdiv_Click()
x=4
End Sub

Private Sub rdo_radd_Click()


x=1
End Sub

Private Sub rdo_rsub_Click()


x=2
End Sub

Private Sub rdo_rmul_Click()


x=3
End Sub

Form4:
Private Sub btn_back_Click()
Form1.rdo_int.Value = False
Form1.rdo_real.Value = False
Form2.rdo_add.Value = False
Form2.rdo_sub.Value = False
Form2.rdo_mul.Value = False

46
Visual Programming Lab Manual (MCA 407)
BAPATLA ENGINEERING COLLEGE: BAPATLA
Department of MCA
Form2.rdo_div.Value = False
Form3.rdo_radd.Value = False
Form3.rdo_rsub.Value = False
Form3.rdo_rmul.Value = False
Form3.rdo_rdiv.Value = False
Form1.Show
Form4.Hide
Form1.btn_continue.Visible = True
Form1.btn_exit.Visible = True
End Sub

Private Sub btn_exit_Click()


End
End Sub

Design:
Title: Application to implement arthimetic operations.
Controls:
Form1:

Control Name Caption


Button1 btn_read Read Numbers
Button2 btn_select Select Operations
Button3 btn_continue Continue
Button4 btn_exit Exit
TextBox1 txt_num1
TextBox2 txt_num2
Label1 lbl_num1 Enter First Number
Label2 lbl_num2 Enter Second Number
Label3 lbl_option Select any Option
Radio button1 rdo_int Integer Arthimetic
Radio Button2 rdo_real Real Arthimetic

47
Visual Programming Lab Manual (MCA 407)
BAPATLA ENGINEERING COLLEGE: BAPATLA
Department of MCA

Form2:

Control Name Caption


Button1 btn_calculate Calculate
Button2 btn_back Back
Button3 btn_exit Exit
Radio Button1 rdo_add Integer Addition
Radio Button2 rdo_sub Integer Subtraction
Radio Button3 rdo_mul Integer Multiplication
Radio Button4 rdo_div Integer Division
Label1 lbl_select Select any option for integer
Arthimetic

48
Visual Programming Lab Manual (MCA 407)
BAPATLA ENGINEERING COLLEGE: BAPATLA
Department of MCA

Form3:

Control Name Caption


Button1 btn_calculate Calculate
Button2 btn_back Back
Button3 btn_exit Exit
Radio Button1 rdo_radd Real Addition
Radio Button2 rdo_rsub Real Subtraction
Radio Button3 rdo_rmul Real Multiplication
Radio Button4 rdo_rdiv Real Division
Label1 lbl_select Select any option for real
Arthimetic

Form4:

Control Name Caption


Button1 btn_back Back
Button2 btn_exit Exit
Label1 lbl_res

49
Visual Programming Lab Manual (MCA 407)
BAPATLA ENGINEERING COLLEGE: BAPATLA
Department of MCA

13.Develop a Visual Basic Application to display the profile of a valid user.


Conditions:
i. Check the user with hid user name and password.
ii. Display the profile of a user (Note: profile of the user will be any of READ ,
WRITE and READ AND WRITE.

Database connection steps:


1. Go to maim menu and click on project menu item.
2. A drop down menu will appear.Select references submenu item.
3. A reference dialog box will appear.
4. In that all levels of all available references are diaplayed in the listbox
with check buttons.
5. Check the following references.
1. Microsoft Remote dataobject 2.0
2. Microsoft Remotedataservices 2.7 library.
3. Microsoft Remotedataservices server 2.7
library.
6. Click ok button to close the references dialog box.
Creating a DSN:
1. Move to control panel and double click on administrative tools then double
click on data Sources.
2. The ODBC data source administrative screen is displayed. Click on System
DSN.
3. Click on ADD button.That create new data source dialog box will
appear.Select Microsoft ODBC for Oracle from the list and click on finish
button.
4. The ODBC for Oracle dialogbox will appear for Data source name . You
need to enter the name of the datasource you need to create.Set the
authentication fileds as follows:
Username:scott
Password: tiger
Service name:oracle.
5. Click on finsibtton and close the ODBC dialogbox.
Code:

Dim conn As rdoConnection


Dim s As String
Dim rs As rdoResultset
Dim env As rdoEnvironment

Private Sub btn_accessrights_Click() //// code for getaccess rights


s = "select * from validuser where username= '" & txt_user.Text & "' "
Set rs = conn.OpenResultset(s, rdOpenDynamic, rdConcurRowVer)
If rs.RowCount <> 0 Then
If rs("password") = Trim(txt_password.Text) Then
txt_access.Text = rs("accessrights")

50
Visual Programming Lab Manual (MCA 407)
BAPATLA ENGINEERING COLLEGE: BAPATLA
Department of MCA
Else
MsgBox ("Not a valid user")
txt_user.Text = ""
txt_password.Text = ""
txt_access.Text = ""
txt_user.SetFocus
End If
Else
MsgBox ("Not a valid user")
txt_user.Text = ""
txt_password.Text = ""
txt_access.Text = ""
txt_user.SetFocus
End If
End Sub
Private Sub btn_nextuser_Click() //// code for next user
rs.Close
txt_user.Text = ""
txt_password.Text = ""
txt_access.Text = ""
txt_user.SetFocus
End Sub
Private Sub Form_Load() /// code for form load
Set env = rdoEnvironments(0)
env.CursorDriver = rdUseOdbc
Set conn = env.OpenConnection(sss, rdodriverprompt, False, "DSN=sss;UID=scott;PWD=tiger;")
End Sub
Private Sub btn_exit _Click()
End
End Sub

Design
Title: Application to display the profile of a valid user

Control Name Caption


Button1 btn_accesrights Get Access Rights
Button2 btn_nextuser Next User
Label1 lbl_user User Name
Label2 lbl_password Password
Label3 lbl_access Access Rights
Button3 btn_exit Exit
Textbox1 txt_user
Textbox2 txt_password
Textbox3 txt_access

51
Visual Programming Lab Manual (MCA 407)
BAPATLA ENGINEERING COLLEGE: BAPATLA
Department of MCA

52
Visual Programming Lab Manual (MCA 407)
BAPATLA ENGINEERING COLLEGE: BAPATLA
Department of MCA
14. Develop a visual basic application to read the details of the candiadate using the following
conditions.
i. Read the Name,Father Name,Address,Qualification and respective Percentage and
experience if any.
ii. Candidate may choose any two os types (MAX)
iii. Candiadate may choose any three database (MAX)
iv. Candidate may choose any Five programming languages (MAX)
(Note: No control in the Form will be NULL)

Database connection steps:


1. Go to maim menu and click on project menu item.
2. A drop down menu will appear.Select references submenu item.
3. A reference dialog box will appear.
4. In that all levels of all available references are diaplayed in the listbox
with check buttons.
5. Check the following references.
1. Microsoft Remote dataobject 2.0
2. Microsoft Remotedataservices 2.7 library.
3. Microsoft Remotedataservices server 2.7
library.
6. Click ok button to close the references dialog box.
Creating a DSN:
1. Move to control panel and double click on administrative tools then double
click on data Sources.
2. The ODBC data source administrative screen is displayed. Click on System
DSN.
3. Click on ADD button.That create new data source dialog box will
appear.Select Microsoft ODBC for Oracle from the list and click on finish
button.
4. The ODBC for Oracle dialogbox will appear for Data source name . You
need to enter the name of the datasource you need to create.Set the
authentication fileds as follows:
Username:scott
Password: tiger
Service name:oracle.
5. Click on finsibtton and close the ODBC dialogbox.
Code:
Dim oscount As Integer
Dim dbcount As Integer
Dim langcount As Integer
Dim env As rdoEnvironment
Dim conn As rdoConnection
Dim rs As rdoResultset
Dim s As String
Dim dc1 As Integer
Dim pl1 As Integer
Dim os1 As Integer

53
Visual Programming Lab Manual (MCA 407)
BAPATLA ENGINEERING COLLEGE: BAPATLA
Department of MCA
Private Sub btn_continue1_Click()
Frame1.Visible = True
End Sub

Private Sub btn_continue_Click()


Frame1.Visible = True
btn_exit.Visible = False
btn_continue.Visible = False
txt_name.Text = ""
txt_fname.Text = ""
txt_address.Text = ""
chk_ssc.value = 0
chk_inter.value = 0
chk_degree.value = 0
chk_pg.value = 0
chk_exp.value = 0
txt_exp.Text = ""
txt_ssc.Text = ""
txt_inter.Text = ""
txt_degree.Text = ""
txt_pg.Text = ""
chk_windows.value = 0
chk_solaris.value = 0
chk_unix1.value = 0
chk_dbms.value = 0
chk_rdbms.value = 0
chk_sql.value = 0
chk_msaccess.value = 0
chk_c.value = 0
chk_cplus.value = 0
chk_java.value = 0
chk_dotnet.value = 0
chk_vb.value = 0
chk_html.value = 0
chk_unix.value = 0
oscount = 0
dbcount = 0
langcount = 0
dc1 = 0
pl1 = 0
os1 = 0
End Sub
Private Sub btn_database_Click()
Frame3.Visible = False
Frame4.Visible = True
btn_lang.Enabled = False
MsgBox ("select five options")
End Sub

54
Visual Programming Lab Manual (MCA 407)
BAPATLA ENGINEERING COLLEGE: BAPATLA
Department of MCA

Private Sub btn_exit_Click()


End
End Sub

Private Sub btn_lang_Click()


Frame1.Visible = False
Frame2.Visible = False
Frame3.Visible = False
Frame4.Visible = False
btn_exit.Visible = True
btn_continue.Visible = True

MsgBox ("Thank you")


s = "select * from information1"
Set rs = conn.OpenResultset(s, rdOpenDynamic, rdConcurRowVer)
If rs.EditMode <> True Then
rs.AddNew
rs("name") = txt_name.Text
rs("fname") = txt_fname.Text
rs("address") = txt_address.Text

If chk_ssc.value = 1 Then
rs("ssc") = txt_ssc.Text
End If

If chk_inter.value = 1 Then
rs("Inter") = txt_inter.Text
End If

If chk_degree.value = 1 Then
rs("Degree") = txt_degree.Text
End If

If chk_pg.value = 1 Then
rs("Pg") = txt_pg.Text
End If
If chk_exp.value = 1 Then
rs("Exp") = txt_exp.Text
End If

If chk_dbms.value = 1 Then
dc1 = dc1 + 1
assign (chk_dbms.Caption)
End If

If chk_rdbms.value = 1 Then
dc1 = dc1 + 1

55
Visual Programming Lab Manual (MCA 407)
BAPATLA ENGINEERING COLLEGE: BAPATLA
Department of MCA
assign (chk_rdbms.Caption)
End If

If chk_sql.value = 1 Then
dc1 = dc1 + 1
assign (chk_sql.Caption)
End If

If chk_msaccess.value = 1 Then
dc1 = dc1 + 1
assign (chk_msaccess.Caption)
End If

If chk_windows.value = 1 Then
os1 = os1 + 1
assign1 (chk_windows.Caption)
End If

If chk_solaris.value = 1 Then
os1 = os1 + 1
assign1 (chk_solaris.Caption)
End If

If chk_unix1.value = 1 Then
os1 = os1 + 1
assign1 (chk_unix1.Caption)
End If

If chk_c.value = 1 Then
pl1 = pl1 + 1
assign2 (chk_c.Caption)
End If

If chk_cplus.value = 1 Then
pl1 = pl1 + 1
assign2 (chk_cplus.Caption)
End If

If chk_java.value = 1 Then
pl1 = pl1 + 1
assign2 (chk_java.Caption)
End If

If chk_dotnet.value = 1 Then
pl1 = pl1 + 1
assign2 (chk_dotnet.Caption)
End If

56
Visual Programming Lab Manual (MCA 407)
BAPATLA ENGINEERING COLLEGE: BAPATLA
Department of MCA
If chk_vb.value = 1 Then
pl1 = pl1 + 1
assign2 (chk_vb.Caption)
End If

If chk_html.value = 1 Then
pl1 = pl1 + 1
assign2 (chk_html.Caption)
End If

If chk_unix.value = 1 Then
pl1 = pl1 + 1
assign2 (chk_unix.Caption)
End If

rs.Update
MsgBox ("record loaded successfully")
End If
End Sub

Function assign(ByVal s1 As String)


If dc1 = 1 Then
rs("db1") = s1
Else
If dc1 = 2 Then
rs("db2") = s1
Else
rs("db3") = s1
End If
End If
End Function

Function assign1(ByVal s2 As String)


If os1 = 1 Then
rs("os1") = s2
Else
rs("os2") = s2
End If
End Function
Function assign2(ByVal s3 As String)
If pl1 = 1 Then
rs("pl1") = s3
Else
If pl1 = 2 Then
rs("pl2") = s3
Else
If pl1 = 3 Then
rs("pl3") = s3

57
Visual Programming Lab Manual (MCA 407)
BAPATLA ENGINEERING COLLEGE: BAPATLA
Department of MCA
Else
If pl1 = 4 Then
rs("pl4") = s3
Else
rs("pl5") = s3
End If
End If
End If
End If
End Function

Private Sub btn_ok_Click()


Frame1.Visible = False
Frame2.Visible = True
btn_os.Enabled = False
MsgBox ("select two options")
End Sub

Private Sub btn_os_Click()


Frame2.Visible = False
Frame3.Visible = True
btn_database.Enabled = False
MsgBox ("select three options")
End Sub

Private Sub btn_read_Click()


btn_read.Visible = False
lbl_name.Visible = True
lbl_father.Visible = True
lbl_address.Visible = True
lbl_qual.Visible = True
lbl_percent.Visible = True
txt_name.Visible = True
txt_fname.Visible = True
txt_address.Visible = True
chk_ssc.Visible = True
chk_inter.Visible = True
chk_degree.Visible = True
chk_pg.Visible = True
chk_exp.Visible = True
btn_ok.Visible = True
End Sub

Private Sub chk_c_Click()


Dim v As Integer
v = checklang(chk_c.value)
If v = 0 Then
MsgBox v

58
Visual Programming Lab Manual (MCA 407)
BAPATLA ENGINEERING COLLEGE: BAPATLA
Department of MCA
chk_c.value = 0
End If
End Sub

Private Sub chk_cplus_Click()


Dim v As Integer
v = checklang(chk_cplus.value)
If v = 0 Then
MsgBox v
chk_cplus.value = 0
End If
End Sub

Private Sub chk_dbms_Click()


Dim v As Integer
v = checkdb(chk_dbms.value)
If v = 0 Then
MsgBox v
chk_dbms.value = 0
End If
End Sub

Function checkdb(ByVal value As Integer) As Integer


Dim k As Integer
k=1
If value = 1 Then
If dbcount = 3 Then
dbcount = dbcount + 1
MsgBox ("you are already selected")
k=0
Else
dbcount = dbcount + 1
End If
max
End If
If value = 0 Then
dbcount = dbcount - 1
End If
checkdb = k
End Function

Function checklang(ByVal value As Integer) As Integer


Dim k As Integer
k=1
If value = 1 Then
If langcount = 5 Then
langcount = langcount + 1
MsgBox ("you are already selected")

59
Visual Programming Lab Manual (MCA 407)
BAPATLA ENGINEERING COLLEGE: BAPATLA
Department of MCA
k=0
Else
langcount = langcount + 1
End If
max
End If
If value = 0 Then
langcount = langcount - 1
End If
checklang = k
End Function

Function checkos(ByVal value As Integer) As Integer


Dim k As Integer
k=1
If value = 1 Then
If oscount = 2 Then
oscount = oscount + 1
MsgBox ("you are already selected")
k=0
Else
oscount = oscount + 1
End If
max
End If
If value = 0 Then
oscount = oscount - 1
End If
checkos = k
End Function

Private Sub chk_degree_Click()


If chk_degree.value = 1 Then
txt_degree.Visible = True
Else
txt_degree.Visible = False
End If
End Sub

Private Sub chk_dotnet_Click()


Dim v As Integer
v = checklang(chk_dotnet.value)
If v = 0 Then
MsgBox v
chk_dotnet.value = 0
End If
End Sub

60
Visual Programming Lab Manual (MCA 407)
BAPATLA ENGINEERING COLLEGE: BAPATLA
Department of MCA
Private Sub chk_exp_Click()
If chk_exp.value = 1 Then
txt_exp.Visible = True
Else
txt_exp.Visible = False
End If
End Sub

Private Sub chk_html_Click()


Dim v As Integer
v = checklang(chk_html.value)
If v = 0 Then
MsgBox v
chk_html.value = 0
End If
End Sub

Private Sub chk_inter_Click()


If chk_inter.value = 1 Then
txt_inter.Visible = True
Else
txt_inter.Visible = False
End If
End Sub

Private Sub chk_java_Click()


Dim v As Integer
v = checklang(chk_java.value)
If v = 0 Then
MsgBox v
chk_java.value = 0
End If
End Sub

Private Sub chk_msaccess_Click()


Dim v As Integer
v = checkdb(chk_msaccess.value)
If v = 0 Then
MsgBox v
chk_msaccess.value = 0
End If
End Sub

Private Sub chk_pg_Click()


If chk_pg.value = 1 Then
txt_pg.Visible = True
Else
txt_pg.Visible = False

61
Visual Programming Lab Manual (MCA 407)
BAPATLA ENGINEERING COLLEGE: BAPATLA
Department of MCA
End If
End Sub

Private Sub chk_rdbms_Click()


Dim v As Integer
v = checkdb(chk_rdbms.value)
If v = 0 Then
MsgBox v
chk_rdbms.value = 0
End If
End Sub

Private Sub chk_solaris_Click()


Dim v As Integer
v = checkos(chk_solaris.value)
If v = 0 Then
MsgBox v
chk_solaris.value = 0
End If

End Sub

Private Sub chk_sql_Click()


Dim v As Integer
v = checkdb(chk_sql.value)
If v = 0 Then
MsgBox v
chk_sql.value = 0
End If
End Sub

Private Sub chk_ssc_Click()


If chk_ssc.value = 1 Then
txt_ssc.Visible = True
Else
txt_ssc.Visible = False
End If
End Sub

Private Sub chk_unix_Click()


Dim v As Integer
v = checklang(chk_unix.value)
If v = 0 Then
MsgBox v
chk_unix.value = 0
End If
End Sub

62
Visual Programming Lab Manual (MCA 407)
BAPATLA ENGINEERING COLLEGE: BAPATLA
Department of MCA
Private Sub chk_unix1_Click()
Dim v As Integer
v = checkos(chk_unix1.value)
If v = 0 Then
MsgBox v
chk_unix1.value = 0
End If
End Sub

Private Sub chk_vb_Click()


Dim v As Integer
v = checklang(chk_vb.value)
If v = 0 Then
MsgBox v
chk_vb.value = 0
End If
End Sub

Private Sub chk_windows_Click()


Dim v As Integer
v = checkos(chk_windows.value)
If v = 0 Then
MsgBox v
chk_windows.value = 0
End If
End Sub

Private Sub Form_Load()


Set env = rdoEnvironments(0)
env.CursorDriver = rdUseOdbc
Set conn = env.OpenConnection(sss, rdoDriverPrompt, False,
"DSN=sss;UID=scott;PWD=tiger;")
Frame1.Visible = True
Frame2.Visible = False
Frame3.Visible = False
Frame4.Visible = False
btn_read.Visible = True
lbl_name.Visible = False
lbl_father.Visible = False
lbl_address.Visible = False
lbl_qual.Visible = False
lbl_percent.Visible = False
txt_name.Visible = False
txt_fname.Visible = False
txt_address.Visible = False
txt_ssc.Visible = False
txt_inter.Visible = False
txt_degree.Visible = False

63
Visual Programming Lab Manual (MCA 407)
BAPATLA ENGINEERING COLLEGE: BAPATLA
Department of MCA
txt_pg.Visible = False
txt_exp.Visible = False
btn_ok.Visible = False
chk_ssc.Visible = False
chk_inter.Visible = False
chk_degree.Visible = False
chk_pg.Visible = False
chk_exp.Visible = False
btn_exit.Visible = False
btn_continue.Visible = False
End Sub

Private Function max()


If dbcount = 3 Then
btn_database.Enabled = True
End If
If oscount = 2 Then
btn_os.Enabled = True
End If
If langcount = 5 Then
btn_lang.Enabled = True
End If
End Function

Design
Title: Application to display the profile of a valid user
Control

Control Name Caption


Frame1 Frame1
Frame2 Frame2
Frame3 Frame3
Frame4 Frame4
Button1(frame1) btn_read Read Details
Button2(frame1) btn_ok Ok
Button3 btn_exit Exit
Button4 btn_continue Continue
Label1(frame1) lbl_name Name
Label2(frame1) lbl_fname Father Name
Label3(frame1) lbl_address Address
Label4(frame1) lbl_qual Qualification
Label5(frame1) lbl_percentage Percentage
Checkbox1(frame1) chk_ssc SSC
Checkbox2 (frame1) chk_inter Inter
Checkbox3 (frame1) chk_degree Degree

64
Visual Programming Lab Manual (MCA 407)
BAPATLA ENGINEERING COLLEGE: BAPATLA
Department of MCA
Checkbox4 (frame1) chk_pg Pg
Checkbox5(frame1) chk_exp Experience
Label1(Frame2) lbl_os Select OS
Checkbox1(frame2) chk_windows Windows
Checkbox2(frame2) chk_solarsi Solaris
Checkbox3(frame2) chk_unix Unix
Button1(frame2) btn_os OK
Label1(Frame3) lbl_database Select Database
Checkbox1(frame3) chk_dbms DBMS
Checkbox2(frame3) chk_rdbms RDBMS
Checkbox3(frame3) chk_sql Sql Server
Checkbox4(frame3) chk_msaccess Ms Access
Button1(frame3) btn_database OK
Label1(Frame4) lbl_lang Select Languages
Checkbox1(frame4) chk_c C
Checkbox2(frame4) chk_cplus C++
Checkbox3(frame4) chk_java Java
Checkbox4(frame4) chk_vb VB
Checkbox5(frame4) chk_dotnet Dot net
Checkbox6(frame4) chk_html Html
Checkbox7(frame4) chk_unix1l Unix
Button1(frame4) btn_lang Ok

65
Visual Programming Lab Manual (MCA 407)
BAPATLA ENGINEERING COLLEGE: BAPATLA
Department of MCA

66
Visual Programming Lab Manual (MCA 407)
BAPATLA ENGINEERING COLLEGE: BAPATLA
Department of MCA
15. Develop a visual basic application to make survey on different age groups.
Example:
Age groups may be (25-34), (35-44), (45-54) and >=55 and display the no ofpeople on a
particular age group.

Database connection steps:


1. Go to maim menu and click on project menu item.
2. A drop down menu will appear.Select references submenu item.
3. A reference dialog box will appear.
4. In that all levels of all available references are diaplayed in the listbox
with check buttons.
5. Check the following references.
1. Microsoft Remote dataobject 2.0
2. Microsoft Remotedataservices 2.7 library.
3. Microsoft Remotedataservices server 2.7
library.
6. Click ok button to close the references dialog box.
Creating a DSN:
1. Move to control panel and double click on administrative tools then double
click on data Sources.
2. The ODBC data source administrative screen is displayed. Click on System
DSN.
3. Click on ADD button.That create new data source dialog box will
appear.Select Microsoft ODBC for Oracle from the list and click on finish
button.
4. The ODBC for Oracle dialogbox will appear for Data source name . You
need to enter the name of the datasource you need to create.Set the
authentication fileds as follows:
Username:scott
Password: tiger
Service name:oracle.
5. Click on finsibtton and close the ODBC dialogbox.
Code:

Dim env As rdoEnvironment


Dim cn As rdoConnection
Dim rs1 As rdoResultset
Dim rs2 As rdoResultset
Dim rs3 As rdoResultset
Dim s1, s2, s3 As String
Private Sub btn_check_Click()
btn_check.Visible = False
btn_continue.Visible = True
btn_exit.Visible = True
txt_from.Enabled = False
txt_to.Enabled = False

67
Visual Programming Lab Manual (MCA 407)
BAPATLA ENGINEERING COLLEGE: BAPATLA
Department of MCA
s1 = "create view v1 as select eno as No,ename as Name,round((sysdate-dob)/365) as
Age from employee"
s2 = "select count(*) no from v1 where age between '" & txt_from.Text & " ' and '" &
txt_to.Text & " ' "
s3 = "drop view v1"
Set rs1 = cn.OpenResultset(s1, rdOpenDynamic, rdConcurRowVer)
Set rs2 = cn.OpenResultset(s2, rdOpenDynamic, rdConcurRowVer)
Set rs3 = cn.OpenResultset(s3, rdOpenDynamic, rdConcurRowVer)
txt_result.Text = rs2("No")
'MsgBox " View Dropped "
End Sub

Private Sub btn_continue_Click()


btn_check.Visible = True
btn_continue.Visible = False
btn_exit.Visible = False
txt_from.Enabled = True
txt_to.Enabled = True
txt_from.Text = ""
txt_to.Text = ""
txt_result = ""
End Sub

Private Sub btn_exit_Click()


End
End Sub

Private Sub Form_Load()


btn_continue.Visible = False
Set env = rdoEnvironments(0)
env.CursorDriver = rdUseOdbc
Set cn = env.OpenConnection(sss, rdodriverprompt, False,
"DSN=sss;uid=scott;pwd=tiger;")
End Sub
Design
Title: Application to make survey on different age groups.
Control

Control Name Caption


Button1 btn_check Check
Button2 btn_exit Exit
Button3 btn_continue Continue
Label1 lbl_from From
Label2 lbl_to To
Label3 lbl_enter Enter the range
Label4 lbl_result No of persons in the above

68
Visual Programming Lab Manual (MCA 407)
BAPATLA ENGINEERING COLLEGE: BAPATLA
Department of MCA
group
Textbox1 txt_from
Textbox2 txt_to
Textbox3 txt_result

69
Visual Programming Lab Manual (MCA 407)
BAPATLA ENGINEERING COLLEGE: BAPATLA
Department of MCA
16. Develop a visual basic application to make the following database operations by using ADO.
i. Insert new Employee into the database.
ii. Delete an existing employee from the database.
iii. Update the employee information on the basis of employee number.
iv. Serach an employee details on the basis of department number.

Database connection steps:


1. Go to maim menu and click on project menu item.
2. A drop down menu will appear.Select references submenu item.
3. A reference dialog box will appear.
4. In that all levels of all available references are diaplayed in the listbox
with check buttons.
5. Check the following references.
1. Microsoft Remote dataobject 2.0
2. Microsoft Remotedataservices 2.7 library.
3. Microsoft Remotedataservices server 2.7
library.
6. Click ok button to close the references dialog box.
Creating a DSN:
1. Move to control panel and double click on administrative tools then double
click on data Sources.
2. The ODBC data source administrative screen is displayed. Click on System
DSN.
3. Click on ADD button.That create new data source dialog box will
appear.Select Microsoft ODBC for Oracle from the list and click on finish
button.
4. The ODBC for Oracle dialogbox will appear for Data source name . You
need to enter the name of the datasource you need to create.Set the
authentication fileds as follows:
Username:scott
Password: tiger
Service name:oracle.
5. Click on finsibtton and close the ODBC dialogbox.
Code:

Adding MDI form:


1. Go to Project menu and add MDI form.
2. Right click on mdi form and select menu editor.
3. Give name and caption for each menu item.
4. Go to project properties and set mdi form as start up.

Mdi form code:


Private Sub Close_Click(Index As Integer)
End
End Sub

70
Visual Programming Lab Manual (MCA 407)
BAPATLA ENGINEERING COLLEGE: BAPATLA
Department of MCA
Private Sub Delete_Click(Index As Integer)
Form3.Show
End Sub

Private Sub New_Click(Index As Integer)


Form4.Show
End Sub

Private Sub Search_Click(Index As Integer)


Form1.Show
End Sub
Private Sub Update_Click(Index As Integer)
form2.Show
End Sub

Form1.code (search)

Dim cn1 As New ADODB.Connection


Dim rs1 As New ADODB.Recordset
Dim s1 As String

Private Sub btn_empdetails_Click()


s1 = "select * from emp where no = '" & txt_no.Text & "' "
rs1.Open s1, cn1, adOpenDynamic, adLockPessimistic
Frame2.Visible = True
If rs1.EOF = True Then
MsgBox "No Row found "
Else
txt_no1.Text = rs1("no")
txt_name.Text = rs1("name")
txt_job.Text = rs1("job")
txt_hiredate.Text = rs1("hiredate")
txt_sal.Text = rs1("sal")
txt_dept.Text = rs1("deptname")
End If
Frame1.Visible = False
End Sub

Private Sub btn_nextemp_Click()


Frame1.Visible = True
Frame2.Visible = False
btn_nextemp.Visible = True
txt_no1.Text = ""
txt_name.Text = ""
txt_job.Text = ""
txt_hiredate.Text = ""
txt_sal.Text = ""
txt_dept.Text = ""
71
Visual Programming Lab Manual (MCA 407)
BAPATLA ENGINEERING COLLEGE: BAPATLA
Department of MCA
txt_no.Text = ""
rs1.Close
End Sub

Private Sub Form_Load()


cn1 = "SERVER=oracle;DSN=sss;UID=scott;PWD=tiger;" 'DBQ=oracle;"
'DBA=W;APA=T;FEN=T;QTO=T;FRC=10;FDL=10;LOB=T;RST=T;FRL=F;MTS=F;CSR=F;PFC=1
0;TLO=O;"
'Set cn = New ADODB.Connection
With cn1
.ConnectionString = conn
.CursorLocation = adUseClient
.Open
End With

End Sub

Form2.code (update)
Dim rs As New ADODB.Recordset
Dim s As String

Private Sub btn_getemp_Click()


s = "select * from emp where no = '" & txt_no.Text & "' "
rs.Open s, cn, adOpenDynamic, adLockPessimistic
Frame2.Visible = True
If rs.EOF = True Then
MsgBox "No Row found "
Else
Frame1.Visible = False
txt_no1.Text = rs("no")
txt_name.Text = rs("name")
txt_job.Text = rs("job")
txt_hiredate.Text = rs("hiredate")
txt_sal.Text = rs("sal")
txt_dept.Text = rs("deptname")
End If
Frame1.Visible = False
End Sub

Private Sub btn_update_Click()


If rs.EditMode <> True Then

rs("no") = txt_no1.Text
rs("name") = txt_name.Text
rs("job") = txt_job.Text
rs("hiredate") = txt_hiredate.Text

72
Visual Programming Lab Manual (MCA 407)
BAPATLA ENGINEERING COLLEGE: BAPATLA
Department of MCA
rs("sal") = txt_sal.Text
rs("deptname") = txt_dept.Text
rs.Update
End If
MsgBox " Employee Updated Successfully...."
btn_update.Visible = False

End Sub

Private Sub btn_update1_Click()


Frame1.Visible = True
Frame2.Visible = False
btn_update1.Visible = True
txt_no1.Text = ""
txt_name.Text = ""
txt_job.Text = ""
txt_hiredate.Text = ""
txt_sal.Text = ""
txt_dept.Text = ""
txt_no.Text = ""
rs.Close
End Sub

Private Sub Form_Load()


cn = "SERVER=oracle;DSN=sss;UID=scott;PWD=tiger;" 'DBQ=oracle;"
'DBA=W;APA=T;FEN=T;QTO=T;FRC=10;FDL=10;LOB=T;RST=T;FRL=F;MTS=F;CSR=F;PFC=10;TL
O=O;"
'Set cn = New ADODB.Connection
With cn
.ConnectionString = conn
.CursorLocation = adUseClient
.Open
End With

'If Cn.State = adStateOpen Then


'MsgBox "Connection successful."
'End If

End Sub

Form3.code(delete)

Dim cn2 As New ADODB.Connection


Dim rs2 As New ADODB.Recordset
Dim s2 As String

Private Sub btn_delete_Click()


s2 = "delete emp where no='" & txt_no.Text & "' "

73
Visual Programming Lab Manual (MCA 407)
BAPATLA ENGINEERING COLLEGE: BAPATLA
Department of MCA
rs2.Open s2, cn2, adOpenDynamic, adLockPessimistic
MsgBox "Employee Deleted Successfully"
End Sub

Private Sub Form_Load()


cn2 = "SERVER=oracle;DSN=oradsn;UID=scott;PWD=tiger;" 'DBQ=oracle;"
'DBA=W;APA=T;FEN=T;QTO=T;FRC=10;FDL=10;LOB=T;RST=T;FRL=F;MTS=F;CSR=F;PFC=10;TL
O=O;"
'Set cn = New ADODB.Connection
With cn2
.ConnectionString = conn
.CursorLocation = adUseClient
.Open
End With

End Sub

Form4.code(New employee insert)

Dim cn4 As New ADODB.Connection


Dim rs4 As New ADODB.Recordset
Dim s4 As String

Private Sub btn_insert_Click()


s4 = "select * from emp"
rs4.Open s4, cn4, adOpenDynamic, adLockPessimistic
Frame2.Visible = True
If rs4.EOF = True Then
MsgBox "No Row found "
Else
rs4.AddNew
If rs4.EditMode <> True Then
rs4("no") = txt_no.Text
rs4("name") = txt_name.Text
rs4("job") = txt_job.Text
rs4("hiredate") = txt_hiredate.Text
rs4("sal") = txt_sal.Text
rs4("deptname") = txt_dept.Text
rs4.Update
End If
End If
MsgBox " Employee Inserted Successfully...."

End Sub

Private Sub btn_next_Click()


txt_no.Text = ""
txt_name.Text = ""

74
Visual Programming Lab Manual (MCA 407)
BAPATLA ENGINEERING COLLEGE: BAPATLA
Department of MCA
txt_job.Text = ""
txt_hiredate.Text = ""
txt_sal.Text = ""
txt_dept.Text = ""
rs4.Close
End Sub

Private Sub Form_Load()


cn4 = "SERVER=oracle;DSN=sss;UID=scott;PWD=tiger;" 'DBQ=oracle;"
'DBA=W;APA=T;FEN=T;QTO=T;FRC=10;FDL=10;LOB=T;RST=T;FRL=F;MTS=F;CSR=F;PFC=10;TL
O=O;"
'Set cn = New ADODB.Connection
With cn4
.ConnectionString = conn
.CursorLocation = adUseClient
.Open
End With

End Sub

Design:
Title: Application to perform operation on employee database using ADO.
Controls:

Form1(Search)
Control Name Caption
Button1 btn_empdetails Get Employee Details
Button2 btn_nextemp Next Employee Details
Label1 lbl_no Enter employee number you
want to search
Label2 lbl_no1 Employee Number
Label3 lbl_name Employee name
Label4 lbl_job Job
Label5 lbl_hiredate Employee Hiredate
Labe6 lbl_sal Salary
Label7 lbl_dept Employee Dept name
Textbox1 txt_no
Textbox2 txt_no1
Textbox3 txt_name
Textbox4 txt_job
Textbox5 txt_hiredate
Textbox6 txt_sal
Textbox7 txt_dept

75
Visual Programming Lab Manual (MCA 407)
BAPATLA ENGINEERING COLLEGE: BAPATLA
Department of MCA

Form2(update)
Control Name Caption
Button1 btn_empdetails Get Employee Details
Button2 btn_update Update Details
Button3 btn_update1 Next Update
Label1 lbl_no Enter employee number you
want to update
Label2 lbl_no1 Employee Number
Label3 lbl_name Employee name
Label4 lbl_job Job
Label5 lbl_hiredate Employee Hiredate
Labe6 lbl_sal Salary
Label7 lbl_dept Employee Dept name
Textbox1 txt_no
Textbox2 txt_no1
Textbox3 txt_name
Textbox4 txt_job
Textbox5 txt_hiredate
Textbox6 txt_sal
Textbox7 txt_dept

76
Visual Programming Lab Manual (MCA 407)
BAPATLA ENGINEERING COLLEGE: BAPATLA
Department of MCA

Form3(Delete)

Form2(update)
Control Name Caption
Button1 btn_delete Delete Employee
Textbox1 txt_no
Label1 lbl_no Enter employee number you
want to update

Form4(New)
Control Name Caption
Button1 btn_insert Insert Employee
Button2 Btn_nextemp Next employee
Label1 lbl_no1 Employee Number
Label2 lbl_name Employee name
Label3 lbl_job Job
Label4 lbl_hiredate Employee Hiredate
Labe5 lbl_sal Salary
Label6 lbl_dept Employee Dept name
Textbox1 txt_no
77
Visual Programming Lab Manual (MCA 407)
BAPATLA ENGINEERING COLLEGE: BAPATLA
Department of MCA
Textbox3 txt_name
Textbox4 txt_job
Textbox5 txt_hiredate
Textbox6 txt_sal
Textbox7 txt_dept

Mdi form

78
Visual Programming Lab Manual (MCA 407)
BAPATLA ENGINEERING COLLEGE: BAPATLA
Department of MCA
17. Develop a visual basic application to make the following operations on employee database.
i. Search an employee on the basis of employee number.
ii. Navigate and display the records on MOVE FIRST, MOVE NEXT, MOVE LAST and
MOVE PREVIOUS.

Database connection steps:


1. Go to maim menu and click on project menu item.
2. A drop down menu will appear.Select references submenu item.
3. A reference dialog box will appear.
4. In that all levels of all available references are diaplayed in the listbox
with check buttons.
5. Check the following references.
1. Microsoft Remote dataobject 2.0
2. Microsoft Remotedataservices 2.7 library.
3. Microsoft Remotedataservices server 2.7
library.
6. Click ok button to close the references dialog box.
Creating a DSN:
1. Move to control panel and double click on administrative tools then double click on
data Sources.
2. The ODBC data source administrative screen is displayed. Click on System DSN.
3. Click on ADD button.That create new data source dialog box will appear.Select
Microsoft ODBC for Oracle from the list and click on finish button.
4. The ODBC for Oracle dialogbox will appear for Data source name . You need to enter
the name of the datasource you need to create.
Set the authentication fileds as follows:
Username:scott
Password: tiger
Service name:oracle.
5. Click on finsibtton and close the ODBC dialogbox.

Dim env As rdoEnvironment


Dim conn As rdoConnection
Dim Rs As rdoResultset
Dim s As String
Dim search As String

'Move First

Private Sub btn_first_Click()


btn_previous.Enabled = False
s = "select * from emp11"
Set Rs = conn.OpenResultset(s, rdOpenDynamic, rdConcurRowVer)
Rs.MoveFirst
If Rs.EOF <> True Then
txt_empno.Text = Rs("empno")
txt_ename.Text = Rs("Ename")
txt_job.Text = Rs("job")

79
Visual Programming Lab Manual (MCA 407)
BAPATLA ENGINEERING COLLEGE: BAPATLA
Department of MCA
txt_mgr.Text = Rs("mgr")
txt_hiredate.Text = Rs("hiredate")
txt_sal.Text = Rs("sal")
txt_deptno.Text = Rs("deptno")
Else
MsgBox "End of file reached"
End If
btn_next.Enabled = True
End Sub

Private Sub btn_no_Click()


hide1
txt_no.Visible = True
lbl_no.Visible = True
btn_search.Visible = True
End Sub

'Move Previous
Private Sub btn_previous_Click()
Rs.MovePrevious
If Rs.EOF <> True Then
txt_empno.Text = Rs("empno")
txt_ename.Text = Rs("Ename")
txt_job.Text = Rs("job")
txt_mgr.Text = Rs("mgr")
txt_hiredate.Text = Rs("hiredate")
txt_sal.Text = Rs("sal")
txt_deptno.Text = Rs("deptno")
Else
MsgBox "End of file reached"
End If
btn_next.Enabled = True
End Sub

Private Sub btn_next_Click()


'Move Next
btn_previous.Enabled = True
Rs.MoveNext
If Rs.EOF <> True Then
txt_empno.Text = Rs("empno")
txt_ename.Text = Rs("Ename")
txt_job.Text = Rs("job")
txt_mgr.Text = Rs("mgr")
txt_hiredate.Text = Rs("hiredate")
txt_sal.Text = Rs("sal")
txt_deptno.Text = Rs("deptno")
Else

80
Visual Programming Lab Manual (MCA 407)
BAPATLA ENGINEERING COLLEGE: BAPATLA
Department of MCA
MsgBox "End of file reached"
End If

End Sub

Private Sub btn_last_Click()

'Move Last
btn_previous.Enabled = True
btn_next.Enabled = False
Rs.MoveLast
If Rs.EOF <> True Then
txt_empno.Text = Rs("empno")
txt_ename.Text = Rs("Ename")
txt_job.Text = Rs("job")
txt_mgr.Text = Rs("mgr")
txt_hiredate.Text = Rs("hiredate")
txt_sal.Text = Rs("sal")
txt_deptno.Text = Rs("deptno")

Else
MsgBox "End of file reached"
End If
End Sub

Private Sub btn_exit_Click()


End
End Sub

Private Sub btn_search_Click()


txt_no.Visible = False
lbl_no.Visible = False

show1
clear
search = "select * from emp11 where empno=" & txt_no.Text & ""
Set Rs = conn.OpenResultset(search, rdOpenDynamic, rdConcurRowVer)
If Rs.RowCount <> 0 Then
txt_empno.Text = Rs("Empno")
txt_ename.Text = Rs("Ename")
txt_job.Text = Rs("job")
txt_mgr.Text = Rs("mgr")
txt_hiredate.Text = Rs("hiredate")
txt_sal.Text = Rs("sal")
txt_deptno.Text = Rs("deptno")
Else
MsgBox "Record not available"
End If

81
Visual Programming Lab Manual (MCA 407)
BAPATLA ENGINEERING COLLEGE: BAPATLA
Department of MCA

End Sub

Private Sub Form_Load()


btn_previous.Enabled = False
txt_no.Visible = False
lbl_no.Visible = False
btn_next.Enabled = False
btn_search.Visible = False
Set env = rdoEnvironments(0)
env.CursorDriver = rdUseOdbc
Set conn = env.OpenConnection(sss, rdoDriverPrompt, False, "DSN=sss;UID=scott;PWD=tiger;")
MsgBox ("connection established")
s = "select * from emp11"
Set Rs = conn.OpenResultset(s, rdOpenDynamic, rdConcurVer)
End Sub

Public Function clear()


txt_empno.Text = ""
txt_ename.Text = ""
txt_job.Text = ""
txt_mgr.Text = ""
txt_hiredate.Text = ""
txt_sal.Text = ""
txt_deptno.Text = ""
End Function
Public Function hide1()
txt_empno.Visible = False
txt_ename.Visible = False
txt_job.Visible = False
txt_mgr.Visible = False
txt_hiredate.Visible = False
txt_sal.Visible = False
txt_deptno.Visible = False
lbl_empno.Visible = False
lbl_ename.Visible = False
lbl_job.Visible = False
lbl_mgr.Visible = False
lbl_hiredate.Visible = False
lbl_sal.Visible = False
lbl_deptno.Visible = False
End Function
Public Function show1()
txt_empno.Visible = True
txt_ename.Visible = True
txt_job.Visible = True
txt_mgr.Visible = True
txt_hiredate.Visible = True

82
Visual Programming Lab Manual (MCA 407)
BAPATLA ENGINEERING COLLEGE: BAPATLA
Department of MCA
txt_sal.Visible = True
txt_deptno.Visible = True
lbl_empno.Visible = True
lbl_ename.Visible = True
lbl_job.Visible = True
lbl_mgr.Visible = True
lbl_hiredate.Visible = True
lbl_sal.Visible = True
lbl_deptno.Visible = True
End Function
Design
Title: Application to make the following operations on employees
control

Control Name Caption


Button1 btn_first First
Button2 btn_previous Previous
Button3 btn_next Next
Button4 btn_last Last
Button5 btn_search Search
Button6 btn_no Enter employeeno to search
Button7 btn_exit Exit
Label1 lbl_empno Employee No
Label2 lbl_ename Employee Name
Label3 lbl_job Job
Label4 lbl_mgr Employee_ MGR
Label5 lbl_hiredate Employee Hiredate
Labe6 lbl_sal Salary
Label7 lbl_job Job
Label8 Lbl_deptno Employee Dept no
Textbox1 txt_empno
Textbox2 txt_ename
Textbox3 txt_job
Textbox4 txt_mgr
Textbox5 txt_hiredate
Textbox6 txt_sal
Textbox7 txt_deptno

83
Visual Programming Lab Manual (MCA 407)
BAPATLA ENGINEERING COLLEGE: BAPATLA
Department of MCA

84
Visual Programming Lab Manual (MCA 407)

Vous aimerez peut-être aussi