Allegheny Posted November 14, 2001 Posted November 14, 2001 The "if and else" portion of my brain doesn't seem to be working today. I need a fresh set of eyes to find the error in my script. if (secretword="fred" and global counter <=5) go to layout #2 end if if (secretword="ginger" and global counter <=10) go to layout #2 end if if (secretword="mikhail" and global counter <=15) go to layout #2 else show message (Sorry, you can't enter) close file end if The secretword will never be "ginger" when global counter <=15. I understand, however, that when global counter <=5, the secretword "mikhail" would work. When none of my three conditions are met, I want the program to quit. Right now sometimes it switches layouts (when it's supposed to) and then forces the quit (when it's NOT supposed to). . . as if to say that one of the conditions was met, but it has to force quit anyway. What and I doing wrong?
FUBAR Posted November 14, 2001 Posted November 14, 2001 Track your steps Using your script, lets say that secretword = "fred" and counter = 4... if (secretword="fred" and global counter <=5) <---This is true go to layout #2 end if if (secretword="ginger" and global counter <=10) <---This is false go to layout #2 end if if (secretword="mikhail" and global counter <=15) <---This is false go to layout #2 else <----------------------------------------------This is true show message (Sorry, you can't enter) close file end if So if secret word = "fred" and counter = 4, then the following script steps are being performed... go to layout #2 show message (Sorry, you can't enter) close file Hope this helps
Allegheny Posted November 14, 2001 Author Posted November 14, 2001 How can I better write the consequence for when none of the condisitons are met. Since the "else" didn't work, what should I use?
FUBAR Posted November 14, 2001 Posted November 14, 2001 Couple of ways that you could do this.... 1. if (secretword="fred" and global counter <=5) ... else if (secretword="ginger" and global counter <=10) ... else if (secretword="mikhail" and global counter <=15) ... else ... end if The basis of this method is using a command that FileMaker does not have "Else If" and should work. 2. On the last If, get rid of the else and end the if statement. Then create a new If statement that would go something like this... If ( not secretword = "fred" or not secretword = "ginger" ... or secret word = "fred" and counter > 5 or... ) In other words, a very long if statement that will happen if the other if statements return false. 3. Create a global field ("gFlag") and at the top of the script set it to 0. Then in each of the if statements, above the 'End If' add the command 'Set Field ( gFlag , 1). Then on the last If, get rid of the else and end the if statement. Then create a new If statement that would go something like this... If ( gFlag = 0 ) show message close file end if These are just a few examples and I'm sure there are a lot more ways to solve the problem.
Thom Posted November 14, 2001 Posted November 14, 2001 A Case() statement would make this a lot cleaner. In a calculation, FM considers 0 to be false and anything else to be true. Put this in an If[]step: Case( secretWord="mikhail" and globalCounter <=15, 1, secretWord="ginger" and globalCounter <=10, 1, secretWord="fred" and globalCounter <=5, 1, 0 ) Since the outcome of each match is the same, you can write your script like this: If["Case(...see above...)"] Go to Layout["Layout #2"] Else Show Message ["Go away."] Close [] End If
Kurt Knippel Posted November 15, 2001 Posted November 15, 2001 quote: Originally posted by Thom: A Case() statement would make this a lot cleaner. In a calculation, FM considers 0 to be false and anything else to be true. Not to my knowledge. "F", "False", "N" and "No" all equal 0 (zero) to Filemaker. In addition "T", "True", "Y" and "Yes" all equal 1 (one) to Filemaker. There were some others I think, somewhere I have a list of all the things that equate to 1 or 0, it was pretty exhaustive, but very logical when you look at it. So you need to exercise some caution when using any calculation that might result in any of the above characters as the result. Now in your example, the result would be that those items specified are true (1), while everything else if false (0).
Thom Posted November 15, 2001 Posted November 15, 2001 Thanks, Kurt. I should be more careful with my language. I meant that 0 is false and any other numeric value is true. As you pointed out, words that begin with "T" or "Y" numerically evaluate to 1, and words that begin with "F", or "N" numerically evaluate to 0. Words that begin with other letters have no numeric value. I'd like to see that list, if you could dig it up or point me to it.
Recommended Posts
This topic is 8413 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 accountSign in
Already have an account? Sign in here.
Sign In Now