Download software: Download Visual Studio Community Edition
Instructions to setup software: Run the installation program that downloads from Microsoft. When you get to the workload selection page, make sure that you select the following workloads.
These workloads will install the tools that you will need for the examples on the Boy’s Life website.
1. Open Visual Studio Community Edition.
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. Hold down the Shift and F7 keys to open the design view for the file Form1.vb
6. Edit 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.
7. On the right side of Visual Studio, right click on the Form1.vb icon and select ‘View Code’ from the menu.
8. 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 }
9. Click on File then Save All from the program menu.
10. 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.
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.
http://www.vbtutor.net/ – A well organized tutorial with a lot of working examples and source code
Inspire Leadership, Foster Values: Donate to Scouting
When you give to Scouting, you are making it possible for young people to have extraordinary opportunities that will allow them to embrace their true potential and become the remarkable individuals they are destined to be.Donate Today