Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lecture 7 Conditional Scripting and Importing/Exporting.

Similar presentations


Presentation on theme: "Lecture 7 Conditional Scripting and Importing/Exporting."— Presentation transcript:

1 Lecture 7 Conditional Scripting and Importing/Exporting

2 Administrative To make the project easier, a combined step by step will cover importing/exporting and relational for parts of the project (not all) To make the project easier, a combined step by step will cover importing/exporting and relational for parts of the project (not all) You may find it helpful to review previous lectures while working on the project You may find it helpful to review previous lectures while working on the project I would prefer all projects in by the 17 th (email them to me, or I will set up an online submission) I would prefer all projects in by the 17 th (email them to me, or I will set up an online submission) Last lecture is on the 10 th but I may upload one additional lecture for you to review on your own Last lecture is on the 10 th but I may upload one additional lecture for you to review on your own

3 Administrative(pg 2) The test details and study guide will be given on the 10 th The test details and study guide will be given on the 10 th You will have until the 22 nd to take the test online at your convenience (1 hour time limit) You will have until the 22 nd to take the test online at your convenience (1 hour time limit) I recommend starting on the project soon. I recommend starting on the project soon.

4 Summary Lecture 6 Advanced Finds Advanced Finds Calculations Calculations  Conditional  Logical  String/Number Ops  Comment

5 Topics Script Conditional Script Conditional  If statement  Loop  Set Field  Replace Importing Importing Exporting Exporting

6 Script Conditionals We learned simple scripts, now let’s add some real power using what we learned last time We learned simple scripts, now let’s add some real power using what we learned last time Just as in calculations you can use If statements. There are the following differences Just as in calculations you can use If statements. There are the following differences  There is no case equivalent  You can choose to perform or not perform script steps based on the result  You use it in combination with a calculation to determine what step to take next.

7 Script Conditionals Often times it is used with the Status(flag) function. Often times it is used with the Status(flag) function.  The Status function takes in a flag that can give you information about the system for example:  Which button was pressed = Status(CurrentMessageChoice) = 2 (was the second button pressed)  How many records were found Status(CurrentFoundCount) = 1 (was only one record found)

8 Script Conditionals  There is also an else step that can be put after the if. This is used if you have mutually exclusive conditions and you want the later to ONLY be executed if the if is false  Which of these scripts works for finding out which button was pressed and why

9 Script Conditionals 1.ShowMessage(“Message”) If(Status(CurrentMessageChoice)=1 ShowMessage(“Button one pressed”) Else ShowMessage(“Button two pressed”) EndIf ShowMessage(“Button three pressed”) 2.ShowMessage(“Message”) If(Status(CurrentMessageChoice)=3 ShowMessage(“Button three pressed”) EndIf If(Status(CurrentMessageChoice)=2 ShowMessage(“Button two pressed”) EndIf If(Status(CurrentMessageChoice=1 ShowMessage(“Button one pressed”) EndIf

10 Script Conditionals Here is another CORRECT way to do it: ShowMessage(“Message”) If(Status(CurrentMessageChoice)=1 ShowMessage(“Button one pressed”) Else If(Status(CurrentMessageChoice)=2 ShowMessage(“Button two pressed”) Else ShowMessage(“Button three pressed”) EndIfEndIf

11 Script Conditionals  Usually when you have one all or nothing decision an else is good otherwise just use multiple If’s; just remember anything not between an If and an EndIf will ALWAYS be executed  One important thing to notice is that everything is indented to show you what is within each If statement

12 Script Conditionals  As you can see the outer if statement(Red) Engulfs the smaller If Statement(Blue) this is similar to a case statement where if the first is true then use that else check next etc.

13 Script Exercise  Now using CurrentFoundCount come up with a script that brings up a message if there are zero arguments and takes the user to a “main” layout, takes the user to the “edit” layout if there is only one record, and takes the user to a “list” layout if there are more than one records.

14 Script Exercise Here is one way to do it, try it a different way in your project remember the areas outside of your “ifs” can contain things done by all paths Here is one way to do it, try it a different way in your project remember the areas outside of your “ifs” can contain things done by all paths Remember anything that could be done with verification can also be done here, you are not limited to the status function Remember anything that could be done with verification can also be done here, you are not limited to the status function

15 Loops Loops allow you to go through the records, usually sequentially, until some end state is reached. Loops allow you to go through the records, usually sequentially, until some end state is reached. Make sure and put an end state in or you may end up in an infinite loop! Make sure and put an end state in or you may end up in an infinite loop! Here’s an example script with two exit conditions, if the criteria is found or if the last record comes up Here’s an example script with two exit conditions, if the criteria is found or if the last record comes up

16 Loops Loops allow you to go through the records, usually sequentially, until some end state is reached. Loops allow you to go through the records, usually sequentially, until some end state is reached. Make sure and put an end state in or you may end up in an infinite loop! Make sure and put an end state in or you may end up in an infinite loop! Here’s an example script with two exit conditions, if the criteria is found or if we get to the last record without finding it Here’s an example script with two exit conditions, if the criteria is found or if we get to the last record without finding it

17 Loops So let’s analyze this in detail So let’s analyze this in detail  First freeze window this a performance enhancer it keeps us from having to redraw the screen every time  Next we go to the first record this is because we have no idea what record the user is on

18 Loops  Notice that first record is outside of the loop, can anyone tell me what would happen if this was inside the loop?  Notice the goto field step? It is not necessary but it does make it easier to read  Next is our conditional it prints out a box if the record is found and then exits the script, the exit script was done so that we can put some stuff after the loop to be done in case the record is not found.

19 Loops  Finally in the gotorecord(ExitAfterLast,Next) you’ll notice the ExitAfterLast box is checked that means it will exit when the last record is hit (our second check)  While this is a trivial example(it is essentially a find) it does show good looping practices

20 Loops  Finally in the gotorecord(ExitAfterLast,Next) you’ll notice the ExitAfterLast box is checked that means it will exit when the last record is hit (our second check)  While this is a trivial example(it is essentially a find) it does show good looping practices  To show the true power of a loop we need a way to set the information

21 SetField  SetField this let you change any field, regardless of whether it is on the current layout or not.  You can use it without loops, an example would be if you have a mailing address and billing address and you don’t want to have to type the whole billing address if it’s the same instead you can have a button that has a series of setfields that sets the billing street to the mailing street etc.

22 SetField  With loops SetField allows you to reformat or fix fields based on other fields, or that field.  There is another script step that is similar but requires no loop: replace  Replace is faster but it is easier for a careless mistake to ruin data  With replace you have to use a calculation to determine which to replace, with set field that calc can be done within the loop.

23 Import  You can import from a number of different sources I won’t go over the specifics of the sources since they differ across mac and pc and also among the different versions  Flat File = a textual representation of the information in a database usually with tabs between fields and CR(a return) between records.  The above is usually the type of output you would get from Sys200 or from a scanner.

24 Import  I recommend starting with tab-deliminated files(mentioned above)  You can get excel to export in this way the advantage is you don’t have to worry about versions.  Beware the mac version of FMPro has problems reading certain types of files, if it doesn’t work open it with BBEDIT and save it with BBEDIT

25 Steps for Importing  While I am going to give the steps manually I strongly recommend you make a script for your users.  Go to File…Import/Export…Import records  Select your file and then…

26 Steps for Importing  You will be presented with a screen like this:  You can scan through the data using the >> buttons  You can choose on the bottom to have the new data replace the old or be added to.

27 Steps for Importing  You will see an arrow -> next to any data that is going to be moved over you can uncheck it to not move that info into your database (e.g. if there is a field in the text you don’t need in your db)  You can move the fields around also if they don’t seem to match up with the ones that you were given  When you’re done select import  Next you will be presented with another screen, this screen asks if you want to perform autoentry actions, usually you will want to do this as it will fill in all your calculated fields.


Download ppt "Lecture 7 Conditional Scripting and Importing/Exporting."

Similar presentations


Ads by Google