Question
Visual Basic program : I need your help to fix the two error in my program. When I start the program I select Metric in
Visual Basic program: I need your help to fix the two error in my program. When I start the program I select Metric in the ListBox, the results in BMI Value is 0.00 and when I also select the Imperial the results in BMI Value is 0.00. Find attached the VB program for your perusal.
Public Class Form1
'Create array with Metric, Imperial
Dim conversionType() As String = {"Metric", "Imperial"}
Private Sub btnCalculate_Click(sender As Object, e As EventArgs) Handles btnCalculate.Click
Dim type As String
Dim weight As Decimal = 0
Dim height As Decimal = 0
Dim bmiValue As Decimal = 0
'Add converstionType array to typeListBox
typeListBox.Items.AddRange(conversionType)
type = typeListBox.SelectedItem
'Get weight from the weight text box
Decimal.TryParse(txtWeight.Text, weight)
'Get height from the height text box
Decimal.TryParse(txtHeight.Text, height)
'Check if type is Metric
If type = "Metric" Then
bmiValue = bmiMetric(weight, height).ToString()
'Check if type is Imperial
ElseIf type = "Imperial" Then
bmiValue = bmiImperial(weight, height).ToString()
End If
'Set bmiLabel text to bmi value
bmiLabel.Text = bmiValue.ToString("N2")
End Sub
'Procedure that take weight and height and returns BMI in metric
Function bmiMetric(weight As Decimal, height As Decimal) As Decimal
Dim BMI As Decimal = 0
BMI = (weight / (height * height))
Return BMI
End Function
'Procedure that take weight and height and returns BMI in imperial
Function bmiImperial(weight As Decimal, height As Decimal) As Decimal
Dim BMI As Decimal = 0
BMI = (weight / (height * height)) * 703
Return BMI
End Function
Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click
Me.Close()
End Sub
End Class
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started