Visual Basic 6.0

Visual Basic 6.0

Slip 8

Q.3) Write a VB Program to accept a number from user and check whether it is palindrome
or not (Accept number using input box ) and display result using message box.
[Marks 15]

Solution

Dim sum As Integer
Dim n As Integer
Dim A As Integer
Dim r As Integer

Private Sub Command1_Click()
n = Val(InputBox("enter number"))
A = n
sum = 0
While n > 0
r = n Mod 10
n = n / 10
sum = sum * 10 + r
Wend
If sum = A Then
MsgBox ("number is pallindrom")
Else
MsgBox ("number is not pallindrom")
End If
End Sub

Output

Palindrome


Q.4) Write a VB Program to accept the details of Company from user & store those details in
to the database. (Don’ t use Standard controls) Company having fields ccode, cname,
cadddress, cphno. [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 COMPANY values(" & Val(Text1.Text) & ",'" & (Text2.Text) & "','" & (Text3.Text) & "'," & Val(Text4.Text) & ")"
r.open s, c, adOpenDynamic, adLockOptimistic
s = "select * from COMPANY"
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 "Details 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 "record is added"
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 "record is added"
End If
End Sub

Private Sub Form_Load()
c.open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\VB\PROJECTS\COMPANY.MDB;Persist Security Info=False"
s = "select * from COMPANY"
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

BCA Pratical Solution

My name is Vivek And I from Mumbai and Complete my Graduation Bca.my Age is 23 Years.

Post a Comment

Previous Post Next Post

DBMS Practical Slips