Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Do Case using a Varible?

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
0
0
Are doing something fundamentally wrong?
We are building a name search on a personsform using a personsgrid and textboxes with no controlsource. .
Our code in the lostfocus of each is:
vfname=thisform.firstname.value
vlname=thisform.lastname.value
Do Case
Case m.vfname=''
Do Case
Case m.vlname=''
Set filter to
Go top
Case m.vlname<>''
Set filter to m.vlame=lname
Endcase
Case m.vfname<>''
Do Case
Case m.vlname=''
Set filter to m.vfname=fname
Case m.vlname<>''
Set filter to m.vfname=fname .and. m.lname=lname
Endcase
Endcase
thisform.refresh
Variables have the value. . .but we can't get them to catch. . .trying to get this to work for we have many Herberto Romaneos here. . .we would like to make it more compound than this, but we are fundamentally missing something.Any guidance would be appreciated! Dun'ka
 
Hi Dun'ka,

Use:
m.vfname==''
or
empty(m.vfname)

For more information, see SET EXACT in the VFP help file. It will give you an explanation of comparing strings of different lengths.
Jon Hawkins
jonscott8@yahoo.com

The World Is Headed For Mutiny,
When All We Want Is Unity. - Creed
 
For the recrod and any lurkers here's a description of how strings are compared for equality in VFP. It is a multistep process, the steps are listed below;

With SET EXACT OFF
1) The strings are assumed equal
2) they are compared one character at a time
3) When the string on the right side of the = sign is exhausted the result is returned

So;

lcVar1 = &quot;John&quot;
lcVar2 = &quot;Jo&quot;

? lcVar1 = lcVar2 && True
? lcVar2 = lcVar1 && False
?lcVar1 = &quot;&quot; && True
? lcVar2 = &quot;&quot; && True

The last are true because when step 2 is encountered the string on the right is already exhausted.

With SET EXACT ON;

1) The strings are assumed equal
2) The shorter string is padded with spaces to be equal in lenght to the onger string
3) The strings are compared one character at a time

So;

lcVar1 = &quot;John &quot;
lcVar2 = &quot;John&quot;
? lcVar1 = lcVar2 && Ture
? lcVar2 = lcVar1 && True
? lcVar1 = &quot;&quot; && True
? lcVar2 = &quot;&quot; && True
? lcVar1 = &quot;Johnny&quot; && False

The double equal sign does thigns differently than SET EXACT ON, == is;

1) The string are assumed equal
2) They are compared one character at a time
3) When the stirng on the right is exhausted ...
4) They are checked for equal length

So;

lcVar1 = &quot;John &quot;
lcVar2 = &quot;John&quot;
? lcVar1 == lcVar2 && False
? lcVar2 == lcVar1 && False

Based on this the only way to do a truly exact comaprison of strings is to use the == operator.

As for the DO CASE stuff in the original question, the first response was on target, use EMPTY instead of comparison to the 0 length string;

CASE EMPTY(lcString)

instead of;

CASE lcString = &quot;&quot;

JimB

JimBooth
jbooth@jamesbooth.com
 
JuanDiegovisitor,
1. In your case statement you use a memvar LNAME and FNAME in 3 different lines of code. I do not see any lines of code that define or initilize these 2 memvars,. Where do they come from?
2. In tyour first case statement you have
Set filter to m.vlame=lname
I Think that should be
Set filter to m.vlname=lname

3. Also on the next to last line you have
m.lname = lname
I think that should be
M.vlname = lname.
[tt]
vfname=thisform.firstname.value
vlname=thisform.lastname.value
if empty(m.vfname)
if empty(M.vlname)

Set filter to
Go top
else
Set filter to m.vlname=lname
endif

else
if empty(m.vlname)
Set filter to m.vfname=fname
else
Set filter to m.vfname=fname .and. m.vlname=lname
endif

Endif
David W. Grewe
Dave@internationalbid.com
ICQ VFP ActiveList #46145644
 
Hi David,

you use a memvar LNAME and FNAME..Where do they come from?

MTL, LNAME and FNAME are fields in his table, since he is attempting to use them in his filter condition.

Set filter to m.vlame=lname

should probably be:

Set filter to lname=m.vlame

Just my SWAG. Jon Hawkins
jonscott8@yahoo.com

The World Is Headed For Mutiny,
When All We Want Is Unity. - Creed
 
Jon, I am so used to putting the table alias in front of a field name example(CUSTOMER.LNAME) I just assumed that [red]lname[/red] was a memvar. Guess some point in life I'll remember that the defination of assume means &quot;Makes an A** of U and ME&quot;. David W. Grewe
Dave@internationalbid.com
ICQ VFP ActiveList #46145644
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top