Can't figure out why reading G4P combo text value in IF statement doesn't work

I’m maintaining a legacy P1.5 app. It works fine, and this question relates to code logic and why code that looks correct isn’t functioning as excepted.

My user selects a font from a drop-down list, and the font on-screen changes. I want to change line spacing with that selection by passing a value to a lineSpace variable when the drop-down value is chosen. This last part is not working.

I’m using a GP4 drop-down combo control, and it works fine for my user to select a font. I can pass the text property to my code to load a font. However, when I check the value of that same selected text, it’s not triggering my IF statement when true, rather it’s returning false and defaulting to the ELSE fallout value. The string I’m checking for is the same as the string value returned by the control, yet when checking if they match, I still get a false(?)

Here’s the code:

void combo1_Click1(GCombo combo) { //_CODE_:combo1:640786:
    println("combo1 - GCombo event occured. Font changed to " + combo1.selectedText() );
    u = loadFont(combo1.selectedText() +".vlw");
    
      if(combo1.selectedText() == "Times"){
        lineSpace = timesLineSpace;
        println("Times");
      }else if(combo1.selectedText() == "Arial"){
        lineSpace = arialLineSpace;
        println("Arial");
      }else if(combo1.selectedText() == "Square"){
        lineSpace = squareLineSpace;
        println("Square");
      }else if(combo1.selectedText() == "Script"){
        lineSpace = scriptLineSpace;
        println("Script");
      }else if(combo1.selectedText() == "Filled"){
        lineSpace = filledLineSpace;
        println("Filled");
      }else{
        lineSpace = customLineSpace;
        println("Else");
      }
}

So when the user selects “Script” the combo1.selectedText() value is “Script”, but combo1.selectedText() == "Script" returns false

I can println the selected value, so I know it’s getting through (also know this because the font changes), but the IF statement logic always returns false and resorts to the final ELSE value.

Any thoughts, suggestions or help are greatly appreciated.

final String s = combo1.selectedText();

if ("Times".equals(s)) {
1 Like

Perfect!!! That was the fastest forum reply ever! Many thanks. :smiling_face_with_three_hearts:

For anyone else looking for this later, here’s the working code (thanks to @GoToLoop )

void combo1_Click1(GCombo combo) { //_CODE_:combo1:640786:
    println("combo1 - GCombo event occured. Font changed to " + combo1.selectedText() );
    u = loadFont(combo1.selectedText() +".vlw");

    String s = combo1.selectedText();
      if("Times".equals(s)){
        lineSpace = timesLineSpace;
        println("Times");
      }else if("Arial".equals(s)){
        lineSpace = arialLineSpace;
        println("Arial");
      }else if("Square".equals(s)){
        lineSpace = squareLineSpace;
        println("Square");
      }else if("Script".equals(s)){
        lineSpace = scriptLineSpace;
        println("Script");
      }else if("Filled".equals(s)){
        lineSpace = filledLineSpace;
        println("Filled");
      }else{
        lineSpace = customLineSpace;
        println("Else");
      }
}