简体   繁体   English

来自变量定义的明显不正确的值?

[英]Apparent incorrect value from variable definition?

New to VBA and lousy at it, so please be gentle! VBA的新手,很糟糕,所以请保持温柔!

I have the following code which gives the Long type variable "EIa" a value. 我有以下代码为Long类型变量“ EIa”赋予一个值。 I was getting a bunch of odd results later down the code so I put in some Debug.Print lines to find my issue and notice that when I Debug.Print the variable EIa, I get 0 but if I Debug.Print EXACTLY the expression that defines EIa, I get the expected value. 我在代码后面得到了一堆奇怪的结果,所以我放了一些Debug.Print行来查找我的问题,并注意到当我进行Debug.Print变量EIa时,我得到0,但是如果我进行Debug.Print精确地表达该表达式,定义EIa,我得到了期望值。 Code below, any ideas? 下面的代码,有什么想法吗?

        'Calculate mA1:
'****************************************************************************************************
EIa = Etimber * ImatA / (Etimber * (ImatA + ImatB + ImatC + ImatD))
Debug.Print "EIa = "; EIa
Debug.Print "EIa = "; Etimber * ImatA / (Etimber * (ImatA + ImatB + ImatC + ImatD))
mA1 = 12 * 0.5 * (q1PSF * EIa) * bMat * LcantiA ^ 2 '12 puts this into lb-in
    If LmatSymA = 0 Then
        fbA1 = 0
    Else
        fbA1 = (mA1 * (0.5 * tMatA) / ImatA)
    End If

The result of the expression is a kind of fractional, floating point number, but since you defined EIa as Long (a large integer), it gets truncated to zero upon assignment. 表达式的结果是一种小数浮点数,但是由于您将EIa定义为Long(大整数),因此在赋值时它会被截断为零。 See Visual Basic Data Types . 请参见Visual Basic数据类型

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM