VB Project :Project: Lucky Seven in strandard vb see notes for

File memnu

Visual basic

Windows applicatgion

Project name

Locqation for saving

WHne form comes onto the scrfeen gop to toolbar and select button and drag to form


Creating the user Interface: :

File menu

Visual basic

Windows application

Project name

Location for saving

When form comes onto the screen go to toolbar and select button and drag to form


1.On the file menu, click the New Project command.

2.0.Click OK to create a standard 32-bit VB application.

3.0.Resize the Form so it will be large enough for all your objects.

4.0.Click the CommandButton control.

5.0.Move the mouse pointer to the form where you want the button and drag to the size you want.

Move and resize a (command) button:

1.      Drag the command button the the right by using the mouse.

2.      Resize and reshape as needed.

Add a second command button:

1.      Click the CommandButton control in the toolbox.

2.      Draw a command button below the first button on the form.

3.      Move or resize the button.

Add the number labels:

1.      Click the Label control in the toolbox, and then place the mouse pointer over the form.

2.      Create a small rectangular box to the right of the first command button.

3.      Click the label control and draw a label box to the right of the first label box.

4.      Click the label control and draw a third label box to the right of the last box.

5.      Click the Label control and create a larger rectangle directly below the two command buttons.

Add an image a picture

1.      Click the image picture control in the toolbox.

2.      Using the image picture control, create a large rectangular box directly beneath the three number labels.

Set the command button properties

1.      Click the first command button on the form.

2.      Double-click the Properties window title bar.

3.      Double-click the Caption Text property in the left column of the Properties window.

4.      Type Spin and press Enter.

5.      Open the object drop-down list box at the top of the Properties window.

6.      Click Command2 Button2 in the list box.

7.      Double-click the current Caption Text property, type End, and press Enter.

Set the number label properties

1.      Click the first number label, and then, holding down the Shift key, click the second and third number labels. When all three labels are selected, release the Shift key.

2.      Click the Alignment Text Align property, and then click the drop-down list box arrow that appears to the right.

3.      Click the 2 - Center option. center button in the map that appears.

4.      Click the BorderStyle property, and then click the drop-down list box arrow that appears to the right.

5.      Click 1 - Fixed Single in the list box to add a thin border around each label. 

6.      Double-click the Font property in the Properties window. And press the button with the ellipses to open the font dialog box


7.      change the font  to Times New Roman, the font style to Bold, and the point size to 24, and then click OK. 

8.      Click the form to remove the selection handles from the three labels, and then click the first label.

9.      Double-click the Caption Text  property, and then press Del.

10.  Delete the captions text in the second and third labels on the form.

Set the descriptive label properties

1.      Click the fourth label object on the form.

2.      Change the Caption Text property to "Lucky Seven".

3.      Double-click the Font property, and use the Font dialog box to change the font to Arial, the font style to Bold, and the point size to 20. Click OK.

4.      Double-click the ForeColor property in the Properties window.

5.      Click the drop down box, and click  Palette Custom tab, and then click the Pallette tab and then the box containing dark purple.

Set the Image box properties

1.      Navigate to the www.mvhs.net/images page with your browser.

2.      Download COINS.wmf by right clicking the mouse and save it in your server drive. 

3.      Click the image boxpicture object on the form.

4.      Click the Stretch Size-mode property in the Properties window, click the drop-down list box arrow, and then click True.Stretch Image

5.      Click the picture image property. Select the file Coins.wmf in the dialog box, and then click Open.

6.      Click the Visible property. Click the Visible drop-down list box arrow.

7.6.Click False to make the image invisible when the program starts.

8.7.Double-click the Properties window's title bar to return it to the docked position.

Use the Code Window

1.      Double-Click the End command button on the form. Inside the Code window are program statements that mark the beginning and the end of this particular Visual Basic subroutine (event procedure). The body of the procedure always fits between these lines and is executed whenever a user activates the interface element associated with the procedure.

2.      Type End, and press the Down arrow key.

3.      Move the cursor to the beginning of the line with the End statement in it, and press the Spacebar four times.

Write code for the Spin Button

1.      Open the Object drop-down list box in the Code window (Lis on the top left that states CLASS).

2.      Click Command1 Button1 in the list box then go to the event window and select the Click Event.

3.      Type the program lines below between the Private Sub and End Sub statements, pressing Enter after each line and taking care to type the program statements exactly as they appear below here.

Private Sub Command1_Click()
    Image1.Visible = False 'hide coins
    Label1.Caption Text = Int(Rnd * 10) 'pick numbers
    Label2.Caption Text = Int(Rnd * 10)
    Label3.Caption Text = Int(Rnd * 10)
    'if any caption is 7 display coin stack and beep
    If (Label1.Caption Text = 7) Or (Label2.Caption Text = 7) _
        Or (Label3.Caption Text = 7) Then
            Image1.Visible = True
    End If
End Sub

Private Sub Command2Button2_Click()
End Sub

Save the Lucky 7 program

1.      On the File menu, click the Save All project As command

2.1.Select the vb folder you created in your server H drive

3.1.Type MyLucky7 in the file name text box and press enter. (The form is saved.)

4.1.Type MyLucky7 in the Project dialog box and press enter. (The project is saved).

Run the program

1.      Click the Start Play  arrow/button on the toolbar.  Or F5.

2.      Click the Spin button.

3.      Click the Spin button 15 or 16 more times, watching the results of the spins in the number windows.

4.      When you have finished experimenting with your new creation, Click the End button and the program stops.

Create an executable file

1.0.On the file menu, click the Make MyLucky7.exe command.

2.0.Click OK to accept the default filename and location for the file.

3.1.On the File menu, click Exit to close Visual Basic and the MyLucky7 project.

Adding to a Program

1.      Load Visual Basic by clicking the VB icon on the desktop.

2.      Click the Recent tab in the New Project dialog box.

3.      Double-click MyLucky7 to load the Lucky Seven program from disk.

4.      Double-click the form (not one of the objects) to display the Form_Load procedure.

5.      Press the Spacebar four times, type Randomize, and press the Down Arrow key.

6.      Run the new version of Lucky Seven, and then save the project to disk.


Build this program in C#

1.       Keep your Lucky 7 program open

2.       Click the VS.Net Icon to open another IDE.

3.      Open new project in C#

4.      Select the windows application project template

5.      Specify the name of the file and its location

6.      Click OK

7.      Leave the C# IDE open and switch to the VB project by pressing alt-tab or clicking on the project name on the task bar.

8.      Select the objects on the VB project form and copy them to the clipboard( use ctrl C).

9.      Switch to the c# project and paste the objects to the form (use ctrlV0

10.  MoDIFY THE code as follows:

// signals the berginning of a rem statement

//The parameter list of one item indicates the object the event happened to and the parameter list 2 item is the event information//
private void Button2_Click(object sender, System.EventArgs e)
 //like end in VB//

private void Button1_Click(object sender, System.EventArgs e)
Random dice = new Random();
  //create a new instance of a random object//
PictureBox1.Visible = false;
int rand1 = dice.Next(1,9);
// a random integer between 1 and 9 is received//
int rand2 = dice.Next(1,9);
int rand3 = dice.Next(1,9);
Label1.Text = rand1.ToString()
   //converts an object reference to a string representation//
Label2.Text = rand2.ToString();
Label3.Text = rand3.ToString();

if (rand1 == 7 || rand2 == 7 || rand3 == 7)
PictureBox1.Visible = true;


Run the C# program

  1. Click the play button to execute the file.