Programming

Visual Basic.NET


Download software: Download Visual Studio Express for Windows Desktop

Cost: Free

Instructions to setup software: Run SETUP program


TRY IT!

1. Open Visual Studio Express for Windows Desktop.

2. From the start page click on New Project…

3. Select Windows Forms App, and enter ‘VB Programming MB Demo’ in the Name and Solution Name boxes.

4. Click on ‘OK’ to create the project.

5. vbasicEdit Form 1 so that it looks like this:

You’ll need to change the Text in the properties box for Form 1. (Lower right part of Visual Studio.)

Create two buttons. Put ‘Convert Temperature’ in the text field for one button and ‘Restart’ in the other.

Create five labels. Label one should have the text ‘Enter temperature.’ Label two should read ‘Converted temperature is:.’ Label 3 will display the converted temperature. Label four will have the text ‘Celsius.’ Finally Label five will have the messages from the conversion.

6. On the right side of Visual Studio, right click on the Form1.vb icon and select ‘View Code’ from the menu.

7. Copy this VB code into the Form1.VB code window

Public Class Form1
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim Starttemp, Fintemp As Double
        Starttemp = TextBox1.Text
        Fintemp = (5 /9) * (Starttemp - 32)
        Label3.Text = Fintemp
        Label3.Visible = True
        Label4.Visible = True
        If Starttemp > 100 Then
            Label5.ForeColor = Color.Red
            Label5.Text = "Better Hydrate!"
            Label5.Visible = True
        ElseIf Starttemp < 32 Then
            Label5.ForeColor = Color.BlueViolet
            Label5.Text = "Brr! Pack the Long Johns!!!"
            Label5.Visible = True
        End If
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        TextBox1.Text = ""
        Label3.Visible = False
        Label4.Visible = False
        Label5.Visible = False
    End Sub
End Class
}

8. Click on File then Save All from the program menu.

9. Click on DEBUG then Start Debugging in the program menu to test the program. Enter a temperature and click the Convert Temperature Button to see the result. Try several different temperatures.


ABOUT THE PROGRAM – A WALK THROUGH

The “Button_Click_1” function

a. Obtains the value entered in the Input Textbox.
b. The value is converted to Celsius (with a single decimal place).
c. The Celsius value is evaluated with a series of IF Statements and a suggested action phrase is assigned to the variable: “Label5.Text”
d. A sentence is created by combining or “concatenating” some static text along with the temperature values (deg F and Deg C) and the action phrase.


TRY THIS

1. Change the temperatures used in the decisions – change the lower temperature from 60 to 30 degrees, for example. Save the file, restart the program, and enter new numbers – did the answers change at the new temperature?

2. Create a new temperature range from 30 to 60 degrees and have it display – “Bring hat and gloves!”

3. Change the wording of the phrases

4. Add another text input – ask for the wind speed, for example

5. Add some conditional statements that evaluate the wind chill factor

6. Add some text to display the wind chill result


LEARN MORE

http://www.vbtutor.net/ – A well organized tutorial with a lot of working examples and source code

Comments about “Visual Basic.NET”

  1. Page Author says:

    Visual Studio Express is a free download from Microsoft. There is no charge for downloading the program and writing code with it.

  2. Armageddon says:

    This is not free anymore it costs money!

Write a comment about “Visual Basic.NET”

Nickname:

Type your comment:

  • 1. Safety. Do the following:
      a. Show your counselor your current, up-to-date Cyber Chip.
      b. Discuss first aid and prevention for the types of injuries or illnesses that could occur during programming activities, including repetitive stress injuries and eyestrain.

    2. History. Do the following:
      a. Give a brief history of programming, including at least three milestones related to the advancement or development of programming.
      b. Describe the evolution of programming methods and how they have improved over time.

    3. General knowledge. Do the following:
      a. Create a list of 10 popular programming languages in use today and describe which industry or industries they are primarily used in and why.
      b. Describe three different programmed devices you rely on every day.

    4. Intellectual property. Do the following:
      a. Explain how software patents and copyrights protect a programmer.
      b. Describe the difference between licensing and owning software.
      c. Describe the differences between freeware, open source, and commercial software, and why it is important to respect the terms of use of each.

    5. Projects. Do the following:
      a. With your counselor’s approval, choose a sample program. Then, as a minimum, modify the code or add a function or subprogram to it. Debug and demonstrate the modified program to your counselor.
      b. With your counselor’s approval, choose a second programming language and development environment, different from those used for requirement 5a and in a different industry from 5a. Then write, debug, and demonstrate a functioning program to your counselor, using that language and environment.
      c. With your counselor’s approval, choose a third programming language and development environment, different from those used for requirements 5a and 5b and in a different industry from 5a or 5b. Then write, debug, and demonstrate a functioning program to your counselor, using that language and environment.
      d. Explain how the programs you wrote for requirements 5a, 5b, and 5c process inputs, how they make decisions based on those inputs, and how they provide outputs based on the decision making.

    6. Careers. Find out about three career opportunities in programming. Pick one and find out the education, training, and experience required. Discuss this with your counselor and explain why this career might be of interest to you.

  • Earning the Cyber Chip can help you learn how to stay safe while you are online and using social networks or the latest electronic gadgets.

    Topics include cell phone use, texting, blogging, gaming, cyberbullying, and identity theft. Find out more about the Cyber Chip at www.scouting.org/cyberchip.