"Compile Error Syntax error" 调用函数
"Compile Error Syntax error" calling function
我想在 VB6 中调用 DLL,并且我在 Visual Studio 2008(示例程序)中有工作代码。
==== 这是 Visual Studio 2008 代码 ====
Declare Function InitStp Lib "stp.dll" () As Integer
Declare Function RunMotor1 Lib "stp.dll" (ByVal steps As Integer, ByVal interval As Integer, ByVal direction As Integer, ByVal outputs As Integer) As Boolean
Private Sub Command1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Stop1.Click
InitStp ()
End Sub
Private Sub Command2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Stop1.Click
RunMotor1 (200, 50, 0, 0)
End Sub
====这是VB6代码====
Private Declare Function InitStp Lib "stp.dll" () As Integer
Private Declare Function RunMotor1 Lib "stp.dll" (ByVal steps As Integer, ByVal interval As Integer, ByVal direction As Integer, ByVal outputs As Integer) As Boolean
Private Sub Command1_Click()
InitStp ()
End Sub
Private Sub Command2_Click()
RunMotor1 (200, 50, 0, 0)
End Sub
当我尝试 运行 InitStp() 的代码时,我得到了 "Compile Error Syntax error"(代码 InitStp() 在 de VB6 中已经是红色,表明存在错误)。这与 "RunMotor1 (200, 50, 0, 0)".
相同
看来我的转换不成功...
无论发生什么情况,在 VB6 中,您都不应该在 Sub
的参数周围使用括号,除非您还使用了 Call
关键字。这也适用于作为 Sub
调用的 Function
s 换句话说:
RunMotor1 200, 50, 0, 0
-- 或--
Call RunMotor1 (200, 50, 0, 0)
但从来没有
RunMotor1 (200, 50, 0, 0)
A VB.Net Integer
是 32 位,但是 VB6 Integer
是 16 位,在 VB6 中 Long
是 32 位类型,所以在你的声明中使用它。
InitStp ()
是无效语法,删除括号并单独使用 InitStp
- 但这会忽略 return 值通常不是一个好主意,因此改为:
Dim result as Long
result = InitStp()
我想在 VB6 中调用 DLL,并且我在 Visual Studio 2008(示例程序)中有工作代码。
==== 这是 Visual Studio 2008 代码 ====
Declare Function InitStp Lib "stp.dll" () As Integer
Declare Function RunMotor1 Lib "stp.dll" (ByVal steps As Integer, ByVal interval As Integer, ByVal direction As Integer, ByVal outputs As Integer) As Boolean
Private Sub Command1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Stop1.Click
InitStp ()
End Sub
Private Sub Command2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Stop1.Click
RunMotor1 (200, 50, 0, 0)
End Sub
====这是VB6代码====
Private Declare Function InitStp Lib "stp.dll" () As Integer
Private Declare Function RunMotor1 Lib "stp.dll" (ByVal steps As Integer, ByVal interval As Integer, ByVal direction As Integer, ByVal outputs As Integer) As Boolean
Private Sub Command1_Click()
InitStp ()
End Sub
Private Sub Command2_Click()
RunMotor1 (200, 50, 0, 0)
End Sub
当我尝试 运行 InitStp() 的代码时,我得到了 "Compile Error Syntax error"(代码 InitStp() 在 de VB6 中已经是红色,表明存在错误)。这与 "RunMotor1 (200, 50, 0, 0)".
相同看来我的转换不成功...
无论发生什么情况,在 VB6 中,您都不应该在 Sub
的参数周围使用括号,除非您还使用了 Call
关键字。这也适用于作为 Sub
调用的 Function
s 换句话说:
RunMotor1 200, 50, 0, 0
-- 或--
Call RunMotor1 (200, 50, 0, 0)
但从来没有
RunMotor1 (200, 50, 0, 0)
A VB.Net Integer
是 32 位,但是 VB6 Integer
是 16 位,在 VB6 中 Long
是 32 位类型,所以在你的声明中使用它。
InitStp ()
是无效语法,删除括号并单独使用 InitStp
- 但这会忽略 return 值通常不是一个好主意,因此改为:
Dim result as Long
result = InitStp()