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. Open Visual Basic 6.0 Start → Programs/All Programs → Microsoft Visual Studio 6.0 → Microsoft Visual Basic 6.0 Select Standard EXE → Open Take one Label(Label1) → Press F4 → Caption → Enter any Number Take one TextBox(Text1) → Press F4 → Text → Press SpaceBar Take on CommandButton(Command1) → Press F4 → Caption Double Click on Command1 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 Save the Project File → Save Project → Save in → Select Desktop → xi69.frm → Save → xi69.vbp → Save Run The Project Press F5
Question: Write a Program in VB to change the background/foreground colour of any of the controls of the form based on the colour selected from a list. Ans. 1. Open Visual Basic 6.0 Start→Programs/All Programs→Microsoft Visual Studio 6.0→Microsoft Visual Basic 6.0 Select Standard EXE → Open 2. Take one Combo Box(Combo1) 3. Double click on Combo1 4. Write the following Code- Private Sub Form_Load() Combo1.AddItem(“BLACK”) Combo1.AddItem(“BLUE”) Combo1.AddItem(“GREEN”) Combo1.AddItem(“CYAN”) Combo1.AddItem(“MEGENTA”) Combo1.AddItem(“VIOLET”) End Sub Private Sub Combo1_Change() Form1.BackColor=QBColor(Combo1.ListIndex) End Sub 5. Save the Project File→Save Project→Save in→ Select Desktop→xi16.frm→Save→xi16.vbp→Save 6. Run The Project Press F5
Comments
Post a Comment