首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在Excel函数中声明变量?

如何在Excel函数中声明变量?
EN

Stack Overflow用户
提问于 2017-04-09 13:02:56
回答 2查看 292关注 0票数 0

更新后

我改变了密码就像。

代码语言:javascript
复制
Option Explicit
Public Function Isokinectic(streamVelocity As Double, sampleVelocity As Double, probeDiameter As Double, density As Double, particleDiameter As Double, viscosity As Double)

        Dim s As Double
        Dim stk_coefficent As Double
        Dim stk As Double
        Dim d As Double

        s = ((0.16 * 10 ^ -4) / particleDiameter) + 1
        stk_coefficent = (1 / (18 * viscosity)) * density * particleDiameter * particleDiameter * s
        stk = (streamVelocity / probeDiameter) * stk_coefficent
        d = 1 + (2 + 0.62 * (sampleVelocity / streamVelocity)) * stk
        Isokinectic = 1 + ((streamVelocity / sampleVelocity) - 1) * (1 - 1 / (d))

End Function

但不起作用。但是,当添加sub ()时,如下所示。它起作用了。

代码语言:javascript
复制
Option Explicit
Function Isokinectic(streamVelocity As Double, sampleVelocity As Double, probeDiameter As Double, density As Double, particleDiameter As Double, viscosity As Double)

        Dim s As Double
        Dim stk_coefficent As Double
        Dim stk As Double
        Dim d As Double

        s = ((0.16 * 10 ^ -4) / particleDiameter) + 1
        stk_coefficent = (1 / (18 * viscosity)) * density * particleDiameter * particleDiameter * s
        stk = (streamVelocity / probeDiameter) * stk_coefficent
        d = 1 + (2 + 0.62 * (sampleVelocity / streamVelocity)) * stk
        Isokinectic = 1 + ((streamVelocity / sampleVelocity) - 1) * (1 - 1 / (d))

End Function

Sub MAIN()
    MsgBox Isokinectic(0.1, 0.2, 0.3, 0.4, 0.5, 0.6)
End Sub

原文:

我试着用excel函数编写一个方程。但我得到了#价值

代码语言:javascript
复制
Function Isokinectic(streamVelocity As Double, sampleVelocity As Double, probeDiameter As Double, density As Double, particleDiamter As Double, visocity As Double)

        Dim s As Double
        Dim stk_coefficent As Double
        Dim stk As Double
        Dim d As Double

        s = (0.16 * 10^ - 4 / particleDiameter) + 1

        stk_coefficent = (1 / (18 * viscosity)) * density * particleDiamter * particleDiameter * s

        stk = (streamVelocity / probeDiameter) * stk_coefficent

        d = 1 + (2 + 0.62 * (sampleVelocity / streamVelocity)) * stk

        Isokinectic = 1 + ((streamVelocity / sampleVelocity) - 1) * (1 - 1 / (1 + d))

        End Function

我在这代码里做错什么了吗?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2017-04-09 13:47:57

稍微清理一下:

代码语言:javascript
复制
Option Explicit
Function Isokinectic(streamVelocity As Double, sampleVelocity As Double, probeDiameter As Double, density As Double, particleDiameter As Double, viscosity As Double)

        Dim s As Double
        Dim stk_coefficent As Double
        Dim stk As Double
        Dim d As Double

        s = ((0.16 * 10 ^ -4) / particleDiameter) + 1
        stk_coefficent = (1 / (18 * viscosity)) * density * particleDiameter * particleDiameter * s
        stk = (streamVelocity / probeDiameter) * stk_coefficent
        d = 1 + (2 + 0.62 * (sampleVelocity / streamVelocity)) * stk
        Isokinectic = 1 + ((streamVelocity / sampleVelocity) - 1) * (1 - 1 / (1 + d))

End Function

Sub MAIN()
    MsgBox Isokinectic(0.1, 0.2, 0.3, 0.4, 0.5, 0.6)
End Sub

票数 0
EN

Stack Overflow用户

发布于 2017-04-09 15:48:28

在您最初的文章中,您已经计算了s,d,stk,但是在后面的阶段中,您没有得到值的值&其他,是值错误的原因。由于您在公式中使用了一个子程序,所以请将函数中的命令行写入函数中,不要忘记从单元格中传递值。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43306981

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档