-2

I use software that has VBA in it, it has the full vba library of references plus its own custom stuff.

So my question is related to the vba part that should be the same everywhere I assume.

I have 5 variables that someone can select as a set point (one at a time), I also have a feedback signal for each of the variables that shows if its on or off.

on the display in the form, I have a text line that I want to display whichever one of the variables is selected.

so is there a way to write a code that says "If this variable is true display it"?

thank you guys,

  • Basically whatever updates the variables would be responsible for updating the label(?) on the form. Difficult to say anything more specific than that given there's no real detail in your question. – Tim Williams May 09 '19 at 15:05

1 Answers1

0

Having finished my previous answer I went back to read over your question one more time and realized what I'd written was probably not what you were trying to do.

Like Tim said, if the feedback signal isn't used for anything else, rather than setting a variable for each option, have the selection set the text.

Private Sub Selection1CommandButton_OnClick()

  Userform1.textdisplaybox.caption = "option1"

End Sub

Or maybe check out combination boxes, the drop down selection menus. That might have everything you're looking for all in one.

Original answer follows.

I'm a little unsure on what you're asking, but I think you want the previously selected option to show up in the text only when it has a signal. I don't know where you're keeping the selection, for now I'm just going to assume it's a global variable named selectedOption with option1, option2 etc being selected.

Something like this might be what you're trying for:

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

If the signal is going to turn on and off on its own, then you could add a timer and put this in its timeout.

MorrisMoss
  • 1
  • 1
  • 2