Ask the Simul8 Community

Using Visual Logic to change Global Data Item value from input spreadsheet

tom100tom100
Created at
in Community support

Hi all,

I am struggling with updating Global Data Item values from a spreadsheet. I want to be able to change a variable value in a spreadsheet (for example, column 1 equals global data item name and column 2 equals global data item variable value), and update this in my model using Visual Logic (VL). I have many variables and so I would like to loop through each of these values and overwrite the pre-existing value.

I have worked out how to create a Global Data Item in VL using, for example, this line of code:
Create Global Data Item Inputs spreadsheet[2,row_no] , Number , Inputs spreadsheet[3,row_no]
but is it possible to then overwrite this value (after changing its numerical value in the Inputs Spreadsheet) using VL? For example, a function like this (note that this function does not exist!):
Overwrite Global Data Item Inputs spreadsheet[2,row_no] , Number , Inputs spreadsheet[3,row_no]

I have tried erasing the variable and then creating a new one using this logic:
Erase Global Data Item Inputs spreadsheet[2,row_no]
Create Global Data Item Inputs spreadsheet[2,row_no] , Number , Inputs spreadsheet[3,row_no]
however this creates an error message because this variable is used in VL code elsewhere..

Any help would be much appreciated!
Thanks



Tagged:

Comments

  • Was this answer helpful?


    1

    Hi David,

    Thank you for your suggestion. Unfortunately I don't think it's possible to use the Erase Simulation Object command as a Global Data Item is not a 'simulation object'. I just tried using this method but without success. The problem with using the SET command as you have suggested is that this line of code
    "SET Inputs spreadsheet[3, row_no] = [value]"
    will set the actual spreadsheet value (in column=3, row=row_no) to 'value' instead of the global data item receiving this new value. I think the issue is that the global data item's value is assigned the raw spreadsheet value (at Inputs spreadsheet[3, row_no]) instead of a reference to this cell where an updated cell value could then automatically update a global data item's value.

    Do you have any other suggestions?

  • Was this answer helpful?


    0

    Hi Tom. I think that Erase Simulation Object will work if you are erasing something like a Number or Text global variable. I think spreadsheet cells cannot be erased and that might be giving the error. Instead of erasing, you can simply use the SET command and write it as:

    "SET Inputs spreadsheet[3, row_no] = [value]"

    David

  • Was this answer helpful?


    0

    Hi Tom, could you also try it the other way around like SET [value] = Inputs spreadsheet[3,row_no] ?

  • Was this answer helpful?


    0

    Hi Tom,
    I'm currently facing the same problem.
    I created multiple (hundreds) global data items via the "Create Global Data Item" command. After I've linked them to other VL-Sections of activities they can't be erased anymore. And sadly I haven't found a way how to set them userfriendly in a loop.
    The only way I found was to list them all manually one after another in the code which would blow the code massive.

    Have you found a solution for this problem?

    Br,
    Sebastian

  • Was this answer helpful?


    0

    Use a spreadsheet to keep the values.

Leave a Comment

BoldItalicStrikethroughOrdered listUnordered list
Emoji
Attach file
Attach image
Align leftAlign centerAlign rightToggle HTML viewToggle full pageToggle lights
Drop image/file