February 28, 201312 yr Below is an image of my Script. Problem Area:(Highlighted in Yellow) Set Field [Table::Vehicle_Description1; $&"VD&$i Goal: Variables $VD1-$VD8 are holding data. I am doing a loop $i which is a counter that increments from 1 to 8. If there is Data within the variable then I want the field Vehicle_Description1 to be filled with $VD1 on the 1st iteration. Current Output: When running the script, assuming data is in $VD1, I am getting VD1 within Vehicle_Description1 instead of what data is within the variable $VD1. What is unusual: The counter $i is working fine. You can see this with the output VD1 InShort: How do you read a variable when you have to concatenate and read a dynamic variable? Any help or suggestion would be much appreciated.
February 28, 201312 yr Author ricardor BruceR--> Thank you, thank you. I did not know about Evaluate() but I figure that had to be a way. I also would have never known about repetitive variables. It sound as if I do not need to use a counter if I am using a repetitive variable. Wow, that is cool. Learned two new things today. Thank you both again for the valuable feedback, much appreciated.
March 1, 201312 yr Author Or use repetitive variable $VD[1], $VD[2] etc.... by loop $VD[$i] This is going to sound stupid, but how might I do this. Objective: I want to initialize 8 variables VD1 thru VD8 to "". Error: Set Variable[$VD[$i]; Value:""] Logic: Might not be correct either Goal: Use repetitive variable within looping to simply and compress code Below is the code I have come up with thus far: Set Variable[$i: Value:1 Loop Set Variable[$VD[$i]; Value:""] Set Variable [$i; Value:$i+1] Exit Loop If[$i >=8] End Loop
March 1, 201312 yr That's a pretty reasonable approach to set a repeating variable. I would make a couple nitpicky minor changes, but the script is sound. Keep in mind that unlike a lot of programming languages, FileMaker does not "initialize" variables. To FMP, an empty variable is a non-existant variable. Some FMI engineers may strike me down, but there is no difference between "empty" and "null" variables.
March 1, 201312 yr FWIW I generally prefer putting the exit condition at the top of the loop. That way you know nothing ever gets processed if it does not satisfy the exit condition. In this case the process is very simple but in more complicated scripts it makes it easier to assure yourself that it is OK to take this action (change data, delete a record, whatever) Sort of like saying, only touch this data if... Set Variable[$i: Value:1 Loop Exit Loop If[$i >8] Set Variable[$VD[$i]; Value:""] Set Variable [$i; Value:$i+1] End Loop
Create an account or sign in to comment