Visual Basic 6.0
Slip 5
Q.1) Write a VB Program to display Fibonacci series up to given term (Accept term
using Input Box )and display Fibonacci series on to the form. [Marks 15]
Solution
Dim n As Integer
Dim A As Integer
Dim B As Integer
Dim fab As Integer
Dim i As Integer
Private Sub Command1_Click()
A = 0
B = 1
n = Val(InputBox("Enter number"))
For i = 1 To n
fab = (A + B)
A = B
B = fab
Print "fibonacci series:" & fab
Next
End Sub
Output
Output
![]() |
Fibonacci |
Q.2) Write a VB program to accept the details of student and display mark sheet details
on grid control.( roll_ no, student_ name, class, sub1, sub2, sub3, total, percentage, grade)
[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 = ""
Text5.Text = ""
Text6.Text = ""
Text7.Text = ""
Text8.Text = ""
Text9.Text = ""
Text1.SetFocus
End Sub
Private Sub Command2_Click()
With Adodc1.Recordset
r.Close
s = "insert into stud values(" & Val(Text1.Text) & ",'" & (Text2.Text) & "','" & (Text3.Text) & "'," & Val(Text4.Text) & "," & Val(Text5.Text) & "," & Val(Text6.Text) & "," & Val(Text7.Text) & "," & Val(Text8.Text) & ",'" & (Text9.Text) & "')"
r.open s, c, adOpenDynamic, adLockOptimistic
s = "select * from stud"
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
Text5.Text = r.Fields(4).Value
Text6.Text = r.Fields(5).Value
Text7.Text = r.Fields(6).Value
Text8.Text = r.Fields(7).Value
Text9.Text = r.Fields(8).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
Text5.Text = r.Fields(4).Value
Text6.Text = r.Fields(5).Value
Text7.Text = r.Fields(6).Value
Text8.Text = r.Fields(7).Value
Text9.Text = r.Fields(8).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
Text5.Text = r.Fields(4).Value
Text6.Text = r.Fields(5).Value
Text7.Text = r.Fields(6).Value
Text8.Text = r.Fields(7).Value
Text9.Text = r.Fields(8).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\SLIP5.4.MDB;Persist Security Info=False"
s = "select * from stud"
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
Text5.Text = r.Fields(4).Value
Text6.Text = r.Fields(5).Value
Text7.Text = r.Fields(6).Value
Text8.Text = r.Fields(7).Value
Text9.Text = r.Fields(8).Value
End If
End Sub
Private Sub Text7_click()
Text7.Text = Val(Text4.Text) + Val(Text5.Text) + Val(Text6.Text)
End Sub
Private Sub Text8_click()
Text8.Text = (Val(Text7.Text) / 300) * 100
End Sub
Private Sub Text9_click()
If Val(Text8.Text) >= 40 Then
Text9.Text = "PASS"
Else
Text9.Text = "FAIL"
End If
End Sub
Output
![]() |
Tags:
VB 6.0