Page 1 of 2

SetText() Failing

Posted: Tue Feb 22, 2022 5:09 pm
by UrbanCyborg
Got an issue with a call to VoltageLabel.SetText() failing to work when passed a blank string constant, i.e., "". Compiles fine, but doesn't do anything. I can't think of another way to zero out an Editable Text Label. Am I missing something Java-ish, or is there another way to phrase it?

Re: SetText() Failing

Posted: Tue Feb 22, 2022 6:10 pm
by honki-bobo
That's odd. In my Volt Meter module I do exactly that to clear the labels when no jack is connected and it works just fine.
Can you provide a bit more context, e.g. in which method do you call label.SetText(""), when do you call it...

Alternatively you could try using label.SetText(" "), a string with just a space character.

Re: SetText() Failing

Posted: Tue Feb 22, 2022 6:33 pm
by UrbanCyborg
Basically, I just can't make the values go away. Here's one usage that fails, in the button notifier:

Code: Select all

                else if(component == clearCaptionsButton) {
                    for(int iDex = 0; iDex < page1Caption.length; ++iDex) {
                        page1Caption[iDex].SetText("");
                        page1Active[iDex] = false;
                        page1Caption[iDex].SetVisible(false);
                        page2Caption[iDex].SetText("");
                        page2Active[iDex] = false;
                        page2Caption[iDex].SetVisible(false);
                        clearCaptionsButton.SetValue(0);
                    }
                }
It also fails in the Reset notifier, and a couple of other places where the value can be set to a null string. I'd rather not use a single space as a null, because there are a number of places where I test on that value, and I don't want to use a string that the user might have typed himself. That way lies madness...or at least, a mad user. :D

Re: SetText() Failing

Posted: Tue Feb 22, 2022 6:45 pm
by honki-bobo
If you're using this code in Notify() case Button_Changed you have created a loop by calling clearCaptionsButton.SetValue(0), and you're calling this for every label in your page1Caption array. That could be the cause of your problems. Why are you calling clearCaptionsButton.SetValue(0) anyways?

Re: SetText() Failing

Posted: Tue Feb 22, 2022 9:20 pm
by UrbanCyborg
Because otherwise, it'll be left in the wrong state. I guess maybe I should have made it a regular button, rather than a toggle. I gotta learn to quit recursing, curse it!

Re: SetText() Failing

Posted: Wed Feb 23, 2022 10:45 am
by honki-bobo
A quick fix would be

Code: Select all

else if(component == clearCaptionsButton && doubleValue > 0.5) {
    for(int iDex = 0; iDex < page1Caption.length; ++iDex) {
        page1Caption[iDex].SetText("");
        page1Active[iDex] = false;
        page1Caption[iDex].SetVisible(false);
        page2Caption[iDex].SetText("");
        page2Active[iDex] = false;
        page2Caption[iDex].SetVisible(false);
    }
    clearCaptionsButton.SetValueNoNotification(0, true);
}
That way it only clears the labels when the toggle is engaged and it resets the toggle just once outside of the for-loop without a call to Notify().

Re: SetText() Failing

Posted: Wed Feb 23, 2022 2:10 pm
by UrbanCyborg
Thanks, Martin. I just went ahead and changed the button to a non-toggle type and eliminated the offending instruction, and it works like a charm. Amazing how much that single recursion messed up.

Re: SetText() Failing

Posted: Sun Feb 27, 2022 6:47 pm
by UrbanCyborg
Quick follow-up question, Martin. Why did you test doubleValue against 0.5, rather than just testing for equality with 1.0 (or 1, which is documented as the active button state)? Is there some quirkiness that could cause the reported value to have drifted from it's documented value?

Re: SetText() Failing

Posted: Mon Feb 28, 2022 6:58 am
by honki-bobo
No particular reason, it's just what I got used to do when programming modules. You can test for doubleValue == 1 and it will work just the same.

Re: SetText() Failing

Posted: Wed Mar 02, 2022 6:46 pm
by seal58
By the way, I just had trouble with resetting toggle buttons too. I found that it is not possible to reset a toggle button, when it is part of a group (radio buttons). In this case it only works with setting another toggle button of that group.