Free Web Hosting by Netfirms
Web Hosting by Netfirms | Free Domain Names by Netfirms

 

Home ] Up ]


My Name Program

This exercise will guide you through the writing of a simple program that will display your name and surname, together with a message.

1.    Start Visual Basic and create a new blank solution.

 

 

2.    Name your solution "MyName Solution".

 

 

3.    Create a new project.

 

 

4.    Name your project "MyName Project".

 

 

5.    Rename the Form1.vb file to MyNameForm.vb

 

 

6.    Click the windows form to make it active, thereby displaying its properties window.  Now change the form's name from Form1 to MyNameForm.

 

 

7.    Change the following properties of MyNameForm:
  • Set MaximizeBox to False
  • Set StartPosition to CenterScreen
  • Change Text to "My Name Program"

 

8.    Right-click MyName Project in the Solution Explorer window and select Properties from the menu.

 

 

9.    Select the Startup object as MyNameForm from the drop-down list, and click OK.

NOTE:  Steps 1 through 9 should be repeated for every program you write, until you move on to more advanced programming.

 

10.    Click-and-drag a Label control onto the windows form.

 

 

11.    In the properties window of the Label control, set the following:
  • Change Text from Label1 to "Name:"
  • Set AutoSize to True
  • Change (Name) from Label1 to "idNameLabel"

 

 

12.    Click-and-drag a TextBox control onto the form and set the following properties (just like we did in the previous step).
  • Change (Name) from TextBox1 to "NameTextBox"
  • Delete TextBox1 from the Text property to leave it blank

 

        

13.   Do the following to make your windows form resemble the image below.  Use steps 10 to 12 above as guidance:

        Click-and-drag a Button control onto the windows form and set the properties as follows:

  • Change (Name) from Button1 to "ExitButton"
  • Change Text from Button1 to "Exit"

        Drag-and-drop a second Button control onto the windows form and set the properties as follows:

  • Change (Name) from Button1 to "EnterButton"
  • Change Text from Button1 to "Enter"

        Drag-and-drop a Label control onto the windows form and set the properties as follows:

  • Change (Name) from Label1 to "idSurnameLabel"
  • Set the AutoSize property to "True"
  • Change Text from Label1 to "Surname:"

        Drag-and-drop a TextBox control onto the windows from and set the properties as follows:

  • Change (Name) from TextBox1 to "SurnameTextBox"
  • Delete the word "TextBox1" from the Text property and leave it blank

        Drag-and-drop a Label control onto the windows form and set the properties as follows:

  • Change (Name) from Label1 to "DisplayLabel"
  • Delete the word "Label1" from the Text property and leave it blank
  • Click-and-drag the label to the same size as the one shown below

 

       <<< This is what your windows form should look like once you have added all the controls

 

14.    Click the Save All button.  Press the F7 key on your keyboard to take you to the Code Editor window.

 

 

15.    We will now write the code for the ExitButton.  This code will allow the Exit button to close the program when you click it.
  • Select the drop-down button on the Class Name list, and choose ExitButton
  • Select the drop-down button on the Method Name list and choose Click

This will allow you to code the ExitButton's Click Event.

 

 

 

16.    Type Me.Close() as indicated below.

 

 

17.    We will now code the EnterButton's Click Event.
  • As you did in step 15, select the drop-down button from the Class Name list and select EnterButton
  • Select the drop-down from the Method Name list and select Click

        Enter the code exactly as indicated below.

 

 

18.    Click the Save All button.  Press F5 to launch your program.

 

 

19.    Your program window will now sit on your screen, ready for you to use it.
  • Enter your name in the first textbox
  • Enter your surname in the second textbox
  • Click the Enter button
  • You should see the same as the image below
  • Click the Exit button to close the program

 

 

~ Back to Top ~


All content on this site is free for private use only  |  Contributions are encouraged  |  Thank you to Netfirms for the free hosting  |  If copyright content is published here or links to certain content violates some right/law, contact the Webmaster to have it removed immediately.

 

Site launched: October 2005  |  Updated: July 20, 2006  |  Link exchange  |  Site map  |  Contact us