What are you doing? Students will be guided through a Units Conversion program using Visual Basic.
Why are you doing it? To develop the foundations of computer science and basic programming, with an emphasis on helping students develop logical thinking and problem solving skills.
What tools are you using? Class posts, Visual Basic.
How will you know you are successful? You will have created a UnitConverter app using Visual Basic. You will understand the steps to use variables in Visual Basic: declare, assign value, display value; converting text input to numeric values; Case Statements to select from multiple options.
App Objective: Students will use VB.net to create an app to make unit conversions as chosen by the user. The app should be able to convert the following:
– km to Miles
– Miles to km
– Meters to Feet (or yards)
– Feet to Meters
– Ounces to Grams
– Grams to Ounces
– At least 4 other unit conversions of your choice.
– Numeric Variables
– Converting Text to Number
– Case Statements
With a partner, plan the design for the UNIT CONVERSION APP. The design should include:
– Window layout for the app, indicate the type of each control (i.e. comboBox, textBox, label)
– Variables needed
– Calculations for conversions
– Data displayed to user
– Attractive form design. The minimum controls required are: ComboBox to choose conversion type; Textbox to enter value to convert; Label that displays ‘convert to’ based on ComboBox selection; Label that displays conversion rate; Label that displays result of conversion; Button or Menu Item to calculate the conversion; Button or Menu Item to Exit the app.
– Correct names (use camelCase) for all form controls; i.e. no Label1; Project Name = pd_lastName_convertUnits
– At least 12 types of unit conversions, see above.
– Click ‘Convert’ button: Conversion is calculated and displayed.
– When finished: have at least 1 other student test your program, grade program (12 pts possible) à report grade to Fornstrom.
– Variables in VB: declare, assign value, display value
– Numeric Variables
The most common numeric variables in VB are integer and real (declared as Double) . To declare each:
Dim intNumber as Integer
Dim realNumber as Double
– Converting Text to Number: required because text boxes read all input as strings and we need to tell it to view the input as a number. Code below takes number input from text box, converts, and stores in a variable of type Double named converVal:
convertVal = Val(txtConvertVal.Text)
– Case Statements: are used to make a selection from multiple choices. The code below uses a variable named convertFrom to calculate what to put in variables named convertTo and convertRate.
‘ Step 1: declare variables
Dim convertFrom as string
Dim convertTo as String
Dim convertRate as Double
‘ Step 2: populate variables
convertFrom = cbConvertFrom.text
Select Case convertFrom
convertTo = “km”
convertRate = 1.609344
convertTo = “Miles”
convertRate = 0.621371
‘ Step 3: Display variables on the screen
lblConvertTo.text = convertTo
lblConvertFrom.text = convertFrom
lblConvertRate.text = convertRate