Page 1 of 1

IF

Posted: Thu Mar 12, 2020 7:22 pm
by luiscambuston
I am running this simple code

cUserName := "Luis"

If cUserName <> ""
? "Not Empty"
Else
? "Empty"
EndIf

The response is "Empty".
I tried everything that I can think.
Driving me crazy...

Thanks

Re: IF

Posted: Thu Mar 12, 2020 11:03 pm
by stefano
Try

if len(alltrim(cUserName )) > 0

Re: IF

Posted: Fri Mar 13, 2020 3:44 am
by Antonio Linares
Luis,

Code: Select all

If ! cUserName == ""
   ? "Not Empty"
Else
   ? "Empty"
EndIf

Re: IF

Posted: Sat Mar 14, 2020 4:01 pm
by MarcoBoschi

Code: Select all

[#include "Set.ch"
FUNCTION MAIN()

? set(_SET_EXACT )
cUserName := "Luis"

If cUserName <> ""
? "Not Empty"
Else
? "Empty"
EndIf

SET EXACT ON
? set(_SET_EXACT )

cUserName := "Luis"

If cUserName <> ""
? "Not Empty"
Else
? "Empty"
EndIf


RETURN NIL
 


SET EXACT
Determines the mode for character string comparison.
Syntax
SET EXACT on | OFF | ( <lOnOff> )

Arguments
on | OFF | ( <lOnOff> )
on | OFF | ( <lOnOff> )
This option toggles if an exact comparison is performed with character strings. or not.
The default is OFF or .F. (false), i.e. characters are compared up the length of the shorter string.
To change the setting use ON or .T. (true) as parameter.
The parameter can also be specified as a logical expression enclosed in parentheses.

Re: IF

Posted: Sat Mar 14, 2020 10:39 pm
by luiscambuston
Basically this ! variable == "" works
This variable <> "" does not
this variable != "" does not....