【问题标题】:Schroedinger's label caption update薛定谔的标签说明更新
【发布时间】: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”是一个自定义函数

【问题讨论】:

  • 将您的实际代码设置为xy
  • 你什么时候打电话给Show?
  • string类型函数还是integer类型?可能您需要对xyvalue 进行一些转换。
  • xy 在哪里以及如何声明和填充?
  • @harun24hr 它们都是整数。但是,函数中的第二个参数是“Long”。我想我需要检查函数的输出

标签: vba excel


【解决方案1】:

使用 userform_initialize 事件而不是 userform_activate。此外,您应该将临时值保存在变量中并使用断点进行调试。

【讨论】:

  • 谢谢。我已经尝试过使用“初始化”,但它没有用。显然会使用很多断点
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-05-19
  • 2012-02-29
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多