Option Explicit
Public Declare Function load_tool Lib "w95_s7.dll" (ByVal nr As Byte, ByVal dev As String, adr As PlcAdrType) As Long
Public Declare Function db_read Lib "w95_s7.dll" (ByVal blockno As Long, ByVal no As Long, Amount As Long, value As Byte) As Long
Public Declare Function db_write Lib "w95_s7.dll" (ByVal blockno As Long, ByVal no As Long, Amount As Long, value As Byte) As Long
Type PlcAdrType
ADDRESS As Byte
SEGMENTID As Byte
SLOTNO As Byte
PACKNO As Byte
End Type
在窗口頁面,我建了按鈕,按鈕下代碼如下:
Dim i As Long
Dim a11 As PlcAdrType
a11.ADDRESS = 2
a11.SEGMENTID = 0
a11.SLOTNO = 2
a11.PACKNO = 0
i = load_tool(1, "S7ONLINE", a11)
If (i <> 0) Then
MsgBox ("連接成功")
Else
MsgBox ("連接失敗")
End If
運行程序後,點擊按鈕就會提示我,w95_s7.dll文件未找到,請問列為大神,到底哪裡出了問題?
不行的,%logpath%不能包在括號裡,應該這樣
Shell "cmd /k mkdir “+LOGPATH+” > nul 2>&1", vbNormalNoFocus
vb調用dos是直接運行引號內的,而不給某一變量賦值。另外包在百分號內的是bat變量而不是vb的變量