VBA If包含公共变量的语句错误类型不匹配(错误13)

时间:2013-07-29 15:09:46

标签: vba if-statement global-variables public

我认为这可能是一个快速解决方案,但整个上午一直困扰着我。

我已经在vba项目的顶部将许多变量定义为public(任何以“yn”结尾的变量都是String,其余变量是Variant或Single)。整个项目中的不同潜艇通过一系列问题和答案来定义这些变量。现在最后,当我尝试将定义的变量编译成等式时,我收到了一个错误。

上周我已经使用不同的最终方程式做了同样的过程,并且运行正常。我检查了每个变量,以确保它输入正确,我看不出代码有什么问题。请帮忙!谢谢!

    Public Sub Rth1 ()

    Dim Red1th as single

    If Width1thyn = vbYes Then
        If Length1thyn = vbYes Then
            If V1turnspeedyn = vbYes Then
                Red1th = ((Width1th + 20) / (1.47 * 20)) - 1
            Else
                Red1th = ((Width1th + 20) / (1.47 * V1turnspeedstudy)) - 1
            End If
        Else
            If V1turnspeedyn = vbYes Then
                Red1th = ((Width1th + Length1thstudy) / (1.47 * 20)) - 1
            Else
                Red1th = ((Width1th + Length1thstudy) / (1.47 * V1turnspeedstudy)) - 1
            End If
        End If
    Else
        If Length1thyn = vbYes Then
            If V1turnspeedyn = vbYes Then
                Red1th = ((Width1thstudy + 20) / (1.47 * 20)) - 1
            Else
                Red1th = ((Width1thstudy + 20) / (1.47 * V1turnspeedstudy)) - 1
            End If
        Else
            If V1turnspeedyn = vbYes Then
                Red1th = ((Width1thstudy + Length1thstudy) / (1.47 * 20)) - 1
            Else
                Red1th = ((Width1thstudy + Length1thstudy) / (1.47 * V1turnspeedstudy)) - 1
            End If
        End If
    End If

    MsgBox "Red Clearance Interval is " & Red1th, "vbOkOnly", "Red Clearance Interval"

    End Sub

1 个答案:

答案 0 :(得分:0)

vbYes返回时使用

MsgBox

如果您的变量不依赖于MsgBox返回,请考虑使用Boolean或分配您自己的枚举(避免使用vb已启动的名称),

确保您在之前的代码中使用了vbYes

相关问题