Is indirect addressing possible?

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
ajperks
Posts: 105
Joined: Sat Sep 06, 2014 3:38 pm

Is indirect addressing possible?

Post by ajperks » Wed Oct 24, 2018 10:56 pm

A text field is called Fld1
Can I put the text Fld1 into a variable and use that as the Field name?
It doesn't seem to work

Code: Select all

  put "Fld1" into temp
   put fld temp into fld "target"

ClipArtGuy
Posts: 253
Joined: Wed Aug 19, 2015 4:29 pm

Re: Is indirect addressing possible?

Post by ClipArtGuy » Wed Oct 24, 2018 11:02 pm

This is working as expected here in 9.01 on Ubuntu 18.04

quailcreek
Posts: 746
Joined: Sun Feb 04, 2007 11:01 pm

Re: Is indirect addressing possible?

Post by quailcreek » Thu Oct 25, 2018 12:13 am

Work fine on my Mac.
Tom
MacBook Pro OS Mojave 10.14

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10323
Joined: Wed May 06, 2009 2:28 pm

Re: Is indirect addressing possible?

Post by dunbarx » Thu Oct 25, 2018 2:56 am

I don't see how any of that other stuff could work.

Two possibilities:

1-

Code: Select all

on mouseUp
   put "Fld 1" into temp
   put temp into fld 2
end mouseUp
This puts "Fld 1" into fld 2.

2-

Code: Select all

on mouseUp
   put "Fld 1" into temp
   do "put " && temp &&  "into fld 2"
end mouseUp
This puts the contents of fld 1 into fld 2.

Was any of that what was intended?

Craig Newman

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10051
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Is indirect addressing possible?

Post by FourthWorld » Thu Oct 25, 2018 3:34 am

The text of a field is a property, like width, height, and the others. While it's sometimes useful to be able to use the shorthand form of "put fld 1 into fld 2", the complete form of addressing a field property is useful here:

Code: Select all

put "MyFieldName" into tFld1
put the text of fld tFld1 into fld "SomeOtherField"
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

ajperks
Posts: 105
Joined: Sat Sep 06, 2014 3:38 pm

Re: Is indirect addressing possible?

Post by ajperks » Thu Oct 25, 2018 9:45 am

OK, I have found the problem.
The difference is between a software generated name and an explicit one when placed in a variable.
If the software generated name has invisible characters, the name you see is not the name the computer sees.

What I could do with is a quick running and clean bit of code that removes the letters Field from (say) Field2 (the clicked field and gives me the number 2 although the range might be up to and including 100) and no trailing spaces.

Klaus
Posts: 14198
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Is indirect addressing possible?

Post by Klaus » Thu Oct 25, 2018 12:45 pm

If you tell us what you are trying to do, maybe we can come up with a smart solution.

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10051
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Is indirect addressing possible?

Post by FourthWorld » Thu Oct 25, 2018 5:19 pm

We move data between fields often. An example of a name containing characters preventing this, along with the code that isn't working, would be helpful.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

AxWald
Posts: 578
Joined: Thu Mar 06, 2014 2:57 pm

Re: Is indirect addressing possible?

Post by AxWald » Fri Oct 26, 2018 10:04 am

Hi,
ajperks wrote:
Wed Oct 24, 2018 10:56 pm
Can I put the text Fld1 into a variable and use that as the Field name?
It doesn't seem to work

Code: Select all

  put "Fld1" into temp
   put fld temp into fld "target"
This works here (LC 6.7.10):

Code: Select all

    put "myFldName" into myVar
    put "Hussah!" into fld (myVar)
    put fld (myVar)
This works, too:

Code: Select all

repeat with i = 1 to 4
    set the textstyle of btn ("c" & i & "_btn") to "plain"
    set the visible of grp ("G_" & i & "_grp") to false
The parentheses are not always required (i.e. sometimes it works w/o - just as with quotes for names), but help a lot to remember that this is a "constructed name".

For sure you must make certain that the name is spelled correctly - for this I omit anything but alphanumerics and "_" in my names, especially spaces.

At last, be sure to use the correct address - often it's a lacking "of me" or "of this cd" that causes confusion ...

Have fun!
All code published by me here was created with Community Editions of LC (thus is GPLv3).
If you use it in closed source projects, or for the Apple AppStore, or with XCode
you'll violate some license terms - read your relevant EULAs & Licenses!

ajperks
Posts: 105
Joined: Sat Sep 06, 2014 3:38 pm

Re: Is indirect addressing possible?

Post by ajperks » Fri Oct 26, 2018 12:01 pm

Hi, Indirect addressing fields is entirely possible but care is needed to avoid including any spaces or other invisible codes into the name. In my case, it was Field(space) a number (space) The trailing space caused a lot of problems.

I needed to address a column of 100 fields, all enclosed in a group with a vertical scroll bar. The Flds were Named Field 1 … Field 100.
The address was placed in a variable.

Post Reply