visual Basic Assignment #1

Biswajit Bhunia

Assistant Teacher, Bankura Banga Vidyalay

my mail: biswajit62418@gmail.com 

Question:

Write a Program in VB to check whether a given number is Prime or Not.

Ans.

  1. Open Visual Basic 6.0

StartPrograms/All ProgramsMicrosoft Visual Studio 6.0Microsoft Visual Basic 6.0

Select Standard EXE Open

  1. Take one Label(Label1) Press F4CaptionEnter any Number

  2. Take one  TextBox(Text1)Press F4TextPress SpaceBar

  3. Take on CommandButton(Command1)Press F4Caption

  4. Double Click on Command1

  5. Write the following Code-


PRIVATE SUB COMMAND1_CLICK()

DIM N,R,I AS INTEGER

N=VAL(TEXT1.TEXT)

R=0

FOR I=2 TO N/2

R=N MOD i

IF R=0 THEN 

  MSGBOX “NUMBER IS NOT PRIME”

  Exit sub

END IF

NEXT I

IF R=0 THEN

 MSGBOX “THE NUMBER IS NOT PRIME”

ELSE

MSGBOX “THE NUMBER IS PRIME”

ENDIF

END SUB


  1. Save the Project

FileSave ProjectSave in Select Desktopxi69.frmSavexi69.vbpSave

  1. Run The Project

Press F5


Comments