|
Home > Archive > FoxPro Help and Support > January 2006 > = or == ???
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
|
| I'm new to Visual FoxPro (version 9).
? "A" = "" returns .T. not the answer I wanted!
? "A" = "B" returns .F.
? "A" == "" returns .F.
? "A" == "B" returns .F.
? "A" == "A" returns .T.
VFP help seems to say = is what I should be using. = seems to work most
times but not in = "". == seems to work everywhere I've used it so far.
I've seen this kind of thing before it's something to do with why
"CAT" = "C" returns .T. But "C" = "CAT" returns .F. Pleas refresh my
mind as to what's going on.
| |
| Anto Maric 2006-01-23, 11:25 am |
| See Set Exact in help
"cj" <cj@nospam.nospam> wrote in message
news:u$w0iSDIGHA.2948@TK2MSFTNGP10.phx.gbl...
> I'm new to Visual FoxPro (version 9).
>
> ? "A" = "" returns .T. not the answer I wanted!
> ? "A" = "B" returns .F.
> ? "A" == "" returns .F.
> ? "A" == "B" returns .F.
> ? "A" == "A" returns .T.
>
> VFP help seems to say = is what I should be using. = seems to work most
> times but not in = "". == seems to work everywhere I've used it so far.
> I've seen this kind of thing before it's something to do with why "CAT" =
> "C" returns .T. But "C" = "CAT" returns .F. Pleas refresh my mind as to
> what's going on.
| |
| Cindy Winegarden 2006-01-23, 11:25 am |
| In addition to Set Exact, Set Ansi governs how strings are compared in SQL
statements.
--
Cindy Winegarden MCSD, Microsoft Visual FoxPro MVP
cindy_winegarden@msn
.com www.cindywinegarden.com
"Anto Maric" <antomaric@hotmail.com> wrote in message
news:dr2u8i$93e$1@ss
405.t-com.hr...[color=darkred]
> See Set Exact in help
>
>
> "cj" <cj@nospam.nospam> wrote in message
> news:u$w0iSDIGHA.2948@TK2MSFTNGP10.phx.gbl...
| |
| Dan Freeman 2006-01-23, 11:25 am |
| It's an old xBase gotcha.
Strings are compared character by character until the string on the right
ends. If the string on the right ends and there has been no inequality, =
will return .t.
== is "exactly equal", but can at times carry a performance penalty.
See SET EXACT and SET ANSI in the help file.
Dan
cj wrote:
> I'm new to Visual FoxPro (version 9).
>
> ? "A" = "" returns .T. not the answer I wanted!
> ? "A" = "B" returns .F.
> ? "A" == "" returns .F.
> ? "A" == "B" returns .F.
> ? "A" == "A" returns .T.
>
> VFP help seems to say = is what I should be using. = seems to work
> most times but not in = "". == seems to work everywhere I've used it
> so far. I've seen this kind of thing before it's something to do
> with why "CAT" = "C" returns .T. But "C" = "CAT" returns .F. Pleas
> refresh my mind as to what's going on.
| |
| Olaf Doschke 2006-01-23, 11:25 am |
| > ? "A" = "" returns .T. not the answer I wanted!
> ? "A" = "B" returns .F.
> ? "A" == "" returns .F.
> ? "A" == "B" returns .F.
> ? "A" == "A" returns .T.
This is a feature, not a bug.
It helps to better find matches in table fields without
trimming whitespace.
That has always been a great advantage, since a C(n) field
of a table always is padded with spaces to it's full length
and so, if VFP would do exact match a where clause in some
SQL Select on a table with a C() field like cName would only
find matches with names that exactly fit into the field length
or you would need trimming. Eg cName = "cj" would have only
find CJs in a C(2) field. You would then need RTRIM(cName)="cj".
Beware, that with SET ANSI ON and/or SET EXACT ON you would
indeed need this where clause expression, which normally isn't
rushmore optimizable.
So all in all, it has much more advantages than disadvantages,
if you know when to use = and when ==.
In your special case you may really want ==. By the way, that
works independant on SET EXACT ON and/or SET ANSI ON. So you
can keep the SET EXACT OFF default setting for the reasons
explained above and still have exact matches with ==.
In several commands like ASCAN and others VFP9 introduced
flag parameters, with which you also can choose between exact
or "normal" (xBase) string comparison without switching the
EXACT and/or ANSI setting.
Bye, Olaf.
|
|
|
|
|