DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

daily lump sum

I have two questions to solve,
 
1- I would like to have the daily lump sums of consumption ('CONSS' channel) of each day ('DATE' channel). How can I do this with VBscript? I tried with Calculator and with Statistics but it was impossible.
 
2- I created a dialog window with the dialog editor of DIAdem but I am not able to add the "minimize button". Is it possible to add it? If not, is there any other way to solve this problem?
 
I am working with DIAdem 9.0 and I attach you a tdm file as example.
 
Thank you,
 
Núria
0 Kudos
Message 1 of 5
(3,326 Views)

Hi Nuria,

The StatBlockCalc() function has the ability to calculate statistical results such as SUM based on a selected row subset, so the problem basically boils down determining which rows correspond to the same days, then running the statistics calculation only on those rows.  You could determine these row ranges with FormulaCalc functions, and that would be preferable if you wanted to cut out those rows from each channel and create a separate group for each day.  If all you want, though, is to calculate the daily sums, then it's a little easier to do this in a VBScript function.

Try out the below code,
Brad Turpin
DIAdem Product Support Engineer
National Instruments


OPTION EXPLICIT

Dim DayRows, SumChs, DayVals
Call GroupCreate("Daily Totals")
Call GroupDefaultSet(GroupCount)

SumChs = Array("Date", "Temps", "VALDEB", "VALFIN")
Call GetDayRows(DayRows, SumChs, DayVals)
Call CalcSumChs(DayRows, SumChs, DayVals)


'-------------------------------------------------------------------------------------
'-- GetDayRows() --                                               -- NEW SUBROUTINE --
'-------------------------------------------------------------------------------------
Sub GetDayRows(DayRows, SumChs, DayVals)
  Dim i, k, iMax, DayChNum, DayValStart, DayRowStart, DayCurrVal, DayRowStr
  DayChNum = CNo(SumChs(0))
  iMax = ChnLength(DayChNum)
  ReDim DayRows(iMax)
  ReDim DayVals(iMax)
  DayRowStart = 1
  DayValStart = ChDX(1, DayChNum)
  FOR i = 2 TO iMax
    DayCurrVal = ChDX(i, DayChNum)
    IF RTP(Abs(DayCurrVal-DayValStart), "D") > 1 THEN
      Call UpdateDayRows(DayRows, k, i, DayRowStart, DayValStart, DayCurrVal, DayVals)
    END IF ' next day
  NEXT ' i
  Call UpdateDayRows(DayRows, k, i, DayRowStart, DayValStart, DayCurrVal, DayVals)
  ReDim Preserve DayRows(k)
  ReDim Preserve DayVals(k)
End Sub ' GetDayRows()


'-------------------------------------------------------------------------------------
'-- UpdateDayRows() --                                               -- NEW SUBROUTINE --
'-------------------------------------------------------------------------------------
Sub UpdateDayRows(DayRows, k, i, DayRowStart, DayValStart, DayCurrVal, DayVals)
  k = k + 1
  DayRows(k) = DayRowStart
  DayVals(k) = DayValStart
  IF i > DayRowStart+1 THEN DayRows(k) = DayRows(k) & "-" & CStr(i-1)
  DayRowStart = i
  DayValStart = DayCurrVal
End Sub ' UpdateDayRows()


'-------------------------------------------------------------------------------------
'-- CalcSumChs() --                                               -- NEW SUBROUTINE --
'-------------------------------------------------------------------------------------
Sub CalcSumChs(DayRows, SumChs, DayVals)
  Dim i, j, iMax, SumChNum
  iMax = UBound(DayRows)
  FOR i = 1 TO 22
    StatSel(i) = "No"
  NEXT ' i
  StatSel(2) = "Yes"
  StatClipCopy  = 0
  StatClipValue = 0
  StatResChn    = 0
  Call ChnAlloc(ChnName(SumChs(0)), iMax, 1, DataTypeFloat64, "Time")
  SumChNum = CNoXGet(GroupCount, GroupChnCount(GroupCount))
  ChnLength(SumChNum) = iMax
  FOR i = 1 TO iMax
    ChDX(i, SumChNum) = DayVals(i)
  NEXT ' i
  Call ChnCharacter(SumChNum)
  FOR j = 1 TO UBound(SumChs)
    Call ChnAlloc(ChnName(SumChs(j)), iMax)
    SumChNum = CNoXGet(GroupCount, GroupChnCount(GroupCount))
    ChnLength(SumChNum) = iMax
    FOR i = 1 TO iMax
      Call StatBlockCalc("Channel", DayRows(i), SumChs(j))
      ChDX(i, SumChNum) = StatSum
    NEXT ' i
    Call ChnCharacter(SumChNum)
  NEXT ' j
End Sub ' CalcSumChs()

0 Kudos
Message 2 of 5
(3,306 Views)

Hi Brad,

I tried out your code and it gave me the following error:

**** Error registered on 25/10/2005 at 17:41:56 [Message file:GFSAUTED / Text area:4 / Text number:1]
     Error in <NoName(1).VBS> (Row: 79, Column: 7):
     No suitable channels have been specified!
     (channel length 0, channel number 0 or too high)

It stops at this line: Call StatBlockCalc("Channel", DayRows(i), SumChs(j))

I don't know why this happens.

 

**And another question: Is it possible to add the "minimize button" in a dialog window created with the dialog editor of DIAdem v 9.0?

Thanks a lot!

Núria

 

0 Kudos
Message 3 of 5
(3,305 Views)

Hi Nuria,

I did not try out the code on a DIAdem 9.0 version.  I was able to reproduce exactly the error you reported with DIAdem 8.1 (which I had handy), and the following minor change got rid of that error:

Call StatBlockCalc("Channel", DayRows(i), CNo(SumChs(j)))

There is no way that I know of to add a "minimize" option to a SUDialog, but this is for a good reason.  The SUDialog is modal-- meaning nothing can happen in DIAdem until it quits.  If you were able to minimize it, DIAdem would still be unresponsive until the SUDialog quit and the VBScript that started it ended.  Long term we would like to have non-modal SUDialogs, and that would be the point when a "minimize" button would really make sense.

Regards,
Brad Turpin
DIAdem Product Support Engineer
National Instruments

Message 4 of 5
(3,289 Views)

Thanks a lot Brad!

I tried the code and it works fine.

And thank you once again for the explanation about the modal SUDialogs! Smiley Very Happy

Nuria

0 Kudos
Message 5 of 5
(3,286 Views)