Example: LoadHistoricalData method

Module code
Option Explicit Type TransactionInfo 'Create storage type nID As Long 'Transaction ID dtStart As Date 'Starting time and date nStartMS As Long 'Millisecond offset from dtStart dtEnd As Date 'Ending time and date nEndMS As Long 'Millisecond offset from dtEnd aPens As Variant 'Array of tags indexs needing data End Type
Form code
Option Explicit 'chart does not dispatch more than 2 requests at any time Dim tiTransactions(3) As TransactionInfo 'static que defined Dim nTransactionsPending As Integer ' Private Sub Timer1_Timer() ' This is an async method to feed historical data to the trend ' Note: Typically this would be done via a PostMessage() or other means Private Sub Timer1_Timer() Dim vTagData As Variant Dim nLastTransactionPending As Integer Dim nCurrTransaction As Integer nLastTransactionPending = nTransactionsPending 'loop through the pending transactions in FIFO order While nTransactionsPending nCurrTransaction = nLastTransactionPending - nTransactionsPending 'build the historical data array GetSamples tiTransactions(nCurrTransaction), vTagData 'send the historical data Trend1.LoadHistoricalData tiTransactions(nCurrTransaction).nID, vTagData nTransactionsPending = nTransactionsPending - 1 Wend End Sub ' Private Sub GetSamples(ti As TransactionInfo, ByRef varData As Variant) ' ti contains the current historical transaction being processed ' varData is an out parameter containing the array of data for the' current historical transaction ' Note: This just generates sample data to feed the trend Private Sub GetSamples(ti As TransactionInfo, ByRef varData As Variant) Dim dtNow As Date Dim varArray As Variant Dim nSampleCount As Integer Dim nSample As Integer 'Get the number of samples in the range nSampleCount = DateDiff("s", ti.dtStart, ti.dtEnd) 'resize the array to hold the samples ReDim varArray(nSampleCount, 4) As Variant dtNow = ti.dtStart 'index through the samples filling with sample data For nSample = 0 To nSampleCount 'set pen name varArray(nSample, 0) = ti.aPens(0) 'set time dtNow = DateAdd("s", 1, dtNow) varArray(nSample, 1) = dtNow 'set ms varArray(nSample, 2) = 0 'set value varArray(nSample, 3) = nSample Next nSample varData = varArray End Sub Private Sub Trend1_HistoricalDataRequested(ByVal TransactionID As Long, ByVal StartTime As Date, ByVal StartMS As Long, ByVal EndTime As Date, ByVal EndMS As Long, ByVal Pens As Variant, WillProcess As Boolean) 'Store the request in a que for async processing 'The request must be processed after this event has returned tiTransactions(nTransactionsPending).nID = TransactionID tiTransactions(nTransactionsPending).dtStart = StartTime tiTransactions(nTransactionsPending).nStartMS = StartMS tiTransactions(nTransactionsPending).dtEnd = EndTime tiTransactions(nTransactionsPending).nEndMS = EndMS tiTransactions(nTransactionsPending).aPens = Pens nTransactionsPending = nTransactionsPending + 1 WillProcess = True 'Let the chart know that it will get a response End Sub
Provide Feedback
Have questions or feedback about this documentation? Please submit your feedback here.
Normal