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) = '''
Pregunta técnica
Moderator: Rathinagiri
-
- Posts: 174
- Joined: Mon May 19, 2014 7:43 pm
- DBs Used: DBF, SQLite, MS-SQL, ACCESS, MariaDB (en proceso)
- Location: Morelia, Mich. México
- Contact:
Pregunta técnica
Cordialmente
POSADAS SOFTWARE
Jorge Posadas Ch.
Programador independiente
Morelia, Mich.
M é x i c o .
Movil +52 44 3734 1858
SKYPE: jorge.posadasch
Email: posoft@gmx.com
POSADAS SOFTWARE
Jorge Posadas Ch.
Programador independiente
Morelia, Mich.
M é x i c o .
Movil +52 44 3734 1858
SKYPE: jorge.posadasch
Email: posoft@gmx.com
Re: Pregunta técnica
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
Code: Select all
IF(cVariable) = ''
Code: Select all
IF cVariable = ''
It's better to use
Code: Select all
if len(cVariable) == 0
Code: Select all
if !(cVariable=="")
else
...
Re: Pregunta técnica
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
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
EMPTY function can be problematic in some cases, too.
If your string consists only from space characters (chr(32)), this function return .T.
If your string consists only from space characters (chr(32)), this function return .T.
- dragancesu
- Posts: 921
- Joined: Mon Jun 24, 2013 11:53 am
- DBs Used: DBF, MySQL, Oracle
- Location: Subotica, Serbia
Re: Pregunta técnica
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
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