hexagon logo

Assigning a variable from a variable assignment

Hello I would like to do something like the following but I cannot get it to work and coffee has still to hit my this Friday morning:

Assign - Counter=1
Assign - V1=1
Assign - VCALL="V"+Counter

Now, I would like for VCALL to take the value of 1 instead of the string "V1". Keep in mind that this is a super simplified example but should give the idea of what I am after. I tried these pointer brackets {} but they don't seem to work. Creating a function does not seem to work either. I am getting a string with the name of the variable instead of the value in the variable :S

Any help here guys please?
  • PC_DMIS stores assignment values as variants and automatically coerces their operand type based on the contents. You can add the INTEGER, DOUBLE, STRING or POINT functions to force your variable to be the operand type that you want: PC-DMIS Help Center - 2023.1 (hexagonmi.com)

    In your case, you'd probably need to have either INTEGER(S) or DOUBLE(S).
  • Hi !
    Not sure to understand what you want to do...

    ASSIGN/COUNTER=1
    ASSIGN/V1=1
    ASSIGN/VCALL=COUNTER+V1​

    In this case, VCALL=2
    Do you want that V1 is the start value, then increment with counter ?
  • Hi !
    Not sure to understand what you want to do...

    ASSIGN/COUNTER=1
    ASSIGN/V1=1
    ASSIGN/VCALL=COUNTER+V1​

    In this case, VCALL=2
    Do you want that V1 is the start value, then increment with counter ?


    So I will make the request more complicated (as is) to be more clear:

    I have a loop and assignments as

    V1=3
    V2=5
    v3=1000
    .
    .
    .


    random numbers in general in the variables.

    Within my loop I want to populate a seperate variable lets say VCALL to take the value of the V variables based on the counter of the loop.
    So first run will take the V1 value of 3 meaning VCALL=3. Second run of loop will take VCALL=5 etc.
    How do I achieve this? My mind is blocked :P
  • Rather than having V1, V2 & V3 as separate assignments, you could put the values in an array like this...

          assign/v1=array(3,5,1000)
                assign/counter=0
                do/
                  assign/counter=counter+1
                  assign/vcall=v1[counter]
                  comment/oper,no,full screen=no,auto-continue=no,ovc=no,
                  vcall
                until/counter==3​
    
  • So this means I cannot do it with pointers right? In fact I found a way (coffee finally kicked in) check next comment
  • So I found a way...

    ASSIGN/V1=5
    ASSIGN/COUNTER=1
    ASSIGN/V2="V"+COUNTER
    ASSIGN/V3=V2.X
    F1 =GENERIC/POINT,DEPENDENT,CARTESIAN,$
    NOM/XYZ,<0,0,0>,$
    MEAS/XYZ,<V3,0,0>,$
    NOM/IJK,<0,0,1>,$
    MEAS/IJK,<0,0,1>​


    F1.X will have the value 5 that I am after. Still..... there should be an easier way apart from the Array solution proposed by neil. I am not sure why ASSIGN/V2={"V"+COUNTER} does not work
  • What are you exactly trying to do?

    You do something like this, as this is what I use for my "looping":

    ASSIGN/COUNT=0
    TOTAL_LBL =LABEL/
    ASSIGN/COUNT=COUNT+1
    IF/COUNT=="4"
    ASSIGN/X_VAR=1.313*0
    ASSIGN/Y_VAR=1.25*3
    GOTO/PART_LBL
    END_IF/
    IF/COUNT=="3"
    ASSIGN/X_VAR=1.313*0
    ASSIGN/Y_VAR=1.25*2
    GOTO/PART_LBL
    END_IF/
    IF/COUNT=="2"
    ASSIGN/X_VAR=1.313*0
    ASSIGN/Y_VAR=1.25*1
    GOTO/PART_LBL
    END_IF/
    IF/COUNT=="1"
    ASSIGN/X_VAR=1.313*0
    ASSIGN/Y_VAR=1.25*0
    GOTO/PART_LBL
    END_IF/
    PART_LBL =LABEL/
    LOOP_XY =GENERIC/POINT,DEPENDENT,CARTESIAN,$
    NOM/XYZ,<0+0,0+0,0+0>,$
    MEAS/XYZ,<X_VAR,Y_VAR,0+0>,$
    NOM/IJK,<0+0,0+0,1+0>,$
    MEAS/IJK,<0+0,0+0,1+0>
    LOOP_ALN =ALIGNMENT/START,RECALL:FIXTURE_ALN,LIST=YES
    ALIGNMENT/TRANS,XAXIS,LOOP_XY
    ALIGNMENT/TRANS,YAXIS,LOOP_XY
    ALIGNMENT/END
    


    Then I have a code at the end that satisfies the total loop count to then end the program or it goes back to the label. You can do this with the DO / UNTIL flow control as well. ​​
  • Have variable like: V1=5, V=12, V3=20.... that are feed from a form.

    Within a loop I populate another Variable (VCALL) with the value of V+counter. For example 2nd loop, the Vcall will be 12, 3rd loop the VCALL would be 20 and so on.
  • Like this ?
    ASSIGN/V1=ARRAY(1,3,5,1000)
    V2 =LOOP/START,ID=YES,NUMBER=4,START=1,SKIP=,
    OFFSET:XAXIS=0,YAXIS=0,ZAXIS=0,ANGLE=0
    ASSIGN/V3="V"+V2
    ASSIGN/V4=V3.XYZ
    ASSIGN/V5=V3.IJK
    F1 =GENERIC/POINT,DEPENDENT,CARTESIAN,$
    NOM/XYZ,<V4.X,V4.Y,V4.Z>,$
    MEAS/XYZ,<V4.X,V4.Y,V4.Z>,$
    NOM/IJK,<V5.I,V5.J,V5.K>,$
    MEAS/IJK,<V5.I,V5.J,V5.K>​
    LOOP/END


    or
    ASSIGN/V4="V"+V2+".XYZ"
    ASSIGN/V5="V"+V2+".IJK"
  • What you are trying to do is possible, but I don't remember how? bahahaha!

    Very handy when you have a bunch variables (after the fact) and need to ram through them.