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

**URL:** <https://discourse.processing.org/t/cant-figure-out-why-reading-g4p-combo-text-value-in-if-statement-doesnt-work/41480>\
**Category:** Libraries\
**Created:** [March 27, 2023, 9:02pm UTC](https://discourse.processing.org/t/cant-figure-out-why-reading-g4p-combo-text-value-in-if-statement-doesnt-work/41480 "2023-03-27T21:02:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![hondaman900](https://avatars.discourse-cdn.com/v4/letter/h/eada6e/32.png) [@hondaman900](https://discourse.processing.org/u/hondaman900)\
**Post date:** [March 27, 2023, 9:02pm UTC](https://discourse.processing.org/t/cant-figure-out-why-reading-g4p-combo-text-value-in-if-statement-doesnt-work/41480/1 "2023-03-27T21:02:03Z")

</div>

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:

```auto
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.

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [March 27, 2023, 9:04pm UTC](https://discourse.processing.org/t/cant-figure-out-why-reading-g4p-combo-text-value-in-if-statement-doesnt-work/41480/2 "2023-03-27T21:04:05Z")

</div>

> **[equals() / Reference](https://processing.org/reference/String_equals_.html)**
>
> Compares two strings to see if they are the same. This method is necessary because it's not possible to compare strings using the equality operator (==). Returns true if the strings are the sam…

> [@hondaman900](#):
>
> `if(combo1.selectedText() == "Times"){`

```auto
final String s = combo1.selectedText();

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

```

---

<div class="post-metadata">

**Author:** ![hondaman900](https://avatars.discourse-cdn.com/v4/letter/h/eada6e/32.png) [@hondaman900](https://discourse.processing.org/u/hondaman900)\
**Post date:** [March 27, 2023, 9:13pm UTC](https://discourse.processing.org/t/cant-figure-out-why-reading-g4p-combo-text-value-in-if-statement-doesnt-work/41480/3 "2023-03-27T21:13:38Z")

</div>

> [@GoToLoop](#):
>
> `.equals(s)`

**Perfect!!!** That was the fastest forum reply ever! Many thanks. 🥰

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

```auto
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");
      }
}

```
