Visual Basic 6.0
Slip 7
contains any text and second combo box contains color names. Write a VB Program to
set caption and background color to the label control from respective combo boxes.
[Marks 15]
Solution
Private Sub Combo1_Click()
Label1.Caption = Combo1.Text
End Sub
Private Sub Combo2_Click()
If Combo2.Text = "RED" Then
Label1.BackColor = vbRed
ElseIf Combo2.Text = "BLUE" Then
Label1.BackColor = vbBlue
Else
Label1.BackColor = vbGreen
End If
End Sub
Output
Q.4) Write a VB Program to accept the details of employee from user & store those details in
to the database. (Don’ t use Standard controls) Employee having fields emp_code,
emp_name, salary, dateofjoining. [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 = ""
Text4.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) & ",'" & (Text4.Text) & "')"
r.open s, c, adOpenDynamic, adLockOptimistic
s = "select * from emp"
r.open s, c, adOpenDynamic, adLockOptimistic
If Not r.EOF Then
Text1.Text = r.Fields(0).Value
Text2.Text = r.Fields(1).Value
Text3.Text = r.Fields(2).Value
Text4.Text = r.Fields(3).Value
End If
.Update
.Requery
End With
MsgBox "record added succesfull!"
End Sub
Private Sub Command3_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
Text4.Text = r.Fields(3).Value
Else
MsgBox "no more records"
End If
End Sub
Private Sub Command4_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
Text4.Text = r.Fields(3).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\SLIP7.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
Text1.Text = r.Fields(0).Value
Text2.Text = r.Fields(1).Value
Text3.Text = r.Fields(2).Value
Text4.Text = r.Fields(3).Value
End If
End Sub
Output
Tags:
VB 6.0