Jump to content
Server Maintenance This Week. ×

Using multiple Else If statements in a script


milky

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

Recommended Posts

Hi Everyone, 

I have a script as per the attached image below, that sets a variable from a field in my Events table and goes to another Layout and sets a field in my Players Table.

Everything works well, my question is:

"Is there another way to accomplish this without the multiple Else If statements?".

The script will eventually have 50 Else If statements.

 

Else If script.jpg

Link to comment
Share on other sites

The script you show has multiple nested If statements, not (only) multiple Else If statements.

1 hour ago, milky said:

Is there another way to accomplish this

Very likely so - but it would help to know what exactly "this" is. What are you trying to accomplish here, and for what purpose?

It seems you have multiple DateChipsX fields in the Players table. That's not a good thing: numbered fields are a symptom of poor database structure.

Note also that there is no need to go to a field (or any object) in order to check if the field is empty, nor to set a field.

 

Edited by comment
Link to comment
Share on other sites

Thanks Comment,

I removed the go to a field and/or object as you suggested.

The script works fine.

I then attempted the following to shorten the script. 

Set Field By Name 

[Case ( 
$$EventNo=1 ; Players::Wk1 ; 
$$EventNo=2 ; Players::Wk2 ;
$$EventNo=3 ; Players::Wk3 ;
$$EventNo=4 ; Players::Wk4 ;
$$EventNo=5 ; Players::Wk5 ;
$$EventNo=6 ; Players::Wk6 ;
$$EventNo=7 ; Players::Wk7 ;
$$EventNo=8 ; Players::Wk8 ;
$$EventNo=9 ; Players::Wk9 ;
"" )

$$EventNo]

This did not work, ?????

 

Any help appreciated.

Link to comment
Share on other sites

I would just add case statements to the SetField statements.

SetField [Players::DateChips1; Case (DateChips1 = ""; $$EventNo)]

SetField [Players::DateChips2; Case (Players::DateChips1 ≠ "" and Players::DateChips2 = ""; $$EvenNo)

You can then just repeat this as needed.

Link to comment
Share on other sites

24 minutes ago, milky said:

Set Field By Name 

[Case ( 
$$EventNo=1 ; Players::Wk1 ; 
$$EventNo=2 ; Players::Wk2 ;
$$EventNo=3 ; Players::Wk3 ;
$$EventNo=4 ; Players::Wk4 ;
$$EventNo=5 ; Players::Wk5 ;
$$EventNo=6 ; Players::Wk6 ;
$$EventNo=7 ; Players::Wk7 ;
$$EventNo=8 ; Players::Wk8 ;
$$EventNo=9 ; Players::Wk9 ;
"" )

$$EventNo]

This did not work, ?????

 

Any help appreciated.

Having $$EventNo after the Case statement doesn't work.  The way you have the case statement is telling FMP that if $$EventNo = 1, then set the field to Players::Wk1, and if $$EventNo = 2 then set the field to whatever is in the field Palyers::Wk2, and so on.  But then you hvae $$EVentNo tacked on at the end, so let's say $$EventNo is 2, then it's trying to return whats in Wk2 and what's in $$EventNo, but you can't just have two results like that without an operator such as +, -, etc.

Keep in mind that when you use the SetField function, you specify which field you are wanting to change, then use the calculation to change the particular field.  You can't use the calculation to set other fields.

Edited by Tpaairman
Link to comment
Share on other sites

This topic is 399 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.