Visual Basic 6.0
Slip 9
(Use Message box to display result) [Marks 15]
Solution
Private Sub Command1_Click()
BirthDate = Text1.Text
MsgBox ("Age :" & ExactAge(BirthDate))
End Sub
Public Function ExactAge(BirthDate As Variant) As String
Dim yer As Integer, mon As Integer, d As Integer
Dim dt As Date
Dim sAns As String
dt = CDate(BirthDate)
If dt > Now Then Exit Function
yer = Year(dt)
Print yer
mon = Month(dt)
Print mon
d = Day(dt)
Print d
yer = Year(Date) - yer
mon = Month(Date) - mon
d = Day(Date) - d
sAns = yer & " year(s) " & mon & " month(s) " & d & " day(s) old."
ExactAge = sAns
End Function
Output
![]() |
Age Calculator |
Q.2) Write a VB program to accept the details of doctor having field’ s dno, dname, address,
and phone number. Display those details on to the grid.
[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 doctor values(" & Val(Text1.Text) & ",'" & (Text2.Text) & "','" & (Text3.Text) & "'," & Val(Text4.Text) & ")"
r.open s, c, adOpenDynamic, adLockOptimistic
s = "select * from doctor"
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
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\SLIP9.4.MDB;Persist Security Info=False"
s = "select * from doctor"
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
Text4.Text = r.Fields(3).Value
End If
End Sub
Output
Tags:
VB 6.0