Example
- Updated2024-09-12
- 2 minute(s) read
ADO > Example
Example
The following example shows you how to use ADO in a VBS script. You must translate the channel names into the language of your DIAdem version.
Data.Root.Clear 'Include contains some ADO constants Call ScriptInclude(ProgramDrv & "\Examples\Documents\" & "adovbs.vbs") Dim oAdoConnection 'Establishes the ADO connection Dim MdbName 'Suggested file is Example.mdb MdbName =DataReadPath & "Example.mdb" AdoConString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & MdbName & ";Persist Security Info=False" 'Calling the ADO connection dialog Call AdoConStrGet Dim sAdoConnectString sAdoConnectString = AdoConString if sAdoConnectString <> "" Then 'Generating the ADO connection object Set oAdoConnection = CreateObject("ADODB.Connection") 'Setting readwrite mode oAdoConnection.Mode = adModeReadWrite 'Opening connection oAdoConnection.Open sAdoConnectString 'Setting cursor location to client oAdoConnection.CursorLocation = adUseClient 'Reading data Dim RecordSet Set RecordSet = CreateObject("ADODB.RecordSet") RecordSet.ActiveConnection = oAdoConnection 'If neccessary, replace the following channel name RecordSet.Source = "SELECT * FROM Example Where TIME < 20" 'The channel name "Time" is language-specific RecordSet.CursorType = adOpenKeyset RecordSet.LockType = adLockOptimistic RecordSet.Open 'Numeric Channel Dim aValues 'Getting 4 columns Dim aColumnNames 'If neccessary, replace the following channel names aColumnNames = Array("Time","Speed","Revs","Torque") 'The channel names are language-specific aValues=RecordSet.GetRows(-1,0,aColumnNames) Dim Channel 'Transfer values into DIAdem channels Channel = ArrayToChannels(aValues,aColumnNames,True) End if
![]() | Note Refer to the ADO page for more information about ActiveX Data Objects. |