Custom properties with variable names.

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
nextyoyoma
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 37
Joined: Sat Oct 06, 2012 6:29 am

Custom properties with variable names.

Post by nextyoyoma » Sun Oct 07, 2012 3:59 am

I'm writing a program to check a student's schedule, based on the output of our student management software. I don't want to depend on an external file to read this information every time, so I am planning on doing the launcher-mainstack combo when I create my standalone app so that I can save the schedule in a custom property or other field in the mainstack of my application and have it persist from session to session. I cannot depend on the output of that software to be consistently formatted, so I need to detect which header columns in the source file contain the word "Period." I am having some trouble using a repeat to create my custom properties for this information. Here is what I am trying to do:

Code: Select all

repeat with i = 1 to 7
      set the periodOffset & i of this stack to wordoffset("Period", line 1 of allschedules, the periodOffset & i of this stack)
   end repeat
In case it isn't clear, what I'm trying to do is create 7 custom properties, each of which is called "periodOffset" + the number of occurrences of the word so far in the loop.
When I try to run the command this way, I get an error:set: no property specified. If I take out the attempt at concatenation of i, it works fine. The same thing applies to the last argument in the wordoffset function, where I get an error: Expression: bad factor.)

First off, is it possible to do what I'm trying to do, and if so, how do I do it?

Second, is this the correct way to go about this task? Apparently my account is not allowed to post links, but the lesson titled "How do I save custom properties in a standalone application?" suggests that using custom properties to save information between sessions, but I'm wondering why this can't just be done with a hidden text field. They seem much easier to work with.

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

Re: Custom properties with variable names.

Post by dunbarx » Sun Oct 07, 2012 4:30 am

Hi.

I have not tested anything with this, but the way you wrote it appears to me to require more than one level of evaluation. In other words, your code probably could do with some "do" constructs. Oh, and "period" is not a constant in LC. You have to use ".", period.

I just rewrote the handler like this;

Code: Select all

on mouseUp
   repeat with i = 1 to 7
      do "put the periodOffset" & i && "of this stack into tOffset"
      get  wordoffset(".", line 1 of allschedules,tOffset )
            do "set the periodOffset" & i && "of this stack to" && it 
      end repeat
end mouseUp
Not even sure I pulled everything together right, but it compiles correctly. You can certainly, if this solves the issue, combine the first two lines back into one, as you first had it. I only broke it out to see where the compiler was complaining.

Craig Newman

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

Re: Custom properties with variable names.

Post by dunbarx » Sun Oct 07, 2012 4:44 am

I suppose you can use a hidden text field instead of a custom property. For text. Try that with an array

But custom properties can hold all kinds of content, and more importantly, custom properties generate messages when they are changed. Read up on the "setProp" and "getProp" control structures. They are for more compact and accessible than using another object. Try them, you will like them.

Craig Newman

nextyoyoma
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 37
Joined: Sat Oct 06, 2012 6:29 am

Re: Custom properties with variable names.

Post by nextyoyoma » Sun Oct 07, 2012 6:11 am

dunbarx wrote: Oh, and "period" is not a constant in LC. You have to use ".", period.
Thanks for your info! I actually am looking for the string "Period" rather than a literal "."

Since posting earlier I decided to ditch this idea and store this info in an external file. Any opinions on which way is better?

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

Re: Custom properties with variable names.

Post by FourthWorld » Sun Oct 07, 2012 7:32 am

Another option would be to use a custom property set named "period" in which each element is labeled or the number, e.g.:

set the uPeriod of this stack to "Some Value"
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

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

Re: Custom properties with variable names.

Post by Klaus » Sun Oct 07, 2012 10:51 am

This also works:

Code: Select all

...
repeat with i = 1 to 7
      put "periodoffset" & i into tCPName
      set the tCPName of this stack to wordoffset("Period", line 1 of allschedules, the tCPName of this stack)
end repeat
...
Best

Klaus

nextyoyoma
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 37
Joined: Sat Oct 06, 2012 6:29 am

Re: Custom properties with variable names.

Post by nextyoyoma » Mon Oct 08, 2012 11:00 pm

Klaus wrote:This also works:

Code: Select all

...
repeat with i = 1 to 7
      put "periodoffset" & i into tCPName
      set the tCPName of this stack to wordoffset("Period", line 1 of allschedules, the tCPName of this stack)
end repeat
...
But wouldn't this just change the value of tCPName every time the repeat iterates? Or does set append the value to the existing container?

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

Re: Custom properties with variable names.

Post by dunbarx » Tue Oct 09, 2012 1:21 am

Each iteration creates a new custom name:

periodOffset1
periodOffset3
periodOffset3

etc.

Craig Newman

nextyoyoma
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 37
Joined: Sat Oct 06, 2012 6:29 am

Re: Custom properties with variable names.

Post by nextyoyoma » Tue Oct 09, 2012 2:25 am

dunbarx wrote:Each iteration creates a new custom name:

periodOffset1
periodOffset3
periodOffset3

etc.

Craig Newman
oh, I missed the first line. Thanks!

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

Re: Custom properties with variable names.

Post by Klaus » Tue Oct 09, 2012 9:54 am

nextyoyoma wrote:oh, I missed the first line. Thanks!
8)

Post Reply