Problem using IF COMPARE_STR

falqnfalqn Global Mapper UserPosts: 123Trusted User
edited June 2015 in GM Script Language
Hi,
I have a simple workspace (see attachement) with objects named A, B and C. I do not understand why script described below is not working.

GLOBAL_MAPPER_SCRIPT VERSION=1.0
IF COMPARE_STR="<Feature Name>=A"
EDIT_VECTOR COPY_TO_NEW_LAYER=YES NEW_LAYER_NAME=A
END_IF

I think this script should work. What's wrong?
I'm using latest v16.1.4.

Regards
Wojtek

Comments

  • bmg_bobbmg_bob Global Mapper Programmer Posts: 2,268
    edited April 2015
    Hi Wojtek,

    What are you trying to do?

    In the IF command, the COMPARE_STR must consist of <value><operation><value>, where either <value> can be a constant or a variable name (enclosed in "%"). Both values must be specified. The <value> is not an attribute name.

    This means that your statement:

    IF COMPARE_STR="<Feature Name>=A"

    is testing to see if the string "<Feature Name>" is equal to "A", which it is not. The following script is an example of using the IF command:
    DEFINE_VAR NAME="NAME" VALUE="A"
    IF COMPARE_STR="%NAME%=A"
    [COLOR=#000000]EDIT_VECTOR COPY_TO_NEW_LAYER=YES NEW_LAYER_NAME=A[/COLOR]
    END_IF
    

    Are you trying to copy all features with <Feature Name>=A to new layer "A"?

    This script will do that:
    GLOBAL_MAPPER_SCRIPT VERSION=1.0
    EDIT_VECTOR COPY_TO_NEW_LAYER=YES COMPARE_STR="<Feature Name>=A" NEW_LAYER_NAME=A
    

    Cheers,

    Bob




  • falqnfalqn Global Mapper User Posts: 123Trusted User
    edited April 2015
    Hi Bob,
    Thank you, I overlooked that the <value> is not and can't be the name of the attribute.
    Regards
    Wojtek
  • monagoosemonagoose Global Mapper User Posts: 7
    edited June 2015
    I am having a slightly different problem with the IF COMPARE_STR statement not allowing for null values.

    DEFINE_VAR NAME="CONT_INTERVAL" PROMPT=YES ABORT_ON_CANCEL=YES PROMPT_TEXT="Please enter the Contour Interval"
    IF COMPARE_STR="%CONT_INTERVAL%="
    DEFINE_VAR NAME="CONT_INTERVAL" VALUE="1"
    END_IF


    Basically if the ok button is pressed without entering a value, then a default value is used.
  • bmg_bobbmg_bob Global Mapper Programmer Posts: 2,268
    edited June 2015
    Hello,

    What version of Global Mapper are you using?
    When I ran your script, I got a message indicating that the left-hand value was missing. Did you get the same result?
    This is a case that should work. I will do some more investigation to see what is going wrong.

    Cheers,

    Bob
  • monagoosemonagoose Global Mapper User Posts: 7
    edited June 2015
    Hi Bob,

    That is the same error that i get, i believe i am using version 16.0.1, but do not quote me on that as i do not have access to my work computer atm and wont be back at work again till Monday (Friday is a local show holiday here). It seems that if a value is not entered into the text box, the CONT_INTERVAL value is not being read as an empty value or anything (hence the error) by the COMPARE_STR command.
  • bmg_bobbmg_bob Global Mapper Programmer Posts: 2,268
    edited June 2015
    Hello,

    I corrected that problem, and have placed new builds with the latest changes at Global Mapper Downloads. Simply download the appropriate installer and run it to install the latest build.
    Cheers,

    Bob
  • monagoosemonagoose Global Mapper User Posts: 7
    edited June 2015
    Hi Bob,

    Thanks that update worked a treat.
Sign In or Register to comment.