0

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

我在 vba 项目的顶部将许多变量定义为公共变量(任何以“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
4

1 回答 1

0

vbYes从 . 返回时使用MsgBox

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

或者

确保您vbYes在以前的代码中的分配中使用。

于 2013-07-29T15:56:20.483 回答