Subject Re: applyLocate and apostrophe applylocate limit ?
From Dirk C <dirk@C.com>
Date Mon, 19 Aug 2024 11:35:08 +0200
Newsgroups dbase.getting-started

Op 18/08/2024 om 15:37 schreef Mervyn Bick:

Mervyn,

thanks for your detailed information

i already sampled out with square quaotes, but mis placed the quotes,
afterwards i used the apostroph function, you gave me once, to use in
calling a form, which succeded,

now i tested  with numbers aswell, all ok

i think Ken should mentioned in his book

and i suppose findkeynearest function is a refined applylocate


Dirk,


> On 2024/08/18 11:52, Dirk C wrote:
>> Op 17/08/2024 om 13:22 schreef Mervyn Bick:
>>
>> Mervyn,
>>
>> on question about
>>
>> what's the difference bewteen your solution ( or which influence has
>> the variable) your shorter way
>>    bSuccess = oRowset.applyLocate("fieldname = ["+searchString+"]")
>
> That was simply meant to point out that, although the help file gives an
> example, it is not usable in all cases.
>
> Using the applyLocate() example in the help file i.e
> form.rowset.applyLocate( "CITY = '" + form.cityText.value + "'" )
>
> If the value in form.cityText.value was O'Grady the code would evaluate to
>
> form.rowset.applyLocate( "CITY = 'O'Grady'" ) which would cause an
> error.  dBASE sees "CITY = 'O'" and doesn't know what to do with Grady'
>
> By using the syntax I suggested the code would evaluate to
>
> form.rowset.applyLocate( "CITY = [O'Grady]" ) which dBASE can handle.
>
> This does not apply to ADOrowsets where one would need to use an
> "escape" character ahead of the apostrophe as "proper" SQL requires
> literal strings to be delimited using single quotes.
>
>>
>> and
>>
>> Case form.keuzedoos_sorteren.value =="firma"
>> c_Veldf = trim(this.value)
>>   o_vraagb.Rowset.applyLocate("Name = ["+c_Veldf+"]")
>>
> The object represented by "this" depends on how the function was
> executed but if this.value contains the name you want to locate then
> your code should work.  The important thing is that c_Veldf is delimited
> with square brackets in the SQL expression used as the argument for
> applyLocate().  This means that if there's an apostrophe in the value it
> won't cause a problem.
>
> There is no real need to use a macro as I did in the example but using
> it does mean you will be able to display the actual command to check for
> errors if it doesn't work.
>
> Mervyn.
>
>