VBA功能仅适用于某些情况 [英] VBA Function only working for some cases

查看:60
本文介绍了VBA功能仅适用于某些情况的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好:


我创建了一个函数,它返回所选每种材质的单个样品重量


我的函数接受5个参数:

1)matType-用户选择的材料

2)batchWeight-每种材料的批量使用

3) SumCem-使用的水泥材料批次重量的总和

4)CemSingWt-水泥单个样品重量的总和

5)pigPercent-使用的颜料百分比


这是我的函数:

公共函数GetSingleWeight(matType为Integer,BatchWeight为Double,SumCem为Double,CemSingWt为Double,PigPerc为Double)As Double

''返回''DM_SingleSampWt''计算中每种材料的单个样品重量


Select Case matType

''水泥

案例1

GetSingleWeight = BatchWeight / 164.5

案例2,3

''课​​程,很好

GetSingleWeigh t = CemSingWt / SumCem * BatchWeight

案例4

''颜料

GetSingleWeight = CemSingWt * 453.5924 * PigPerc

结束选择

结束功能

我的连续子表单上有一个名为DM_SingleSampWt的未绑定文本框。此文本框的控件来源是:

Hello:

I have a function that I created that returns the single sample weight of each material that is selected

My function accepts 5 arguments:
1)matType-The material the user has selected
2)batchWeight-The batchweight of each material used
3)SumCem-Sum of the cement material batchweights used
4)CemSingWt- Sum of cement single sample weight
5)pigPercent- the percent of pigments being used

Here is my function:
Public Function GetSingleWeight(matType As Integer, BatchWeight As Double, SumCem As Double, CemSingWt As Double, PigPerc As Double) As Double
''returns the single sample weight of each material in the ''DM_SingleSampWt'' calculation

Select Case matType
''Cement
Case 1
GetSingleWeight = BatchWeight / 164.5
Case 2, 3
''Course, Fine
GetSingleWeight = CemSingWt / SumCem * BatchWeight
Case 4
''Pigment
GetSingleWeight = CemSingWt * 453.5924 * PigPerc
End Select
End Function

I have an unbound text box on my continuous subform called DM_SingleSampWt. the control source for this text box is:

展开 | 选择 | Wrap | 行号

推荐答案

您的任何值是零还是null ?具体来说,你可能不得不说

GetSingleWeight = iif(SumCem = 0,0,CemSingWt / SumCem * BatchWeight)
Are any of your values zero or null? Specifically, you might have to say
GetSingleWeight = iif(SumCem = 0, 0, CemSingWt / SumCem * BatchWeight)


不,它们都不是零或空值;它们永远不会是0或null。在本例中的情况1中,SumCem为658,CemSingWt为4.
No, none of them are zero or null; they will never be 0 or null. In Case 1 in this instance, SumCem is 658 and CemSingWt is 4.


txtCemSum是一个设置为数字格式或字符串的文本框吗?
Is txtCemSum a text box set to Number format or a string?


这篇关于VBA功能仅适用于某些情况的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆