AdsWriteConnect
Creates a fixed connection of a Visual Basic variable and an ADS device.
object.AdsWriteConnect(
nIndexGroup As Long,
nIndexOffset As Long,
cbLength As Long,
nRefreshType As ADSOCXTRANSMODE,
nCycleTime As Integer,
pData As Variant
) As Long
Parameter
nIndexGroup
[in] Index group of the ADS variable
nIndexOffset
[in] Index offset of the ADS variable
cbLength
[in] Length of the data in bytes (see VB variable lengths)
nRefreshType
[in] Type of data exchange between VB variable and ADS variable (see the ADSOCXTRANSMODE data type)
nCycleTime
[in] Write cycle in ms
pData
[in] Visual Basic variable from which the data is written into the ADS variable
Return value
See ADS error codes
Comments
If the connection to the ADS variable is no longer required, it should be released using the AdsWriteDisconnect() method. If only certain specific values are required in a form, the connection should only be created when the form is loaded, and should be released again when the form is closed.
The string variable type is not supported.
Example
Dim VBVarInteger(0) As Integer
Dim VBVarSingle(0) As Single
Dim VBVarBoolean(0) As Boolean
'wird beim Starten des Programms aufgerufen
Private Sub Form_Load()
'Verbindung zu den Variablen in der SPS herstellen
Call AdsOcx1.AdsWriteConnect(&H4020&, 0&, 2&, ADSTRANS_CLIENTCYCLE, 55, VBVarInteger)
Call AdsOcx1.AdsWriteConnect(&H4020&, 2&, 4&, ADSTRANS_CLIENTCYCLE, 55, VBVarSingle)
Call AdsOcx1.AdsWriteConnect(&H4021&, 48&, 2&, ADSTRANS_CLIENTCYCLE, 55, VBVarBoolean)
End Sub
'wird beim Beenden des Programms aufgerufen
Private Sub Form_Unload(Cancel As Integer)
'Verbindung zu den Variablen in der SPS beenden
Call AdsOcx1.AdsWriteDisconnect(VBVarInteger)
Call AdsOcx1.AdsWriteDisconnect(VBVarSingle)
Call AdsOcx1.AdsWriteDisconnect(VBVarBoolean)
End Sub
'wird vom Bediener aufgerufen
Private Sub cmd_write_Click()
VBVarInteger(0) = CInt(txt_int.Text)
VBVarSingle(0) = CSng(txt_single.Text)
VBVarBoolean(0) = IIf(chk_boolean.Value = 1, True, False)
End Sub