Page 1 of 1

entry field error after 9 fields

Posted: Fri Apr 11, 2014 7:12 pm
by trags3
I have a card with 11 text entry fields that need to be numbers.
I have code for each text box to check for the enter key, return key and to make sure each key pressed is a number.
When the enter or return key is pressed focus is sent to the next desired entry field.
The code I am using is:

on returninfield
focus on field misc2
end returninfield

on enterinfield
returninfield
end enterinfield

on keyDown theKey
if theKey is not a number then beep
else pass keyDown
end keyDown

After pressing the enter Kee in the 10th field I get an error message as follows:

field "misc2": execution error at line 2 (focus: not a valid control), char 1

I don't know what to do.
thanks

Tom

Re: entry field error after 9 fields

Posted: Fri Apr 11, 2014 7:28 pm
by FourthWorld
Where is the variable "misc2" defined?

It may be simpler to just turn on the autoTab property for each field, and then the engine will take care of the tab-on-return behavior for you automatically.

Re: entry field error after 9 fields

Posted: Fri Apr 11, 2014 7:57 pm
by trags3
misc2 is the name of the next entry field and works and is different for each field and allows focus to be in the order I want.
Thanks that works. I didn't have the "tab on Return" property checked in the offending field.
The only problem now is how do I change the order of which entry field gets the focus on the tab key.
I have removed all the code except for the On keyDown message.

Thanks

tom

Re: entry field error after 9 fields

Posted: Fri Apr 11, 2014 8:10 pm
by Simon
Hi Tom,
The fields are focused in layer order.

Simon

Re: entry field error after 9 fields

Posted: Fri Apr 11, 2014 8:12 pm
by dunbarx
Hi.

You can change the layer order of the fields, so the natural progression works for you, or you can place a tabKey handler in each field that explicitly focuses on the next field you want.

Are your fields really named as numbers? This is not good practice at all. Could you rename them something like "f1,f2,f3..."? These are much easier to manage. If your fields are named in the desired order, can you write a single tabKey handler in the card script that does the refocusing? It would be a terrific learning exercise. Do try. Write back if you get stuck.

Anyway, know that a little re-thinking is really powerful sometimes.

Craig Newman

Re: entry field error after 9 fields

Posted: Fri Apr 11, 2014 10:42 pm
by trags3
I have tried to change the level of the entry fields on the card unsuccessfully.
I tries script at the entry box level and at the card level.
The code I tried is:
set the layer of "SellerN" to 1
set the layer of "PropAddr" to 2
set the layer of "City" to 3
set the layer of "salesprice" to 4
set the layer of "MortPayoff" to 5
set the layer of "commissionp" to 6
set the layer of "TransactFee" to 7
set the layer of "HOATrans" to 8
etc
Help Please
Tom

Re: entry field error after 9 fields

Posted: Fri Apr 11, 2014 11:20 pm
by Simon
Hi Tom,
You must include the object with that name e.g.
set the layer of field "SellerN" to 1

Using the Project Browser you can drag the objects to new layers, for simple stack it often works but I find it flaky.

The best way I find is to use the Inspector and set the layer in "Size & Position"

Simon

Re: entry field error after 9 fields

Posted: Fri Apr 11, 2014 11:27 pm
by trags3
Thanks Simon, I just realized that as you posted the answer.
It sucks to be a noob

Tom

Re: entry field error after 9 fields

Posted: Fri Apr 11, 2014 11:58 pm
by Simon
Hey Tom, don't worry with liveCode you will learn very quickly.

My favorite gotcha's:

Code: Select all

repeat with x = 1 to the number of lines in tVar
if "Remove this sad little line" is in line x of tVAr
delete line x of tVar
end if
end repeat
That one is great because it almost works and looks very reasonable.

Code: Select all

offset("b","abacadabra",2) -- returns 6
That "2" is characters to skip but it doesn't work the way I expect

And one that never actually got me but comes up here too often is that global variables have to be declared everywhere they are used.

When you come to any of those and get stumped just ask here.

Simon
Edit:
myPlants.zip
LC 6.5
(2.21 KiB) Downloaded 201 times
This is the other big thing that comes up, saving the state of your standalone. You must write to a separate file to save changes. You haven't gotten to that point yet but I can tell you will ;)
Keep that stack handy.

Re: entry field error after 9 fields

Posted: Sat Apr 12, 2014 2:05 am
by trags3
Thanks a lot Simon.
I really am learning pretty fast.

Tom