【发布时间】:2017-08-16 17:06:43
【问题描述】:
我正在尝试制作一个简单的 BMI 应用程序,并且我正在尝试获取它,以便当您输入您的体重和身高时,它会进行数学运算。
当然我得到“从'String'到'Double'的隐式转换”
这是一个问题:当我尝试将字符串转换为文本时,它给了我;但是现在当我在该行上只有 Option Strict 时,它在第 1 行上给了我错误。
所以我想知道如何使用正确的算术来解决这个问题?我从 VB.net 开始,现在只是不明白我在做什么。
我看过另一篇文章,但奇怪的是我仍在尝试弄清楚,因为我还没有了解 Double.TryParse()。
代码如下:
Dim strbmi As String
Dim strHeight As String
Dim strweight As String
Dim decbmi As Decimal
strweight = txtWeight.Text
strHeight = txtHeight.Text
strbmi = lblBMI.Text
If IsNumeric(txtHeight) Then
strHeight = Convert.ToString(txtHeight.Text)
End If
If IsNumeric(txtHeight) Then
strHeight = Convert.ToString(txtHeight.Text)
End If
If IsNumeric(txtWeight) Then
strweight = Convert.ToString(txtWeight.Text)
End If
If decbmi <= 18.5 Then
lblBMICategory.Text = "Underweight"
ElseIf decbmi <= 25 Then
lblBMICategory.Text = "Normal Weight"
ElseIf decbmi <= 30 Then
lblBMICategory.Text = "Overweight"
ElseIf decbmi > 30 Then
lblBMICategory.Text = "Obesity"
End If
【问题讨论】:
标签: vb.net vba visual-studio