Preprocessor vlookup macro

+1 vote
asked Apr 5, 2020 in Question / help by gobravedave (200 points)

I am loving PlantUML and have many lines of script.. As the number of lines of script grows, the overall effort to keep the diagrams consistent and standard gets difficult.

To assist, I am attempting to write a simple macro which works along the lines of a excel vlookup where you pass in a search string, a file name of what is to be searched and an offset value to be returned.

However i am struggling on my first attempt with a parsing error. I am hoping some fresh eyes can help.. or even better if someone in the plantuml community has already done something along these lines.  

thank you,

David.

@startuml vlookup test

!preprocessorV2

!unquoted function $vlookup( $id, $range, $offset)

   !log vlookup on $id

   '!log vlookup on %get_variable_value("$id")

   !$row1 = "cm|customer master|manages customers"

   !$row2 = "tm|transaction manager|manages transactions"

   !$row3 = "am|account manager|manages accounts"

    '%set_variable_value("$row1", "cm|customer master|manages customers" )

    '%set_variable_value("$row2", "tm|transaction manager|manages transactions" )

    '%set_variable_value("$row3", "am|account master|manages accounts" )

    !if ($id == "cm")

      '!return %get_variable_value("$row1")

      !return $row1

    !endif

    !if ($id == "tm")  

      '!return %get_variable_value("$row2")

      !return $row2

    !endif

    !if ($id == "am")  

      '!return %get_variable_value("$row3")

       !return $row3

   !else

        !return "error"

    !endif

 !endfunction

!$note = $vlookup("cm", "system.iuml", 1)

component comp1 [

$note

]

@enduml

1 Answer

+2 votes
answered Apr 5, 2020 by plantuml (276,340 points)
commented Apr 7, 2020 by gobravedave (200 points)
commented Apr 7, 2020 by albert (3,180 points)
@plantuml You just beat me when I was analysing the problem.

Am I corect that the problem lies in the "1" of "row1"
commented Apr 7, 2020 by gobravedave (200 points)
thanks again.. the numeric variable name, assuming @albert is correct, is going to be important for the script as I introduce the looping thru each of the rows to find the matching $id..
commented Apr 7, 2020 by albert (3,180 points)
As far as I can see on the online server the version wit the numeric value is working.
...