Page 1 of 3
Numbers in text fields
Posted: Thu Jan 28, 2021 1:42 am
by dalkin
Hello. I have an issue which I suspect is related to Unicode but I can't seem to lift the bonnet to check the spark plugs. I have a fairly simple structure involving a button that creates a name for a project, then puts that name into a scrolling list field with
Button:
Code: Select all
on mouseUp pButtonNumber
ask "Please enter a name for the project."
if the result is not "cancel" then
put it into tName
clone card "Lyricist"
put the long id of it into tCardID
put tName into field "Title" of tCardID
set the name of tCardID to tName
put return before line 1 of field "Index" of card "Navigation"
put tName before field "Index" of card "Navigation"
end if
end mouseUp
Scrolling list field (Index):
Code: Select all
on mouseup
put the selectedtext of me into tCard
if there is a card tCard then
go to card tCard
end if
end mouseup
Naming the project commencing with a letter (a,b,c etc.) allows navigation but naming the project starting with a number does NOT allow navigation.
Re: Numbers in text fields
Posted: Thu Jan 28, 2021 9:30 am
by richmond62
That is odd.
I set up a stack with 4 cards named respectively "1KARD", "2KARD", "3KARD", "4KARD"
and even the in-built navigation would not behave itself ( View/Go Next ).
In fact almost all of the IDE grinds to a halt.
I have no idea what the reason for this is, but, obviously, the simplest solution from your point of view would
be to prefix every name with something alphabetic, say "x", so "x1KARD", "x2KARD", etc. in my example.
Oh, and while I'm here, here's a jolly bit of code to put in each cardScript:
Code: Select all
on openCard
set the title of stack "XXXX" to the short name of me
end openCard
Re: Numbers in text fields
Posted: Thu Jan 28, 2021 11:09 am
by Xero
I haven't tried this, but this might simplify the code by a line...
Existing code:
Code: Select all
put return before line 1 of field "Index" of card "Navigation"
put tName before field "Index" of card "Navigation"
I gather this is to place a blank line at the start of the field then replace it with 'tName', having it at the top of a list...
I think this should do the same job:
Code: Select all
put tName & cr before line 1 of field "Index" of card "Navigation"
This should place the name at the start and then add a return...
XdM
Re: Numbers in text fields
Posted: Thu Jan 28, 2021 1:44 pm
by bogs
dalkin wrote: ↑Thu Jan 28, 2021 1:42 am
Naming the project commencing with a letter (a,b,c etc.) allows navigation but naming the project starting with a number does NOT allow navigation.
Almost all RAD languages I've used tend to not want a number as the first part of the name of an object, and Lc itself strongly suggests not doing it all the way back to MetaCard, but allows for it in certain formatting. From the User Guide in the current version -
Avoid using numbers as object names
It is dangerous to set the name property of an object to a number.
For example, create three fields on a new card, naming the first one "3", the second one "2", and the
third one "1". In other words, the creation order of those three fields is the reverse of the numerical
names you've given them. Now use the message box to:
Code: Select all
put "This is field 3" into field 3
The third field created, the one named "1", has its text set. The number of the field, not the name set
by you, was used by LiveCode as the object reference.
This shows the perils of using a number as the name of an object. There are built-in properties of
controls (the layer and the number) that are based on integers, and to use integers in yet another
way, in the name property, will likely cause unexpected behaviour at best.
This applies to cards as well.
The card order supersedes any numerical card name.
You can, however, use a name which includes a number safely. For example, you could call you fields
"field1", "field2" and "field3".
Now there is no conflict when you use the message box to:
Code: Select all
put "This is field 3" into field "field3"
You could also construct numerical field names:
Code: Select all
on mouseUp
repeat with y = 1 to 3
put y into field ("field" & y)
end repeat
end mouseUp
This will put the values "1", "2" and "3" into the fields named "field1", "field2" and "field3". The "field",
concatenated with the number, removes the conflict with the control number.
To summarize, it can be done if approached in a certain way, typically any name should be preceded either with an underscore or letter, if you are going to use a bare number, it should correspond with the object's layer / control number.
Alternately, give the control a sane name and use the title or label for displaying the "number first" name.
Re: Numbers in text fields
Posted: Thu Jan 28, 2021 2:37 pm
by richmond62
From the User Guide in the current version
Good Lord: you're actually expecting people to read that before they get their feet wet!
-

- error.jpeg (5.86 KiB) Viewed 11405 times
Re: Numbers in text fields
Posted: Thu Jan 28, 2021 2:50 pm
by bogs
Sure, as they used to say when I was younger, "...reading is fundamental" (or fun-and-mental)

Re: Numbers in text fields
Posted: Thu Jan 28, 2021 3:18 pm
by dunbarx
I made a new stack with enough of your gadgetry to test the handler. Works without issue. Preceding the stack name or stack file with a number don't enter into it.
Craig
Re: Numbers in text fields
Posted: Thu Jan 28, 2021 4:45 pm
by FourthWorld
My experience has been like Craig's. Could either of the two examples noted here as problematic be posted here so we can reproduce this?
Re: Numbers in text fields
Posted: Fri Jan 29, 2021 2:34 am
by dalkin
Thanks for taking a look at this. The Mac version is available via the bug-tracker at
quality.livecode.com/show_bug.cgi?id=23025 - the bug was solely related to Big Sur - use serial 856087687675
steps to reproduce:
1. create new project without a number. Takes you to the project interface
2. Enter your new data if you want to. Click on 'Navigation' to go back to the navigation pane.
3. Create a new project starting with a number. Takes you to the project interface.
4. The project name listed that starts with a number is not clickable
Re: Numbers in text fields
Posted: Fri Jan 29, 2021 3:20 am
by dalkin
Asking users not to start a tile with a number would be like hanging out a 'Wet Paint' sign. Would there be a way to disable the use of numbers in a text field perhaps?
Re: Numbers in text fields
Posted: Fri Jan 29, 2021 5:07 am
by dunbarx
Asking users not to start a tile with a number would be like hanging out a 'Wet Paint' sign. Would there be a way to disable the use of numbers in a text field perhaps?
I am losing the thread of this thread. What are "tiles"? Fields? What is a "project"? A stack? How did we get to worrying about a field having issues with numbers?
Dalkin. Please tell me where we are with this.
Craig
Re: Numbers in text fields
Posted: Fri Jan 29, 2021 5:31 am
by dalkin
Oh right. Typo. Read tile as 'Title' ie. the name of the Project. My app is destined to be a platform for people to develop lyrics for songs and provide an audio interface for recording sound snippets. Each cloned card is its own 'Project', findable by its Title in the navigation structure .. clicking on the Title takes you to the Project.
If you think it's confusing, thank your lucky stars you don't have my head on your shoulders.
Re: Numbers in text fields
Posted: Fri Jan 29, 2021 1:38 pm
by bogs
@Craig & Richard -
dunbarx wrote: ↑Thu Jan 28, 2021 3:18 pm
I made a new stack with enough of your gadgetry to test the handler. Works without issue. Preceding the stack name or stack file with a number don't enter into it.
FourthWorld wrote: ↑Thu Jan 28, 2021 4:45 pm
My experience has been like Craig's.
I think the main problem (where naming with a number first in
Lc) would be reserved for people who, like me when I started, were confused about placing quotations around the name (or any string literal, really).
How many times do you see ...
...in example code? If I had a nickle for each time I have, I would have been able to retire by now. You two from long experience
know that means the 3rd card of that stack, but lets say a new person to this language see's a lot of examples of that, and thinks it refers to the name of the card, which is "3", but the card is actually card 6 of that stack. They type the same code, but wind up at a completely different card.
Yes, the above is an oversimplification, but, at least when I first got here, was accurate in my case.
It is the same problem that develops when you have names with spaces, but no quotes around the name in code, but that is for another discussion.
@dalkin - Glad you found out you were looking at a bug and filed the report.
Re: Numbers in text fields
Posted: Fri Jan 29, 2021 3:03 pm
by dunbarx
Bogs.
Could be, but I read the initial post as "starting with a number". as in "go to cd "3xyz" of stack "5abc".
As for heads on shoulders, I have been trying to get rid of mine for ages.
Craig
Re: Numbers in text fields
Posted: Fri Jan 29, 2021 4:03 pm
by FourthWorld
The bug report shows there's more going on than using an integer for an object name.
Panos confirmed it was an issue, and fortunately was acknowledged as fixed on the 13th in v9.6.2 rc2.