Visual Basic 6.0

Visual Basic 6.0


Slip1

Q.1) Write a VB program to find out twin prime numbers between 10 to 100. Twin primes
are defined to be two consecutive odd numbers, which are prime (Accept input through
textbox and display result on form)
e.g.: 11 and 13, 17 and 19 are twin prime numbers.   [15 Marks]

Solution

Dim no1 As Integer
Dim no2 As Integer
Dim i As Integer
Dim flag As Boolean

Private Sub Command1_Click()
flag = False
no1 = InputBox("ENTER 1ST NO")
no2 = InputBox("ENTER 2ND NO")
If no1 > 10 And no2 < 100 Then
While no1 <= no2
For i = 2 To no1 \ 2
If no1 Mod i = 0 Then
flag = True
End If
Next
If flag = True Then
MsgBox "Either of the number is not prime"
Else
cnt = cnt + 1
no3 = no1
no1 = no1 + 2
flag = False
End If
If cnt = 2 Then
If no3 = no2 Then
MsgBox "No1 and no2 are twin primes"
Else
MsgBox "No1 and no2 are not twin primes"
End If
End If
Wend
End If
End Sub





Q.2) Create the following application in VB. The form should contain the following menu
Draw     Modify     Exit
Circle    Shrink
              Expand
              Erase
On selection of the menu option ‘ Circle’ , a circle should be drawn on the screen. The
user can Shrink, Expand or Erase the circle by selecting the menu option or by displaying
a popup menu after the right mouse button is clicked or pressed. The popup menu should
contain the option Shrink, Expand or Erase which should perform the same operation as
the menu option.   [25 Marks]

Solution

Private Sub circle_Click()
Shape1.Visible = True
Shape2.Visible = False
Shape3.Visible = False
End Sub

Private Sub erase_Click()
Shape1.Visible = False
Shape2.Visible = False
Shape3.Visible = False
End Sub

Private Sub exit_Click()
Unload Me
End Sub

Private Sub expand_Click()
Shape1.Visible = False
Shape2.Visible = False
Shape3.Visible = True
End Sub

Private Sub Form_Load()
Shape1.Visible = False
Shape2.Visible = False
Shape3.Visible = False
End Sub

Private Sub Form_MouseDown(Button As Integer, Shift As Integer, x As Single, Y As Single)
If Button = vbRightButton Then
PopupMenu abc, vbPopupMenuRightButton
End If
End Sub

Private Sub shrink_Click()
Shape1.Visible = False
Shape2.Visible = True
Shape3.Visible = False
End Sub


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