我该如何解决这个问题VB code? [未参数指定的参数] [英] How do I fix this VB code? [Argument not specified for parameter]
本文介绍了我该如何解决这个问题VB code? [未参数指定的参数]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我挣扎得到这code的工作:
I'm struggling to get this code to work:
Module Module1
Function BMI(ByVal H, ByVal W)
BMI = (W / H) ^ 2
Return BMI
End Function
Function reading(ByVal BMI)
If BMI <= 19 Then
reading = "Underweight"
ElseIf BMI >= -20 <= 25 Then
reading = "Perfect"
ElseIf BMI >= 26 <= 30 Then
reading = "Slightly Overweight"
ElseIf BMI >= 31 <= 40 Then
reading = "Overweight"
ElseIf BMI >= 41 Then
reading = "Obese"
End If
Return reading
End Function
Sub Main()
Dim height, weight As Integer
Console.Write("What is your height? ")
height = Console.ReadLine
Console.Write("What is your weight? ")
weight = Console.ReadLine
BMI(height, weight)
reading(BMI)
End Sub
End Module
我得知'阅读(BMI)'有'参数未指定参数''的'公职BMI(H为对象,W作为对象)作为对象W'。
I'm informed that 'reading(BMI)' has an 'argument not specified for parameter 'W' of 'Public Function BMI(H As Object, W As Object) As Object.'
请有人可以帮我解决这个问题?
Please can someone help me fix this?
推荐答案
下面是你的code再分解了一下。它没有任何错误的用户输入检查。如果你在公制单位工作删除公式中* 703
部分:
Here's your code re-factored a bit. It doesn't have any error checking on the user inputs. If you're working in metric units remove the * 703
part in the formula:
Module Module1
Sub Main()
Dim height, weight As Integer
Console.Write("What is your height in inches? ")
height = Console.ReadLine
Console.Write("What is your weight in pounds? ")
weight = Console.ReadLine
Dim BMI As Integer = CalculateBMI(height, weight)
Dim Category As String = reading(BMI)
Console.WriteLine(String.Format("Your BMI is {0}, which is {1}.", BMI, Category))
Console.Write("Press Enter to Quit")
Console.ReadLine()
End Sub
Function CalculateBMI(ByVal H As Integer, ByVal W As Integer) As Integer
Return CDbl(W * 703) / Math.Pow(H, 2)
End Function
Function reading(ByVal BMI As Integer) As String
Select Case BMI
Case Is <= 19
Return "Underweight"
Case 20 To 25
Return "Perfect"
Case 26 To 30
Return "Slightly Overweight"
Case 31 To 40
Return "Overweight"
Case Else
Return "Obese"
End Select
End Function
End Module
这篇关于我该如何解决这个问题VB code? [未参数指定的参数]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文