Jump to content
Sign in to follow this  
Sabrina

looping w/ a variable name

Recommended Posts

My goal is to loop through some variables and set them to zero when a button is clicked. What I want is the FMP equivilent of:

for (int i = 1, i < total_questions, i++) {

g_questionNum [ i ] = 0;

}

I figured out that I can do

Set Field [count = 0]

Loop

Exit Loop If [count = total_questions]

Set Field [count, count + 1]

*****This is where I have problems . I want to use Set Field [g_questionNum(count) = 0] but obviously that isn't working.************

End Loop

I can set each question equal to 0 seperately but that's a waste of space and my time when I have 50+ questions on a questionnaire. (Not to mention carpel tunnel from the repetitive motions!) Help!

Share this post


Link to post
Share on other sites

Hi Sabrina,

Are all questions in the same record but in different fields?

If so, then you could change your database so that each question corresponds with one question and then loop through the records that you want to reset.

Anyway, Filemaker does not have a 'set' command which uses a variable to determine the target field.

Regards,

Ernst.

Share this post


Link to post
Share on other sites

Hey Ernst,

Yes, the questions are in the same record, but different fields.

There is actually a database for questions which is linked by a foreign key. When the key matches, then the set questions are inputted into the second database which is for the answers. The answers database is set up so that each record is for a particular respondent. If I was to set it up so that there was a record per question per respondent, I would have an unweildy database. Put it this way . . . I have usually 10 respondants per case and usually around 30 questions per respondent. That's not too many records (10 x 30 = 300) per case, but I have around 400 cases to input eventually. (300 x 400 = 120,000) Managing a database with 120,000 records compared to managing a database with 4,000 records is undesirable, but the limitations of FMP might make it necessary.

I can do the long hand method I mentioned but I was hoping to avoid the repetitive motions and wasted time. *insert big sigh here*

Thanks!

Sabrina

Share this post


Link to post
Share on other sites

If you want to go from one field to another on a single record, you don't necessarily need a counter. Just loop with a "go to next field," and Exit Loop If (Status (CurrentFieldName) = "theNameOfYourField")

Share this post


Link to post
Share on other sites

Fitch,

If I did a go to next field, can I still set the next field to 0 with out manually setting the increment?

Sabrina

Share this post


Link to post
Share on other sites

Fitch,

I just played with the idea and I cannot easily set the field. The issue I have is wanting to set an incremented list of global variables to zero without having to script SetField for each one. Having a script with 50 Set Fields does not appeal to me, but if I have to, I will. I was just hoping there was an alternative.

Sabrina

Share this post


Link to post
Share on other sites

Hi Sabrina,

That's indeed a lot of records. Though I think Filemaker can handle this without a problem, I can imagine that using seperate field has got something to say for it.

Luckily there is this very good suggestion by Fitch! You could set the Tab Order so that it goes through all your questionfields and have the script do something like:

goto field (select, firstquestion)

loop

insert calculated result (select, "0") <-- dont specify a field here

exit loop if (Status (currentfieldname) = lastquestion )

go to next field

end loop

You could add an extra 'outer' loop if you would want to reset severtal records in one go.

Regards,

Ernst.

Share this post


Link to post
Share on other sites

Ernst! Cool!

OK, for clarification "select" is similar to Java's "this"? In other words, leaving it as "select" means the current record?

Gosh I love this site! Ya'll are awesome!

Sabrina

Share this post


Link to post
Share on other sites

Enter Browse Mode

Go to Field []

Loop

..Go to Next Field

..Set Field ["0"]

..Exit Loop If [status(CurrentFieldName) = "TheEnd"]

End Loop

The trick is, do not specify a field in the Set Field step.

Share this post


Link to post
Share on other sites

"Select" in this context just means that the contents of the field will be selected as if you had highlighted the text. I.e., what's selected will be replaced by whatever you're doing in that script step, vs. the script step would append its data if the field contents aren't selected.

Set Field on the other hand will always replace the entire contents of the field. Also, Set Field in general does not require that the field even be present on any layout; however, in this case, the fields have to be on the layout and in the tab order for the script to work.

Share this post


Link to post
Share on other sites

I didn't know that you could leave that blank! You and Ernst are awesome! Thanks for your help!

Sabrina

Share this post


Link to post
Share on other sites

hi sabrina, instead of typing, why not use export/import. Sice every global has a corresponding field in the 2nd database, just do a scripted import (if there is just 1 record in main db, or omit other records first before import by using as selfjoin gotorelatedrecord based on unique record id).

no need for carpal tunnel syndrom here.

Share this post


Link to post
Share on other sites

There are better ways involving lookups or relations to accomplish this task.

also, have a look at the open source file "Test generator" at www.fmfiles.com on how to set up a test/survey database.

Share this post


Link to post
Share on other sites

It sounds like you've got it working. If not, one "gotcha" when using Go to Next Field, Set Field [""] is the Tab Order.

It uses the Tab Order of the current layout.

Use Exit Record first to start at 1st field.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.