GSAK (Geocaching Swiss Army Knife)
Contents - Index

SaveFilter (function)

SaveFilter() : string

This function will save all your current filter settings to a variable that can later be used by the RestoreFilter function. Only information saved to a variable by this function can be used in the RestoreFilter function otherwise you will get an error. You would normally save your current filter settings to a variable just by running the following command:
 

$SavedFilter = SaveFilter()


You can then use the $SavedFilter variable at any time later in the macro in the RestoreFilter command to regenerate the filter settings (and run it). To fully understand this function also study the RestoreFilter function.

This function has no parameters, but is a function because it returns a string variable. 

Note: SaveFilter() does not support joined filters (the filter could be the result of many join operations). You can test to see if the current filter is the result of a join or not by using the SysInfo() function. 

There is a way to effectively restore *any* filter, joined or not. However, this method has a subtle, but significant difference in the end result. This difference needs to be understood and evaluated to determine if it is a viable work around/solution for your intended use and audience.

That is, you can take a snap shot of the "codes" in the current filter. When your macro code has finished its work, you can then create a filter of those "codes".

The difference now is that your filter criteria is now basically a "static" one, that just matches those codes.

Below is sample code that shows how this can be done:

# Save the codes in our current filter to a sqldatabase in memory
$status = Sqlite("sql","drop table if exists gsak_mem.FilterSave")
$status = Sqlite("sql","create table gsak_mem.FilterSave as select code from caches where rowid in (select * from gridtemp)")
 
# cancel the current filter to work on the whole database
cancelfilter
msgok msg="Filter now canceled"


# You would now execute your main macro code here
GoSub Name=DoSomething

# Now we need to restore our filter of codes

# First get our list of saved codes via sql
$codes = sqlite("sql","select * from gsak_mem.FilterSave")

# clear out all macro flags
macroflag type=clear range=all

# Now match these codes and set the macroflag
$number = codematch($codes,$_NewLine,"M")

# Now set a filter of our matched codes by filtering on macroflag
Mfilter where=$d_Macroflag

BeginSub Name=DoSomething
# macro code here
EndSub


Note: The FilterSave table is created in the "gsak_mem" database. This is a special "memory" database (used for speed optimization) that is automatically created and then attached to the main database at GSAK start up.  

Related: RestoreFilter()

Alpha List         Category List

Copyright 2004-2019 CWE Computer Services  
Privacy Policy Contact