DIAdem Help

Controlling DIAdem as an ActiveX Object

  • Updated2024-09-12
  • 3 minute(s) read

Controlling DIAdem as an ActiveX Object

This example shows how to use DIAdem as an ActiveX object and how to remote control it from a different application.

Load sample data set

Select a layout:

Open selected layout

Note Depending on which safety settings you have, the operating system warns you that an ActiveX element may be unsafe. You must register the control to run the example. This warning appears if you use the CreateObject command to embed an automation object in an HTML page.
Note When this example starts, DIAdem loads example files and overwrites existing data and layouts.
Note The following script is embedded in the HTML code for this help page. The script registers DIAdem as an ActiveX object and uses the DIAdem command interface to send commands. All other embedded scripts are for evaluating the HTML forms.
Dim oMyDIAdem, ProgramDrv
Set oMyDIAdem = new DIAdemAutomation

Call oMyDIAdem.LoadDiademDataSet(ProgramDrv & "examples\data\report_expl.tdm", True)
Call oMyDIAdem.LoadDiademLayout(ProgramDrv & "examples\documents\Expl_Report_2DAxis.TDR")
Set oMyDIAdem = Nothing

Class DIAdemAutomation
Dim oDIAdem, DIAdemApp
  Private Sub Class_Initialize()
    Set oDIAdem = Nothing
    Call ConnectToDIAdem
    Call oDIAdem.VariantVarget("Application",DIAdemApp)
    Call oDIAdem.VariantVarget("ProgramDrv",ProgramDrv)
  End Sub

  '================================================================
  Private Sub Class_Terminate()
    Set oDIAdem = Nothing
  End Sub

  
  '================================================================ 
  Function DIAdem_Exec(DIAdemCommand)
      DIAdem_exec = False
      If ConnectToDIAdem Then
          If oDIAdem.CmdExecuteSync(DIAdemCommand) = 1 Then DIAdem_exec = True
      End If
  End Function
  '================================================================
  Sub LoadDiademLayout(LayOut)
     Call DIAdemApp.Report.LoadLayout(LayOut)
     Call DIAdem_exec("WndOpen(""Report"")")
     Call DIAdemApp.Report.Refresh
  End Sub

  '================================================================
  Sub ExportPDF(PDFName)
    Call DIAdemApp.Report.Sheets.ExportToPDF(PDFName)
  End Sub
  
  '================================================================
  Function LoadDiademDataSet(DataSet, clear)
    If clear Then
      Call DIAdemApp.Data.Root.Clear
    End if
    Dim MyCommand : MyCommand = "DataFileLoad(""" & DataSet & """)"
    LoadDiademDataSet = DIAdem_exec(MyCommand)
  End Function
  
  '================================================================
  Private Function ConnectToDIAdem
    Dim nValueT, iWait
    If NOT oDIAdem Is Nothing Then
      ConnectToDIAdem = True
      Exit Function
    End If  
    ConnectToDIAdem = False
      On Error Resume Next
      Set oDIAdem = CreateObject("DIAdem.TOCommand")
      If Err.Number > 0 then
        Set oDIAdem = Nothing
        Err.Clear
      Else
        iWait = 0 
        Do 
          iWait = iWait + 1
          If iWait >=1000 Then
            Exit Function
          End If
        Loop Until Not oDIAdem.bInterfaceLocked    
        ' Suppress all messages
        oDIAdem.bNoMsgDisplay = true
        oDIAdem.bNoInfoDisplay = true
        oDIAdem.bNoErrorDisplay = true
        oDIAdem.bNoWarningDisplay = true
        oDIAdem.bNoNoDialogDisplay = true
        ConnectToDIAdem = True
      End If
  End Function

End Class