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 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 |
empcode and display that record onto the form. (Use Input box).
[Marks 25]
Solution
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
Tags:
VB 6.0

