-2

我使用包含 VBA 的软件,它具有完整的 vba 参考库以及自己的自定义内容。

所以我的问题与我假设的所有地方都应该相同的 vba 部分有关。

我有 5 个变量可以选择作为设定点(一次一个),我也有每个变量的反馈信号,显示它是打开还是关闭。

在表单的显示上,我有一个文本行,我想显示选择了哪个变量。

那么有没有办法编写一个代码“如果这个变量是真的显示它”?

感谢你们,

4

1 回答 1

0

完成我之前的回答后,我又再次阅读了你的问题,并意识到我写的可能不是你想要做的。

就像蒂姆说的,如果反馈信号不用于其他任何事情,而不是为每个选项设置一个变量,让选择设置文本。

Private Sub Selection1CommandButton_OnClick()

  Userform1.textdisplaybox.caption = "option1"

End Sub

或者也许检查组合框,下拉选择菜单。这可能将您要查找的所有内容合二为一。

原始答案如下。

我有点不确定您要问什么,但我认为您希望先前选择的选项仅在有信号时才显示在文本中。我不知道您将选择保留在哪里,现在我只是假设它是一个名为 selectedOption 的全局变量,其中 option1、option2 等被选中。

这样的事情可能是你正在尝试的:

Private sub

'If both the selected option is the first and the feedback signal
'is true, then set the display to that option
If selectedOption = option1 and variableSignal1 = True Then
       Userform1.textdisplaybox.caption = option1

'Option is the second and signal is true
ElseIf selectedOption = option2 and variableSignal2 = True Then
       Userform1.textdisplaybox.caption = option2
'However many else ifs you need, then if the signal is not true,
'blank the textbox
Else
       Userform1.textdisplaybox.caption = ""
Endif

End sub

如果信号要自行打开和关闭,那么您可以添加一个计时器并将其设置为超时。

于 2019-05-19T14:14:20.267 回答