Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2010 Barcelona Spain September 2010 Proceedings Part 2 Lnai 6322

Authors: Jose L. Balcazar ,Francesco Bonchi ,Aristides Gionis ,Michele Sebag

2010th Edition

364215882X, 978-3642158827

More Books

Students also viewed these Databases questions

Question

Are you exposed to any hazards or unusual working conditions?

Answered: 1 week ago