Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vba 如何使用visual Basic中的正确参数在另一个函数中调用函数_Vba_Function_Parameters - Fatal编程技术网

Vba 如何使用visual Basic中的正确参数在另一个函数中调用函数

Vba 如何使用visual Basic中的正确参数在另一个函数中调用函数,vba,function,parameters,Vba,Function,Parameters,我不断出错,它不允许我在其他函数中使用我的isworth函数: Private Function isworthy(ByVal home As Boolean) As Boolean Dim score As Double Dim income As Double If home = True Then Return "True" ElseIf score < 500 Then Return "False" ElseI

我不断出错,它不允许我在其他函数中使用我的
isworth
函数:

Private Function isworthy(ByVal home As Boolean) As Boolean
    Dim score As Double
    Dim income As Double
    If home = True Then
        Return "True"
    ElseIf score < 500 Then
        Return "False"
    ElseIf income >= 12000 Then
        Return "True"
    Else
        Return "False"
    End If
End Function

Private Function cardtype(ByVal score As Double, ByVal income As Double) As Double
    If isworthy() = False Then
        Return "N/A"
    ElseIf score >= 750 And income >= 20000 Then
        Return "Gold"
    ElseIf score >= 650 And income >= 15000 Then
        Return "Silver"
    Else
        Return "Basic"
    End If
End Function

Private Function interestrate(ByVal cardtype() As Double) As String
    If isworthy() = False Then
        Return "N/A"
    ElseIf cardtype() = "Gold" Then
        Return "2%"
    ElseIf cardtype() = "Silver" Then
        Return "8%"
    ElseIf cardtype() = "Basic" Then
        Return "22%"
    End If
End Function
私有函数值为布尔值(ByVal home为布尔值)
双杀
微薄的收入翻了一番
如果home=True,则
返回“True”
ElseIf评分<500分
返回“False”
如果收入>=12000,则
返回“True”
其他的
返回“False”
如果结束
端函数
私人功能卡类型(ByVal分数加倍,ByVal收入加倍)加倍
如果isworthy()=False,则
返回“不适用”
如果得分>=750,收入>=20000
返回“黄金”
ElseIf得分>=650,收入>=15000
返回“银”
其他的
返回“基本”
如果结束
端函数
私有函数interestrate(ByVal cardtype()作为Double)作为字符串
如果isworthy()=False,则
返回“不适用”
ElseIf cardtype()=“Gold”然后
返回“2%”
ElseIf cardtype()=“银色”则
返回“8%”
ElseIf cardtype()=“基本”然后
返回“22%”
如果结束
端函数
1)Isworth是私人的
2) Isworth在代码中的任何地方都不包含布尔值。

有几个问题:

Private Function isworthy(ByVal home As Boolean) As Boolean
    Dim score As Double
    Dim income As Double
    If home = True Then
        Return "True"
    ElseIf score < 500 Then
        Return "False"
    ElseIf income >= 12000 Then
        Return "True"
    Else
        Return "False"
    End If
End Function
私有函数值为布尔值(ByVal home为布尔值)
双杀
微薄的收入翻了一番
如果home=True,则
返回“True”
ElseIf评分<500分
返回“False”
如果收入>=12000,则
返回“True”
其他的
返回“False”
如果结束
端函数
如果VBA中有可能“重载”函数(有多个同名函数,但需要不同类型或数量的参数),则需要精确地调用它。你的函数定义说它接受一个布尔值作为参数,但是你调用它却没有给它一个参数。正确的调用应该是“isworthy(true)”,但“isworthy()”不起作用

此外,如果您正确地调用它,它仍然没有什么用处: 您将分数和收入设置为双倍,但未为其分配任何值。 因此,如果函数被调用,它将假定两者都为“0”,并始终返回false

基于此,我想说你需要更像这样的东西:

Private Function isworthy(ByVal home As Boolean, ByVal score As Double, ByVal income As Double) As Boolean
    If home = True Then
            Return "True"
        ElseIf score < 500 Then
            Return "False"
        ElseIf income >= 12000 Then
            Return "True"
        Else
            Return "False"
        End If
    End Function
Private Function值得(ByVal home作为布尔值,ByVal score作为Double,ByVal income作为Double)作为布尔值
如果home=True,则
返回“True”
ElseIf评分<500分
返回“False”
如果收入>=12000,则
返回“True”
其他的
返回“False”
如果结束
端函数
把它叫做:

Isworth(家、分数、收入)


在你至少能弄清楚你在用什么语言之前,我投票决定以不清楚的方式结束这个问题。您的标题说明了Visual Basic,但您将其标记为VBA和VisualC++(显然它不是)。如果你不知道你在用什么语言,你显然不能用它写代码。(您还应该学习阅读和理解您自己的代码(或您正在复制/粘贴的代码);如果您阅读并理解了,您会发现您的
isworth
声明需要一个参数,而您试图调用它的代码不会通过该参数。)