Re: Ascan with a Substr
- From: otto <ohaldi@xxxxxxxxxxx>
- Date: Mon, 05 Nov 2007 19:32:55 +0100
On Mon, 05 Nov 2007 06:11:27 -0000, diogenes <jjaeckel@xxxxxxxxx> wrote:
Hello Diogenes and Johan
Thanks for your help. The following solution work well
if Ascan(aFiltre, { |x| SubStr(x,2,3) == AGENDA->KST }) = 0
Regards
Otto
On Nov 2, 4:27 am, otto <oha...@xxxxxxxxxxx> wrote:.
Hello
How do I have to code a Ascan() with a SubStr() function ?
I like to see if the Substr(pos 2, Lenght 3) of AGENDA->KST is already in the array aFiltre.
This does not wordk !
if Ascan(aFiltre, { |x| SubStr(x,2,3) == AGENDA->KST })
Aadd(aFiltre, " " + AGENDA->KST + " " + AGENDA->JOB)
end
Thanks in advance for any help.
Otto
WHOOPS! Twice in a row now I accidentally clicked
on SEND before I meant to, thus sending you
incomplete responses. Sorry.
One more time:
Ok, here's my two bytes worth.
aScan(...) returns a NUMBER, so your code
needs to work with it that way. Hence,
the above suggestion:
if Ascan( aFiltre, SubStr(AGENDA->KST,2,3) ) <> 0
Aadd(aFiltre, " " + AGENDA->KST + " " + AGENDA->JOB)
end
comes closest to the mark. Myself, I would stick
with the code block so you can use the ==
operator to compare the strings. I think the
code block you originally used was just right,
assuming that AGENDA->KST is exactly a two-character
field.
But note: aScan(...) will return ZERO if the
string was NOT found, and non-zero if the string
IS found. So you should have:
if Ascan(aFiltre, { |x| SubStr(x,2,3) == AGENDA->KST }) = 0
Aadd(aFiltre, " " + AGENDA->KST + " " + AGENDA->JOB)
end
Note the = 0 test, rather than <> 0 test.
And note, you don't need to pre-initialize the
aFiltre array with something in it like somebody
else suggested. Just pre-init it with array(0)
(empty array) and I think that will work just fine.
Note on aScan(...) and the == comparison operator:
If you don't use a code block, the manual says
aScan(...) compares strings with the = operator,
which works differently depending on whether you
have EXACT set to be ON or OFF. Where I used to
work (among heavy-duty Clipper app programmers),
I found a distressing lack of in-depth understanding
among the staff about how = vs. == really works,
and worse still about how the other comparison
operators like > < >= and <= and <> really work
with EXACT ON vs. OFF. It's not discussed well
in any manual I've ever seen, but I experimented
with it in detail once until I figured it all out.
In your case, if you are comparing two strings
that are EXACTLY the same length (two characters
each), then you would have no problem. But my
general knee-jerk habit has always been to compare
strings with == instead of = unless I specifically
need to do otherwise, and to do that with aScan(...)
you need to use a code block. So stick to your
guns and do it that way.
My suggested code, above, is UN-tested just like
everybody else's. Hope it works for you if you
don't have your solution alrady, or if not, hope
the above doctoral dissertation gives you some
good clues how to deal with it.
There. NOW I can go ahead and click on Send.
-- Jay (diogenes) Jaeckel
---------------------------------------------
- References:
- Ascan with a Substr
- From: otto
- Re: Ascan with a Substr
- From: diogenes
- Ascan with a Substr
- Prev by Date: Re: not a valid win32 application
- Next by Date: Re: Any programmers still using clipper out there?
- Previous by thread: Re: Ascan with a Substr
- Next by thread: Re: Configuration Management
- Index(es):
Relevant Pages
|