Vb6 ByRef参数类型不匹配

Vb6 ByRef参数类型不匹配,vb6,call,Vb6,Call,我写的代码只是整个代码的一部分,因为我只想测试part子过程是否可以运行。当我运行时,会出现一条消息:By Ref参数不匹配。我不熟悉使用call调用子过程。任何人请帮帮我 Dim Age As Integer Dim Weight, Heights, BMI, BMR As Single Dim MenBMR, WomenBMR As Single Private Sub cmdBMI_Click() If Age > 20 Then Call AdultBMI(BMI) End En

我写的代码只是整个代码的一部分,因为我只想测试part子过程是否可以运行。当我运行时,会出现一条消息:By Ref参数不匹配。我不熟悉使用call调用子过程。任何人请帮帮我

Dim Age As Integer
Dim Weight, Heights, BMI, BMR As Single
Dim MenBMR, WomenBMR As Single

Private Sub cmdBMI_Click()
If Age > 20 Then
Call AdultBMI(BMI)
End
End Sub

Private Sub AdultBMI(BMI As Single, Weights As Single, Heights As Single)
Age = Val(txtAge.Text)
Weight = Val(txtWeight.Text)
Heights = Val(txtHeight.Text)
BMI = Weight / ((Heights / 100) ^ 2)

If BMI < 18.5 Then
txtBMIValue.Text = BMI
txtBMIStatus.Text = "Underweight"
MsgBox ("You are underweight!")
End
End Sub
Dim Age作为整数
单侧低体重、身高、BMI、BMR
昏暗的男人,单身的女人
专用子cmdBMI_Click()
如果年龄>20岁,则
呼叫成人BMI(BMI)
终点
端接头
私人亚成年BMI(BMI为单体,体重为单体,身高为单体)
Age=Val(txtAge.Text)
Weight=Val(txtwweight.Text)
高度=Val(txtHeight.Text)
体重指数=体重/((身高/100)^2)
如果BMI<18.5,则
txtbimvalue.Text=BMI
txtBMIStatus.Text=“体重不足”
MsgBox(“你体重不足!”)
终点
端接头

BMI
是一种变体

在下面这行

Dim Weight, Heights, BMI, BMR As Single
体重
身高
体重指数
都是变量。在VB6中,使用逗号时必须显式提供每个变量的类型。试试这个

Dim Weight As Single, Heights As Single, BMI As Single, BMR As Single

好的,这段代码有很多问题,我会尽可能多地解决

您已经为子程序成人BMI设置了BMI、体重和身高参数,但您将它们用作子程序中的局部变量。参数用于从子程序外部引入值。请参阅下文,了解我将如何更改您的代码

当您调用AdultBMI时,您只给了它一个参数,而不是例程所期望的三个参数,这就是为什么您会得到一个错误

在End Sub之前有一个End语句。End将立即终止程序。您需要使用“如果结束”

理想情况下,成人BMI子例程是一个函数,它接受两个参数体重和身高,然后返回BMI:

Private Sub Command1_Click()
    Dim BMI As Double
    BMI = AdultBMI(Val(txtHeight.Text), Val(txtWeight.Text))
    If BMI < 18.5 Then
        MsgBox "Underweight"
    End If
End Sub
Private Function AdultBMI(ByVal Height As Double, ByVal Weight As Double) As Double
    AdultBMI = Weight / ((Height / 100) ^ 2)
End Function
Private子命令1_Click()
双倍体质量指数
体重指数=成人体重指数(Val(txtweath.Text),Val(txtweaght.Text))
如果BMI<18.5,则
MsgBox“重量不足”
如果结束
端接头
私人功能成人BMI(ByVal身高加倍,ByVal体重加倍)加倍
成人体重指数=体重/((身高/100)^2)
端函数
我认为您需要更多地了解变量和作用域,因为它将在您进行编程时很好地为您服务。

您有一个名为
AdultBMI()
,它接受函数定义中的三个参数

您仅使用一个参数调用此函数。剩下的两个呢

你的定义是

Private Sub AdultBMI(BMI As Single, Weights As Single, Heights As Single)
    Age = Val(txtAge.Text)
    Weight = Val(txtWeight.Text)
    Heights = Val(txtHeight.Text)
    BMI = Weight / ((Heights / 100) ^ 2)

    If BMI < 18.5 Then
    txtBMIValue.Text = BMI
    txtBMIStatus.Text = "Underweight"
    MsgBox ("You are underweight!")
End
End Sub

谢谢!真的很有帮助,因为我对VisualBasic ^^^@shirley还不太熟悉,因为我看了你的代码,你似乎想一下子学会所有东西。一步一步地学习。
Dim Age As Integer
Dim Weight As Single, Heights As Single, BMI As Single, BMR As Single
Dim MenBMR As Single, WomenBMR As Single

Private Sub cmdBMI_Click()
    If Age > 20 Then
    Call AdultBMI()
End Sub

Private Sub AdultBMI()
    Age = Val(txtAge.Text)
    Weight = Val(txtWeight.Text)
    Heights = Val(txtHeight.Text)
    BMI = Weight / ((Heights / 100) ^ 2)

    If BMI < 18.5 Then
        txtBMIValue.Text = BMI
        txtBMIStatus.Text = "Underweight"
        MsgBox ("You are underweight!")
End Sub