Page 1 of 1

Su ayuda con este código

PostPosted: Fri Mar 11, 2022 11:46 pm
by Armando
Hola Amigos del foro:

Por favor ayúdenme a entender este simple y sencillo código

Code: Select all  Expand view

   ? "Texto" <> ""
   ? "Texto" == ""
 


Ambos me devuelven FALSE, y mi lógica me dice que la primera comparación
debería ser TRUE, será que la noche ha sido larga? :cry:

Saludos

Re: Su ayuda con este código

PostPosted: Sat Mar 12, 2022 12:17 am
by cnavarro

Re: Su ayuda con este código

PostPosted: Sat Mar 12, 2022 3:12 am
by Armando
Cristóbal:

Perfecto, me estaba volviendo loco :oops: .

Saludos

Re: Su ayuda con este código

PostPosted: Sat Mar 12, 2022 5:38 am
by nageswaragunupudi
Use
? !( "TextTo" == "" )
This does not require changing SET EXACT.
Please note that setting SET EXACT ON will have global effect and somewhere some comparisons may give different results.

Re: Su ayuda con este código

PostPosted: Sat Mar 12, 2022 7:18 am
by Armando
Mr. Rao:

Thanks a lot.

Best regards

Re: Su ayuda con este código

PostPosted: Sat Mar 12, 2022 9:20 am
by Enrico Maria Giordano
The opposite of

Code: Select all  Expand view
? "Texto" <> ""


is

Code: Select all  Expand view
? "Texto" = ""


EMG

Re: Su ayuda con este código

PostPosted: Sat Mar 12, 2022 11:16 am
by cnavarro
nageswaragunupudi wrote:Use
? !( "TextTo" == "" )
This does not require changing SET EXACT.
Please note that setting SET EXACT ON will have global effect and somewhere some comparisons may give different results.


Dear Rao
Do you mean that what we have to do is induce our code to obtain the result that we expect and that it is not harbour, using the commands and functions that it provides us, that resolves the expression?
So, let's not put the expression (!) and put directly ( ? .T. ) or ( ? .F. ) depending on the result you want to obtain, right? It would be much simpler ( it's a joke ).
The colleague's question is why he obtains that result when the expression is evaluated, I don't think he should be induced as to how it would be resolved to obtain the expected result, that should be done by Harbour.
Use SET EXACT ON and SET EXACT OFF when needed, that's my advice

Quiere decir usted que lo que hay que hacer es inducir a nuestro codigo a obtener el resultado que nosotros esperamos y que no sea harbour, usando los comandos y funciones que nos proporciona, el que resuelva la expresión?
Entonces, no pongamos la expresion (!) y ponga directamente ( ? .T. ) o ( ? .F. ) dependiendo del resultado que usted desea obtener, no?, sería mucho más sencillo ( es una broma ).
La pregunta del compañero es por qué obtiene ese resultado al ser evaluada la expresión, no creo que se le deba inducir a como se resolvería para obtener el resultado esperado, eso debe hacerlo Harbour.
Use SET EXACT ON y SET EXACT OFF cuando se necesite, ese es mi consejo


Armando, por favor, prueba este codigo ( sin el SET EXACT ON )
Code: Select all  Expand view

? "" <> "Text"
 

Re: Su ayuda con este código

PostPosted: Sat Mar 12, 2022 3:41 pm
by Armando
Cristóbal:

? "" <> "Text"

Funciona como se espera, retorna (.T.)

Pero
? "Texto" <> ""
No funciona como se espera, retorna (.F.)

Me estoy volviendo loco

Saludos

Re: Su ayuda con este código

PostPosted: Sat Mar 12, 2022 3:55 pm
by Enrico Maria Giordano
As I wrote, "Text" <> "" is the opposite of "Text" = "", so

Code: Select all  Expand view
? "Text" <> ""


gives .F. because it is the opposite of

Code: Select all  Expand view
"Text" = ""


that gives .T. because "Text" begins with "" (any strings contain or begins with ""). Moreover

Code: Select all  Expand view
"" <> "Text"


gives .T. because it is the opposite of

Code: Select all  Expand view
"" = "Text"


that gives .F. because "" (the empty string) doesn't begin with "Text".

EMG

Re: Su ayuda con este código

PostPosted: Sat Mar 12, 2022 10:01 pm
by cnavarro
Enrico, I totally agree with you.