Home > Archive > Programming with dBASE > June 2005 > applyLocate()









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]

 

Author applyLocate()
Ross Wyborn

2005-06-22, 8:23 pm

What is the best way to test if applylocate has been sucessfull. Using
simple tests I found that
if form.rowset.applyLocate()
and
if form.rowset.applyLocate() = true
both return false when the locate has found a match.
I guess I could test the complete locate conditions with an if statement but
that seems cumbersome. There must be a better way.
Thank you
Ross Wyborn



Frank J. Polan

2005-06-22, 8:23 pm

Ross,

Copy the following form & run from navigator
It shows that applylocate works properly

HTH

Frank Polan

...................................................
/* use this to create tables for turnkey */
/////////////// test.wfm ////////////////
close databases
close all
clear all
release all
clear memory
clear program
set proc to
//

if file('table1.dbf')
drop table 'table1.dbf'
endif
create table 'table1.dbf' ( ;
field1 char (10), ;
field2 char (10) ;
)

insert into table1 (field1, field2) values ('abc', 'def')
insert into table1 (field1, field2) values ('ghi', 'jkl')
insert into table1 (field1, field2) values ('mno', 'pqr')


//


** END HEADER -- do not remove this line
//
// Generated on 04/11/2005
//
parameter bModal
local f
f = new ApplyLocateTestForm(
)
if (bModal)
f.mdi = false // ensure not MDI
f.readModal()
else
f.open()
endif

class ApplyLocateTestForm of FORM
with (this)
height = 16.0
left = 16.2857
top = 0.0
width = 126.8571
text = ""
endwith

this.TABLE11 = new QUERY()
this.TABLE11.parent = this
with (this.TABLE11)
left = 7.7143
top = 2.2727
sql = 'select * from "table1.dbf"'
active = true
endwith

this.GRID1 = new GRID(this)
with (this.GRID1)
dataLink = form.table11.rowset
height = 6.3636
left = 3.4286
top = 0.9091
width = 29.1429
endwith

this.PUSHBUTTON1 = new PUSHBUTTON(this)
with (this.PUSHBUTTON1)
onClick = class::PUSHBUTTON1_O
NCLICK
height = 1.0909
left = 3.4286
top = 12.7273
width = 15.2857
text = "Applylocate"
endwith

this.ENTRYFIELD1 = new ENTRYFIELD(this)
with (this.ENTRYFIELD1)
height = 1.0
left = 19.7143
top = 12.7273
width = 11.1429
value = "tst"
endwith

this.CHECKBOX1 = new CHECKBOX(this)
with (this.CHECKBOX1)
height = 1.0909
left = 10.0
top = 11.0
width = 14.1429
text = "Found"
endwith

this.TEXT1 = new TEXT(this)
with (this.TEXT1)
height = 2.5
left = 3.0
top = 8.0
width = 29.0
fontBold = true
text = "Source demos syntax for applylocate string"
endwith

this.TEXT2 = new TEXT(this)
with (this.TEXT2)
height = 7.4545
left = 38.0
top = 1.0
width = 51.0
text = "<p> function PUSHBUTTON1_onClick</p><p> local
bRes, cLookFor</p><p> cLookfor = " + '"' + "Field1 = '" + '"' +
"+form.entryfield1.value+" + '"' + "'" + '"' + "</p><p> bRes =
form.rowset. applylocate(cLookFor
)</p><p> if bRes</p><p>
form.checkbox1.value := true</p><p> else</p><p>
form.checkbox1.value := false</p><p> endif</p><p>
return</p>"
endwith

this.rowset = this.table11.rowset

function PUSHBUTTON1_onClick
local bRes, cLookFor
cLookfor = "Field1 = '"+form.entryfield1.value+"'"
bRes = form.rowset. applylocate(cLookFor
)
if bRes
form.checkbox1.value := true
else
form.checkbox1.value := false
endif
return
endclass
...................................................

On Wed, 22 Jun 2005 16:05:09 -0700, "Ross Wyborn" <rosswyborn@shaw.ca>
wrote:

>
>What is the best way to test if applylocate has been sucessfull. Using
>simple tests I found that
>if form.rowset.applyLocate()
>and
>if form.rowset.applyLocate() = true
>both return false when the locate has found a match.
>I guess I could test the complete locate conditions with an if statement but
>that seems cumbersome. There must be a better way.
>Thank you
>Ross Wyborn
>
>
>



Ross Wyborn

2005-06-23, 1:23 pm

Thanks Frank. I was unable to get your program to work because the text line
was jumbled by outlook and when I tried to correct it I got an error
(missing quotes). Anyway what I did was set up the same table and make a
form which had a grid (so I could see what was going on), two entryfields
(EF1, EF2), a pushbutton and a checkbox (to test result).
When I used the example(for the pusbutton onclick) as in the example ie;
if form.rowset.applyLocate("Field1='"+form.EF1.value+"'")
it worked fine. So thank you for showing me that. I did find the quotes
confusing and probably would never have got it right on my own.
However what I wanted to do was:
form.rowset.beginLocate()
form.rowset.fields["field1"].value = form.EF1.value
form.rowset.fields["field2"].value = form.EF2.value
form.rowset.applyLocate()
if form.rowset.applyLocate()
**I also tried if form.rowset.applyLocate() = true
form.CBTrue.value = true
else
form.CBTrue.value = false
endif
and this does not work. I also noted that the second scope statement
(form.rowset.fields["field2"].value = form.EF2.value) was not at all
considered. I could see from the grid that it was locating fine for the
first condition but still the checkbox would not show true.I then tried to
combine two conditions like;
if form.rowset.applyLocate("Field1='"+form.EF1.value+"'"+and+"Field2
='"+form.EF2.value+"'")
but could not get it right - quotes in wrong places?.
It would be nice if the beginLocate / applyLocate could be used for multiple
conditions and be able to test if it was true. Surely this is basic
programming so I wonder why I don't get it.
Any further light on the subject would be appreciated. Thanks for the one
example, at least that works.
Ross Wyborn



Sponsored Links





Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive | Programming forum archive

Copyright 2008 droptable.com