Visual Basic 6.0
Slip11
Q.1) Write a VB Program to accept the number from the user in text box and display
multiplication table of that number into the list box.
[Marks 15]
Solution
Dim n, i As Integer
Private Sub Command1_Click()
n = Val(Text1.Text)
For i = 1 To 10
List1.AddItem n * i
Next
End Sub
Private Sub Command2_Click()
Unload Me
End Sub
Private Sub Command3_Click()
Text1.Text = ""
List1.Clear
Text1.SetFocus
End Sub
Output
![]() |
Multiplication |
Q.2) Write a VB program to accept the details of book, store those details into the database
and delete the particular record of given book id. (Use InputBox) [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 book values(" & Val(Text1.Text) & ",'" & (Text2.Text) & "'," & Val(Text3.Text) & ")"
r.open s, c, adOpenDynamic, adLockOptimistic
s = "select * from book"
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 n As Integer
n = Val(InputBox("enter book id"))
r.Close
s = "delete from book where (id = " & n & " )"
r.open s, c, adOpenDynamic, adLockOptimistic
s = "select * from book"
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
.Update
.Requery
End With
MsgBox "record are deleted"
End Sub
Private Sub Command4_Click()
r.MoveNext
If Not r.EOF Then
Text1.Text = r.Fields(0).Value
Text2.Text = r.Fields(1).Value
Text3.Text = r.Fields(2).Value
Else
MsgBox "no more records"
End If
End Sub
Private Sub Command5_Click()
r.MovePrevious
If Not r.BOF Then
Text1.Text = r.Fields(0).Value
Text2.Text = r.Fields(1).Value
Text3.Text = r.Fields(2).Value
Else
MsgBox "no more records"
End If
End Sub
Private Sub Form_Load()
c.open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\VB\PROJECTS\SLIP11.4.MDB;Persist Security Info=False"
s = "select * from book"
r.open s, c, adOpenDynamic, adLockOptimistic
If Not r.BOF And Not r.EOF Then
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