Jump to content
Claris Platform 2023 Roadmap ×

Variables within field names

This topic is 6067 days old. Please don't post here. Open a new topic instead.

Recommended Posts

  • Newbies

I’m making an inventory script that will count the total number of a particular type of item. For example, if it were a automobile database, there would be a car type, a truck type and an SUV type. Without doing a sort based on type, I want to have a running total on the bottom of each record of that particular type.

To do this, I have a number of global variables (or fields) with consecutive field names such as fieldType1, fieldType2, fieldType3 so on and so forth.

I want to modify all of these fields with just a few lines of code instead of writing a very repetitive, 20-line if-statement to test which field I’m in. So I’m hoping I can write a script that basically says:

Go to Field [fieldType(tmpVariable)]

As is obvious by the fact that I’m here, I’m not having much luck in this. Any suggestions?

Link to comment
Share on other sites

I would have only 1 Type field, with the choices, "car", "truck", "SUV". Then a self-relationship on Type. Then a calculation field: Count ( self_Type::Type ). That would show the total for that particular Type in one its records (but only in one of its records).

If you want to see an record-independent count (not in the body of the table's records), you would do like you did, but hard-code each type into an unstored (or globally-stored) calculation. Example: _cCarTxt = "Car" (that's just the word "Car"). Then you'd need a relationship from that to the Type field, one relationship for each type.

Or possibly something fancy to set the unique values into constants or globals from the data.

All the above would produce a total for the table, irregardless of found set. I don't know if you really meant "running total", which is a special term in FileMaker, and something quite different involving a Sort, Summary field, and likely Get ( Summary; break field ).

Link to comment
Share on other sites

  • Newbies

The original type field is just 1 field with several options in a drop list. The consecutive global fields are where the totals are going to be stored while the script switches from record to record.

Basically the script runs like this:

Upon opening the database for the first time, a small script clears out all the global fields so that they all = 0.

Then it goes to the first record.

Currently the script then enters a rather long if statement that checks what type is selected for this record.

If it's type 1, it sets a field globalType1Count equal to globalType1Count + the current item count of this record. [type1Total = (type1Total + itemCount)]

Then it repeats this assignment for every type in every record.

As you can imagine, this if statement can get pretty long (especially since I actually have much more then 3 types. There are over a dozen and more coming)

I'm hoping there is a way I can just call a subscript and say "Set globalType(currentType)Count = (globalType(currentType)Count + itemCount)" where the number of the current type would be the "1" if it's type 1, the "2" if it's type 2, so on and so forth.

I know this is possible in C++ and VB (which I have a fair bit of experience in) but I don't know if this is possible in FileMaker (which as of four or five weeks ago, I had never heard of)

Link to comment
Share on other sites

This topic is 6067 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Create New...

Important Information

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