| Subject |
Re: how left() works in dbase 11 plus |
| From |
AGOSTINHO <agostinhoteixeira@yahoo.com> |
| Date |
Sun, 30 May 2021 23:38:23 -0400 |
| Newsgroups |
dbase.getting-started |
Dear Mervyn Bick thanks you for your help and support.
The Entryfield4 is where the users search clients in database.
This is how I have my clients.dbf query setup with a GRID on the form
this.CLIENTS1 = new QUERY(this)
with (this.CLIENTS1)
left = 4.0
top = 24.0
sql = 'select * from "C:\Users\HOME_PC\Desktop\dBASEtutorial\clients.dbf" where lower(customercode+name+address) like lower(:ag)' params["ag"] = "%"
active = true
endwith
so whatever number the user type it will search for customer number, I use 4 digit for customer number.
In the same entryfield4 if the user type character instead he will get the customer name or customer address.
This works perfect so far, just like a Google search.
Now if the user want to add a customer to the database.
First he have to test if the number he wants to add already exists in the database.
In old DBASE DOS I used to program the following
find &ccode
yn=" "
if .not. found() .or. eof()
?chr(7)
@23,05 say 'Customer name not found ,Add new Customer to the list? Y/N !'
get yn
read
if upper(yn)="Y"
if val(ccode)<99 .or. val(ccode)>9999
wait " ACCEPT ONLY FOUR(4) DIGITS FOR CUSTOMER No. "
ccode=" "
loop
endif
if val(ccode)>1 .and. val(ccode)<999
if left(ccode,1)<>"0"
wait " ACCEPT ONLY FOUR(4) DIGITS FOR CUSTOMER "
ccode=" "
loop
endif
endif
append blank
replace code with ccode
endif
endif
This is what I've done in my form to get the same result.
function ENTRYFIELD4_onKey(nChar, nPosition,bShift,bControl)
form.clients1.params['ag'] = '%'+this.value+'%'
form.clients1.requery()
if form.entryfield4.value<9999 .and. form.clients1.rowset.endofset
if msgbox( "Add New Customer?", " ", 36 ) == 6
form.rowset.beginAppend()
form.rowset.fields["code"].value = form.entryfield4.value
form.rowset.save()
endif
endif
return
Agostinho
Thanks
Mervyn Bick Wrote:
> On 2021/05/30 08:03, AGOSTINHO wrote:
> > Dear group,
> >
> > If I want to test an user's input in DBASE DOS I do somethng like this
> > ?left(ccode,4)
> >
> > I've tried it in this function but I get an error
> > also need to make sure that the input are numbers only.
> >
> > function ENTRYFIELD4_onKey(nChar, nPosition,bShift,bControl)
> > form.clients1.params['ag'] = '%'+this.value+'%'
> > form.clients1.requery()
> > if form.entryfield1.value.left(4)
> > do something
> > endif
> > return
>
> Error messages usually, but unfortunately not always, point to exactly
> what is wrong. It does help though if you give us the wording of the
> error message.
>
> Set the value property of entryfield4 to Integer. This will ensure that
> the only digits can be entered.
>
> Adding '%' to the start and end of the value will automatically convert
> the result to character so that the requery() will work properly.
>
> The left() function only works with strings, not numbers. You can test
> for a 4 digit number as follows.
>
> if form.entryfield4.value > 999 and form.entryfield4.value < 10000
> do something
> return
>
> At present you onKey event handler requeries and fetches a new rowset as
> each digit is entered. If you are not going to "do something" until you
> have entered 4 digits then the following may be a better option
>
>
> function ENTRYFIELD4_onKey(nChar, nPosition,bShift,bControl)
> if form.entryfield4.value > 999
> form.clients1.params['ag'] = '%'+this.value+'%'
> form.clients1.requery()
> do something
> endif
> return
>
> This will requery as soon as the 4th digit is entered. If you want to
> prevent further digits from being entered then add the 'and
> form.entryfield4.value < 10000' to the test or set the entryfield's
> picture property to'9999'.
>
> Mervyn.
>
>
>
>
>
>
>
|
|