Visual Basic 6.0

Visual Basic 6.0

Slip17

Q.1) Write a VB program to enter two positive numbers, calculate the sum of the products of
each pair of digits occupying the same position in the two numbers. Display the result on
to the form.
Example:
If first number is 45 and second number is 534, then output will be 32.
(0*5 + 4*3 + 5*4 = 32)
[Marks 15]

Solution

Private Sub Command1_Click()
Dim no1 As Integer
Dim no2 As Integer
Dim r1 As Integer, r2 As Integer, sum As Integer
no1 = Val(Text1.Text)
no2 = Val(Text2.Text)
While no1 Or no2
r1 = no1 Mod 10
r2 = no2 Mod 10
prod = r1 * r2
sum = sum + prod
no1 = no1 \ 10
no2 = no2 \ 10
Wend
Print "Sum of Product is "; sum
End Sub

Output





Q.2) Write a VB a program to enter “ Voters details and on next form disply Voter’ s
Information and check proper validation for(name, age,nationality) as
 Name should be in upper case letters
 Age should not be less than 18 yrs.
 Natinality should be Indian. [Marks 25]

Solution

Dim age As Integer
Dim vname As String

Private Sub Command1_Click()
age = Text2.Text
vname = Text1.Text
If Val(Text2.Text) < 18 Then
MsgBox ("Age should be greater than 18")
ElseIf Text3.Text <> "Indian" Then
MsgBox ("Nationality must be Indian")
Else
Form2.Show
Form2.Label4.Caption = vname
Form2.Label5.Caption = age
End If
End Sub

Private Sub Text1_KeyPress(KeyAscii As Integer)
Select Case Chr(KeyAscii)
Case "a" To "z"
MsgBox ("Only Capital letters are allowed")
KeyAscii = 0
Case 0 To 9
MsgBox ("Only Characters are allowed")
KeyAscii = 0
End Select
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