Announcement

Collapse
No announcement yet.

basic if statement wont work ?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • basic if statement wont work ?

    Code as follows :
    #platform "uLCD-32PT_GFX2"
    func main()
    var test :="01";
    putstr(test);
    if(test =="01") putstr("\nTest = 01");endif
    putstr(" This works");
    repeatforeverendfunc

    Have had heaps of issues with the compiler and ended up doing a sanity check with the above code and it failed, or I did. Can one not do " string comparisons ?Any ideas / suggestions ?

  • #2


    4DGL is very much like C, there is no string type.
    var test :="01";

    that is simply creating a string, and var test
    points to the strings address.

    eg, if you were to

    print(test); // show address of stored string
    print([STR] test); // show string stored at address
    putstr(test); // ditto

    later on where your code is:-

    if(test =="01")

    it is syntactically correct, but what's happening is that test is being compared
    to a new instance of a string "01" at a different address, therefore there will be no match.
    Regards,
    Dave

    Comment

    Working...
    X