Monday, 7 January 2013

VB .Net, Creating Hello World Example



In this blog entry we are going to create a form in VB .Net.  The user will be able to run the form and enter their name in a text box.  On pressing the submit button the form will display the words Hello and the name entered in the text box.

To create this application we will complete the following steps:
    1. Open up Visual Studio 2012
    2. Create a new project
    3. Add a text box to the form
    4. Set the properties of the text box
    5. Add a button
    6. Set the properties of the button
    7. Add a label to the form
    8. Set the properties of the label
    9. Create the code behind the form
    10. Run the form

      Step 1, Open up Microsoft Visual Studio 2012.

      • Click the windows button
      • Click on Visual Studio 2012

      Step 2, Create a new project

      • Click File
      • New Project




      • In the name field enter a name
      • Click OK.

      Step 3, Add a text box to the form


      A page will appear with a new blank form.
      At the left hand side of the form there is a menu called Toolbox.



      Click on the Toolbox Menu


      • Click on TextBox
      • Hold down the left mouse button
      • Drage th Text Box off the Menu
      • When the mernu disappears drop the text box onto the form.
       The form should now look like this:


      Step 4, Set the properties of the text box


      If we click on the text box on the bottom right of the screen we can see the properties of the text box.  The properties are all the differnt settings of the text box.



      Click on the properites and find name.  Make sure its set to textBox1


      Step 5, Add a button

      • Click on the Toolbox on the left of the form
      • Click on Button
      • Hold down the left mouse button
      • Drag the Button off the Menu
      • When the mernu disappears drop the button onto the form.

      Step 6, Set the properties of the button

      • Click on the button on the form
      • Go over to the properties (bottom right of the screen)
      • Make sure the name is button1
      • Change text to Submit.  When this is changed you'll see the label of the button change from button1 to Submit 

      Step 7, Add a label to the form


      Click on the Toolbox on the left of the form
      Click on Label
      Hold down the left mouse button
      Drag the Label off the Menu
      When the menu disappears drop the label onto the form.
      Put the lavel on the form underneath the button

      Step 8, Set the properties of the label

      • Make sure the name is label1
      • Set the text to nothing
      • Set Minimum Size to 50,0


      Step 9, Create the code behind the form

      • Double click on the button
      • Enter the following code
        • label2.Text = "Hello " +  textBox1.Text
      • between the text Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click and  End Sub
      Public Class Form1
      
          Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
      
             label2.Text = "Hello " +  textBox1.Text
      
          End Sub
      End Class
      



      Step 10, run the form


      Click the start button on the toolbar to run the form

      How it works

       

      • The users enters their name in textbox1.
      • The user then presses the button button1.
      • Pressing button1 causes the code behind button1to run.
      • The code behind button1 sets the label (labl1) to the text Hello + whatever text has been entered in textbox1.



      No comments:

      Post a Comment