GSAK (Geocaching Swiss Army Knife)
 

Contents - Index


Mfilter (command)

MFILTER <Expression=valid expression> [<Reverse=Yes|No>] [<Join=None|or|and|xor|andnot|ornot|xornot>]

The MFILTER (Macro Filter) command allows you to set filters on the fly without having to set them up and save them. Not all the functionality of the filter dialog is supported. If you can't generate the filter you want using this command then you will still need to set up a filter, save it, then use the FILTER command. 

Expression = Basically, all you need to do is enter an expression that evaluates to a Boolean value after the expression= token. In fact the syntax is exactly the same as any valid IF command, however as we are dealing with the database you should at least reference 1 database variable. Note: Prior to version 7 this parameter was If=. This is still supported for backwards compatibility but you should now always use Expression=.

Reverse =  Yes - To invert/reverse the filter (That is, give you all the waypoints that do not match your selection criteria). No - do not reverse. The default value is No

Join = Action to perform with the current filter. The default of "none" meaning the Filter command does not do any "joining" and behaves exactly the same as setting a new filter. Any other value will compare the current filter against this filter using the "join" type and produce a new subset/filter (which will then become the current filter and you can do another "join" and so forth). See join notes for a full explanation of Join.



Sample code:
  
# set  filter on all found caches
MFILTER Expression=$d_Found

# set a filter on all caches found in the last 7 days
MFILTER Expression=$d_LastFoundDate > $_Today - 7

# set a filter on all caches that contain "hill" (ignore case)
MFILTER Expression=regex("hill",$d_name)

# set a filter on all caches that start with "The" (ignore case)
MFILTER Expression=regex("^the",$d_name)

# set a filter on all caches that are not found, and not archived, and not temp disabled
MFILTER Expression= not($d_found) and not($d_Archived) and not($d_TempDisabled)

# another way to set the previous filter 
MFILTER Expression=not ($d_Found or $d_Archived or $d_TempDisabled)
 
When iterating through a database, it is far more efficient to set a filter first if you can rather than use IF statements within the while loop. For example let us say you want to perform some commands on only found caches:

# bad (inefficient, especially on large databases)
While  not($_EOL)
IF $d_Found
    .... do some commands
ENDIF
GOTO Position=Next
ENDWHILE

# good, far more efficient
MFILTER Expression=$d_Found 
While ($_EOL)
  .... do some commands
   GOTO Position=Next
ENDWHILE 

When you use the MFILTER command you will notice the left most status panel of the grid will show in red "Subset: Macro Filter". This will let you know the current sub set has been set by the MFILTER command. Note: These settings are at the macro level only and are not reflected in the Filter dialog (if you bring up the dialog there will be nothing set)

Note: If the filter does not return any waypoints it will automatically be cancelled and your subset will contain all waypoints. You can test for this situation using the $_FilterCount system variable. For example:
MFILTER Expression=$d_UserFlag
IF $_FilterCount > 0
  ... do some action
ELSE
  PAUSE Msg="No waypoints in filter, action cancelled"
ENDIF

This command does have few  quirks:
1. Memo fields are not supported. These include $d_UserNote, $d_LongDescription, $d_ShortDescription, $d_TravelBugs, $d_Hints
2  Do not enclose the expression in double quotes (because of the nature of an expression you may already have double quotes as part of the expression)
3. MFilter is a portal to the raw database, engine so only functions that exist in the raw database engine are supported these include:

not
Abs
AllTrim
Asc
AT
chr
Exp
Extract
IsEmpty
IsOwner
Left
len
Quote
RegEx
RegExCount
RegExData
Replace
Right
Str
Substr
Time
Trim
Upper
Val

Summary



Copyright 2004-2008 CWE Computer Services  
Privacy Policy Contact