DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

VB Script not working correctly the first attempt

Solved!
Go to solution

I have a VB script that loads the active channels data into a Report. 

The weird thing is that upon first run (pressing F5) of the script it does not update my Graph Data on either page of my 3 page Report (1st page has a table and the 2/3 pages have a graph). Upon the second attempt of running the script it will update the Graph on page 2 but the not on page 3 and finally one the third run of the script it will update page 3's Graph.

I added code to cycle through each sheet and bring the active sheet to the front of the Report but no change in behavior. I can simply ad a For Loop to repeat the data loading procedure 3 times but this is just bad coding in my opinion, I would like my code to be efficient.

 

If anyone has any ideas or similar experiences please let me know what resolution you came too. Code is below.

Thanks.

 

---------------------------------------------------

 

Option Explicit  'Forces the explicit declaration of all the variables in a script.

'PScript Function --- Finds the Graph or Table to be Changed and calls Subroutine

Dim iObjNo, sObjectName, sCurveName, iCurveNo, iSheetNo, aSheetName, 

'---- Cycles Through the Graphic Sheets of the Report
For iSheetNo = 1 to GraphSheetCount
  aSheetName = GraphSheetNGet(iSheetNo)
  GraphSheetShow(aSheetName)

  For iObjNo = 1 To ObjectNoMax         'Loop over all objects in DIAdem REPORT
    sObjectName = ReportObj(iObjNo)     'Gets the object name
    If sObjectName <> "" Then           'Ensures that the object is not deleted
      Select Case ReportObjType(iObjNo) 'Gets the object type
      Case "2D-Axis"
        Call Change2DAxis(sObjectName)  'Calls procedure to change the objects of the 2D axis system
      Case "2D-Table"
        Call Change2DAxisTable(sObjectName)
      Case "FreeText"
        Call GraphObjMoveToForeground(sObjectName)
      End Select
    End If
  Next
  Call PicUpdate(True)
Next 'goto next sheet


' --- Procedure to change object of the 2D axis graph system ---
Sub Change2DAxis(sObjectName)          
  Call GraphObjOpen(sObjectName)       'Opens the 2D axis system
    D2AxisColor      = "blue"          'Sets the axis color
    For iCurveNo = 1 To CurveNoMax     'Loop over all curves
      sCurveName= D2CurveObj(iCurveNo) 'Gets the curve name
      If sCurveName <> "" Then         'Ensures that curve is not deleted
        Call GraphObjOpen(sCurveName)  'Opens the curve object
          
          '--- Gets a reference to the active channel and set the data for the correct graph
          If sObjectName = "DELCDgraph" Then
            D2CChnYName = Data.Root.ActiveChannelGroup.Channels.Item("DELCD").GetReference(eRefTypeIndexName)      'Sets the curve to the Current Channel
          End If
          
          If sObjectName = "PIDgraph" Then
            D2CChnYName = Data.Root.ActiveChannelGroup.Channels.Item("PID").GetReference(eRefTypeIndexName)      'Sets the curve to the Current Channel
          End If
          
          D2CurveColor = "red"         'Sets the curve color
        Call GraphObjClose(sCurveName) 'Closes the curve object
      End If
    Next
  Call GraphObjClose(sObjectName)      'Closes the 2D axis system
End Sub


' --- Procedure to change table object values of column 2 ---
Sub Change2DAxisTable(sObjectName)          
  Call GraphObjOpen(sObjectName)       'Opens the 2D axis system
    
    If sObjectName = "DELCDtable" Then
        '--- Gets a reference to the active channel
        D2TabChnName(2) = Data.Root.ActiveChannelGroup.Channels.Item("Concentration").GetReference(eRefTypeIndexName)
        ' --- Gets references to permanant channel containing Compound Names and Units
        D2TabChnName(1) = Data.Root.ChannelGroups(1).Channels("Compound").GetReference(eRefTypeIndexName)
        D2TabChnName(3) = Data.Root.ChannelGroups(1).Channels("Units").GetReference(eRefTypeIndexName)
    End If
    
    If sObjectName = "PIDtable" Then
        '--- Gets a reference to the active channel
        D2TabChnName(2) = Data.Root.ActiveChannelGroup.Channels.Item("Concentration").GetReference(eRefTypeIndexName)
        ' --- Gets references to permanant channel containing Compound Names and Units
        D2TabChnName(1) = Data.Root.ChannelGroups(1).Channels("Compound").GetReference(eRefTypeIndexName)
        D2TabChnName(3) = Data.Root.ChannelGroups(1).Channels("Units").GetReference(eRefTypeIndexName)
    End If
    
    If sObjectName = "mainTable" Then
        '--- Gets a reference to the active channel
        D2TabChnName(2) = Data.Root.ActiveChannelGroup.Channels.Item("Concentration").GetReference(eRefTypeIndexName)
        ' --- Gets references to permanant channel containing Compound Names and Units
        D2TabChnName(1) = Data.Root.ChannelGroups(1).Channels("Compound").GetReference(eRefTypeIndexName)
        D2TabChnName(3) = Data.Root.ChannelGroups(1).Channels("Units").GetReference(eRefTypeIndexName)
    End If

  Call GraphObjClose(sObjectName)      'Closes the 2D axis system
  
End Sub

' --- Renames all Sheets of the current report with the Sample Name
Call GraphSheetRename("TABLE", Data.Root.ActiveChannelGroup.Name & " Table")
Call GraphSheetRename("PID", Data.Root.ActiveChannelGroup.Name & " PID")
Call GraphSheetRename("DELCD", Data.Root.ActiveChannelGroup.Name & " DELCD")

Call PicUpdate(True)

 

0 Kudos
Message 1 of 7
(4,437 Views)

Hi techerdone,

 

One simple way to troubleshoot these type of errors is to use the record button in the SCRIPT tab. The icon is located to the right of the calculator icon on top. You can manually update all three pages of  your report, stop the recording and compare the code from the recording to your own and see where the mistake might be.

 

I hope this helps.

 

Josh L.

Applications Engineer
National Instruments
0 Kudos
Message 2 of 7
(4,413 Views)

The recording mode is kind of a joke. Maybe it's good for 2+2 but it does not seem to record 98% of what I do. Maybe I'm missing something? It also does not seem to be variable friendly. I much prefer scripting either way.

This is what it recorded for the actions that parallel the code I attached above.

Call PicUpdate(0)                       '... PicDoubleBuffer 
Call PicUpdate(0)                       '... PicDoubleBuffer 
Call PicUpdate(0)                       '... PicDoubleBuffer 
Call GRAPHSHEETRENAME("TABLE", "TABLE") '... GraphSheetName,GraphSheetNameII
Call GRAPHSHEETRENAME("TABLE", "FO.GC.212__@@CurrDate@@TABLE") '... GraphSheetName,GraphSheetNameII
Call GRAPHSHEETRENAME("FO.GC.212__@@CurrDate@@TABLE", "TABLE") '... GraphSheetName,GraphSheetNameII

 So I long ago disregarded the record mode.

 

One more detail about my above problem is that all my problems started when I moved from DIAdem Evaluation (which I believe is the Pro edition) to DIAdem Advanced edition. When I originally wrote the script in Evaluation Edition it worked great, everytime. Once I purchased DIAdem and ran the script on Advanced Edition, I began having the problems with the curves not updating their data properly every script cycle.

 

Thanks.

0 Kudos
Message 3 of 7
(4,391 Views)

Hi Techerdone -

 

You mention "maybe I'm missing something..." so I wanted to throw this tip out there in case you weren't aware of it.

 

When you're working in DIAdem SCRIPT's recording mode, you can press <Ctrl+A> while viewing any dialog box to get a look at all of the variables the dialog box sets.  This will help you when you're looking to programmatically change parameters, for example, in REPORT.  You can press the shortcut while viewing the dialog box, take a look at the variables listed in SCRIPT to identify the one you're looking to programmatically manipulate, and delete the ones you aren't touching.  

 

REPORT should be the final panel where this is necessary...

Derrick S.
Product Manager
NI DIAdem
National Instruments
Message 4 of 7
(4,369 Views)

DRock,

 

The <ctrl+A> works well to actually show the scripting when I change values in a dialogue box, but like you said I need to go through and delete the variables I did not touch. Which has ended up being about 1150 lines of code I need to go through for just 6 changes to my 3-page report. Phew. I think I can deal with a For Loop to repeat my code 3 times until I get some free time to really dive into this scripting macro recorder. 

Thanks for your tip, I would have completely thought the scripting recorder was useless without your input!

0 Kudos
Message 5 of 7
(4,356 Views)
Solution
Accepted by topic author techerdone

Hi Techerdone,

 

One more thought on this.  When you're creating/using/renaming multiple pages in a VBScript, make sure you execute PicUpdate() once for EACH SHEET after all the changes to that sheet are done.  The GraphSheetShow() by itself is not enough to force a refresh of that sheet.

 

Brad Turpin

DIAdem Product Support Engineer

National Instruments

Message 6 of 7
(4,141 Views)

Seems to be working. Thanks Brad. Thought I'd tried that but I guess not.

 

Cheers,

Brian

0 Kudos
Message 7 of 7
(3,931 Views)