Page 1 of 1

Custom properties with variable names.

Posted: Sun Oct 07, 2012 3:59 am
by nextyoyoma
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.

Re: Custom properties with variable names.

Posted: Sun Oct 07, 2012 4:30 am
by dunbarx
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

Re: Custom properties with variable names.

Posted: Sun Oct 07, 2012 4:44 am
by dunbarx
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

Re: Custom properties with variable names.

Posted: Sun Oct 07, 2012 6:11 am
by nextyoyoma
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?

Re: Custom properties with variable names.

Posted: Sun Oct 07, 2012 7:32 am
by FourthWorld
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"

Re: Custom properties with variable names.

Posted: Sun Oct 07, 2012 10:51 am
by Klaus
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

Re: Custom properties with variable names.

Posted: Mon Oct 08, 2012 11:00 pm
by nextyoyoma
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?

Re: Custom properties with variable names.

Posted: Tue Oct 09, 2012 1:21 am
by dunbarx
Each iteration creates a new custom name:

periodOffset1
periodOffset3
periodOffset3

etc.

Craig Newman

Re: Custom properties with variable names.

Posted: Tue Oct 09, 2012 2:25 am
by nextyoyoma
dunbarx wrote:Each iteration creates a new custom name:

periodOffset1
periodOffset3
periodOffset3

etc.

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

Re: Custom properties with variable names.

Posted: Tue Oct 09, 2012 9:54 am
by Klaus
nextyoyoma wrote:oh, I missed the first line. Thanks!
8)