📄 s2l5.bas
字号:
Option Explicit
'**********************************************************************
'* S2L5.bas - (Section 2, Lesson 5) SENDING AN ARRAY OF INTEGERS USING
'* SAFEARRAYS
'* This is the RTDX Host Client for Section 2, Lesson 5
'*
'* This example sends integer values 1-10 to the target
'**********************************************************************
Const Success = &H0 ' Method call is valid
Const Failure = &H80004005 ' Method call failed
Const ENoDataAvailable = &H8003001E ' No data was available.
' However, more data may be
' available in the future.
Const EEndOfLogFile = &H80030002 ' No data was available
' The end of the log file has
' been reached.
Sub main()
Dim rtdx As Object
Dim arraydata(10) As Long
Dim data As Long
Dim bufferstate As Long
Dim status As Long
Dim i As Long
On Error GoTo Error_Handler
' Create an instance of the RTDX COM object
Set rtdx = CreateObject("RTDX")
' Open channel ichan for writing
status = rtdx.Open("ichan", "W")
If status <> Success Then
Debug.Print "Opening of channel ichan failed"
GoTo Error_Handler
End If
'******************************************************************
' Insert code from Step #3 here - to fill up the SAFEARRAY with
' values
'******************************************************************
data = 1
For i = LBound(arraydata) To (UBound(arraydata) - 1)
arraydata(i) = data
data = data + 1
Next i
'******************************************************************
' Insert code from Step #4 here - to write a SAFEARRAY of 32-bit
' integers to the target
'******************************************************************
status = rtdx.Write(CVar(arraydata), bufferstate)
If status = Success Then
For i = LBound(arraydata) To (UBound(arraydata) - 1)
Debug.Print "Value " & arraydata(i) & " was sent to the target"
Next i
Else
Debug.Print "Write failed"
End If
' Close the channel
status = rtdx.Close()
' Release the RTDX COM object
Set rtdx = Nothing
Exit Sub
Error_Handler:
Debug.Print "Error in COM method call"
Set rtdx = Nothing
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -