【发布时间】:2017-12-08 02:27:12
【问题描述】:
我在 VBA 中有一些代码是这样的:
Sub UserForm2_Activate()
....
If [statement] then
Label1.caption = x
Label2.caption = x*y
Else
...
当我使用来自另一个标签的这些标签(使用 UserForm2.Show)激活用户窗体时,结果是 Label1 = x,Label2 = 0。但是当我从即时窗口尝试“UserForm2.Show”时,一切正常我得到了正确的数据。
我做错了什么?
实际代码:
If Sheets("SL").Range("B8").Value = True Then
Label8.Caption = Find_cost(Sheets("SL").Range("b5").Value, Sheets("SL").Range("B4").Value, "ID")
Label20.Caption = Find_cost(Sheets("SL").Range("b5").Value, Sheets("SL").Range("B4").Value, "ID") * Sheets("SL").Range("b4").Value
Else
Label8.Caption = "none"
Label20.Caption = "none"
End If
其中“Find_cost”是一个自定义函数
【问题讨论】:
-
将您的实际代码设置为
x和y。 -
你什么时候打电话给Show?
-
是
string类型函数还是integer类型?可能您需要对x和yvalue 进行一些转换。 -
x和y在哪里以及如何声明和填充? -
@harun24hr 它们都是整数。但是,函数中的第二个参数是“Long”。我想我需要检查函数的输出