Forum Discussion

Marco's avatar
Marco
Contributor II
5 months ago

How to sum three times in a single getdatacell

Hi Everyone.

What I want to achieve is to obtain the amount of three times in a single getdatacell. What I have is the following:

Dim first As Decimal = api.Data.GetDataCell("S#[" & strScenario & "]:" & timesTest(0) & ":E#30801_30800:A#FINVOLUME:F#None:O#BeforeAdj:U1#D0000:U2#P0100:U3#LOCAL_DATA:U4#PJ00000").CellAmount

The issue is that I need to use three different times, but I don’t want to create three variables to sum those values, and I also don’t want to do something like the following:

'Example
Dim tot as Decimal = api.Data.GetDataCell("#Time1" + "#Time2" + "#Time3")

So, I wanted to see if there is a way to put all the times together in one so that the sum is done internally, or if it can only be done as shown above. I hope you can explain the best method to achieve this.

  • chul's avatar
    chul
    Contributor III

    You can write a loop that will run as many times as you want. Dim a result, set it to zero. First time through the loop, grab the amount from Time1 and add it to the result. Second time through the loop, grab the amount from Time2 and add it to the result. Third time, same. Exit loop and you have your result.

    Be careful that you write an exit to the loop as you don't want it loop indefinitely.