Page 1 of 1
Pregunta técnica
Posted: Tue Jul 17, 2018 10:43 pm
by jorge.posadas
Grupo
¿Qué es mejor usar?
1- IF .NOT. MyFunction()
::
::
ENDIF
o esta
2. IF !MyFunction
::
::
ENDIF
es decir es mejor usar .NOT. o !
De antemano agraezco el comentario, y la pregunta surge porque en SQL cuando se valora una variable es mejor usar IF LEN(cvariable) = 0 a usar IF(cVariable) = '''
Re: Pregunta técnica
Posted: Wed Jul 18, 2018 6:04 am
by mol
There is a problem with such a construction for testing empty string:
In my opinion, it should look like this:
but, this statement always return .t.
It's better to use
or
Re: Pregunta técnica
Posted: Wed Jul 18, 2018 9:31 am
by Anand
Agree with Mol.
better use 'If Empty(cVariable)' code to check if a variable is empty.
Using '=' is a mistake as the logic of it is to stop checking after reaching end of 'right side' text.
So, 'abcd' = 'ab' is true
but 'abcd' == 'ab' is false
So 'abcd' = '' will be always true
but 'abcd' == '' will be false.
Regards,
Anand
Re: Pregunta técnica
Posted: Wed Jul 18, 2018 11:55 am
by mol
EMPTY function can be problematic in some cases, too.
If your string consists only from space characters (chr(32)), this function return .T.
Re: Pregunta técnica
Posted: Thu Jul 19, 2018 6:56 am
by dragancesu
The main thing is to write a function
1. if you are using: IF myfunc()
then the function should be written to return TRUE or FALSE,
It's better for me because it's solved in one place
2. if you are using: _variable = myfunc()
then
IF _variable ...
see
http://www.oohg.org/cl53/ng11d14f.html