Visual Basic 6.0

Visual Basic 6.0

Slip13

Q.1) Write a VB program to design following screen with validation name should contain
character only, mobile number should contain only 10 digit, Pin code should contain only
6 digit, email id should contain @, . symbol. [Marks 15]


Solution

Private Sub Command1_Click()
Dim str As String
str = Text4.Text
If Not InStr(1, "@", str) And Text4.Text <> "" Then
If Not InStr(1, ".", str) Then
MsgBox ("All data validated")
Else
MsgBox ("Email not contain.")
End If
Else
MsgBox ("Email withoun @")
End If
End Sub

Private Sub Text1_KeyPress(KeyAscii As Integer)
Print KeyAscii
Select Case Chr(KeyAscii)
Case 0 To 9
MsgBox ("Only Characters are allowed")
KeyAscii = 0
End Select
End Sub
Private Sub Text2_KeyPress(KeyAscii As Integer)
If Not IsNumeric(Text2.Text & Chr(KeyAscii)) And Not KeyAscii = 8 Then
MsgBox ("only Numbers are allowed")
KeyAscii = 0 '8 for backspace
End If
End Sub

Private Sub Text3_KeyPress(KeyAscii As Integer)
If Not IsNumeric(Text3.Text & Chr(KeyAscii)) And Not KeyAscii = 8 Then KeyAscii = 0
End Sub




Q.2) Write a VB program to accept the details of product (pno, pname, qty, price
totalprice) store it into the database and update the quantity of product having pno is 100.
(Don’ t use Standard Data controls) [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 = ""
Text1.SetFocus
End Sub

Private Sub Command2_Click()
With Adodc1.Recordset
r.Close
s = "insert into product values(" & Val(Text1.Text) & ",'" & (Text2.Text) & "'," & Val(Text3.Text) & "," & Val(Text4.Text) & "," & Val(Text5.Text) & ")"
r.open s, c, adOpenDynamic, adLockOptimistic
s = "select * from product"
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
End If
.Update
.Requery
End With
MsgBox "record added succesfull"
End Sub

Private Sub Command3_Click()
Dim a As Integer
Dim qty As Integer
a = Val(InputBox("enter pno"))
qty = Val(InputBox("enter qty to update"))
r.Close
s = "update product set qty=" & (qty) & " where(pno=" & Val(a) & ")"
r.open s, c, adOpenDynamic, adLockOptimistic
MsgBox "data is update"
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
Text4.Text = r.Fields(3).Value
Text5.Text = r.Fields(4).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
Text4.Text = r.Fields(3).Value
Text5.Text = r.Fields(4).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\SLIP13.4.MDB;Persist Security Info=False"
s = "select * from product"
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
End If
End Sub

Private Sub Text5_click()
Text5.Text = Val(Text3.Text) * Val(Text4.Text)
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