Visual Basic 6.0

Visual Basic 6.0


Slip12

Q.1) Write a VB Program to display all even and odd numbers from an array. [Marks 15]

Solution

Dim i As Integer
Dim n As Integer
Dim A() As Integer

Private Sub Command1_Click()
n = Val(InputBox("enter number"))
ReDim A(n)
Print "array is:"
For i = o To n - 1
A(i) = Val(InputBox("enter element"))
Print A(i)
Next
Print "even number is:"
For i = o To n - 1
If A(i) Mod 2 = 0 Then
Print A(i)
End If
Next
Print "odd number is:"
For i = o To n - 1
If A(i) Mod 2 <> 0 Then
Print A(i)
End If
Next
End Sub


Output

Even or Odd



Q.2) Write a VB program to search an employee record from the database according to the
empcode and display that record onto the form. (Use Input box).
[Marks 25]

Solution

Dim c As New ADODB.Connection
Dim r As New ADODB.Recordset
Dim s As String

Private Sub Command1_Click()
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text1.SetFocus
End Sub

Private Sub Command2_Click()
With Adodc1.Recordset
r.Close
s = "insert into emp values(" & Val(Text1.Text) & ",'" & (Text2.Text) & "'," & Val(Text3.Text) & ")"
r.open s, c, adOpenDynamic, adLockOptimistic
s = "select * from emp"
r.open s, c, adOpenDynamic, adLockOptimistic
If Not r.EOF Then
r.MoveFirst
Text1.Text = r.Fields(0).Value
Text2.Text = r.Fields(1).Value
Text3.Text = r.Fields(2).Value
End If
.Update
.Requery
End With
MsgBox "record added succesfull"
End Sub

Private Sub Command3_Click()
With Adodc1.Recordset
Dim a As Integer
a = Val(InputBox("enter you want search"))
r.Close
s = "select * from emp where (eno = " & Val(a) & "  )"
r.open s, c, adOpenDynamic, adLockOptimistic
s = "select * from emp"
If Not r.BOF And Not r.EOF Then
r.MoveFirst
Text1.Text = r.Fields(0).Value
Text2.Text = r.Fields(1).Value
Text3.Text = r.Fields(2).Value
End If
End With
MsgBox "record is not found"
End Sub

Private Sub Form_Load()
c.open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\VB\PROJECTS\SLIP12.4.MDB;Persist Security Info=False"
s = "select * from emp"
r.open s, c, adOpenDynamic, adLockOptimistic
If Not r.BOF And Not r.EOF Then
r.MoveFirst
Text1.Text = r.Fields(0).Value
Text2.Text = r.Fields(1).Value
Text3.Text = r.Fields(2).Value
End If
End Sub


Output


BCA Pratical Solution

My name is Vivek And I from Mumbai and Complete my Graduation Bca.my Age is 23 Years.

Post a Comment

Previous Post Next Post

DBMS Practical Slips