The problem of converting VBA code to vb.net code
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
The problem of converting VBA code to vb.net code
The following code works fine in VBA, but I tried to convert it to vb.net code but always reported an error. Who can help me to convert it?
VBA code:
Private Declare PtrSafe Function SetCursorPos Lib "user32" (ByVal X As Long, ByVal Y As Long) As Long
Private Declare PtrSafe Sub mouse_event Lib "user32" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)
Private Declare PtrSafe Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Type POINTAPI
X As Long
Y As Long
End Type
Public Const MOUSEEVENTF_LEFTDOWN = &H2
Public Const MOUSEEVENTF_LEFTUP = &H4
Sub XZZ()
Dim P As POINTAPI
GetCursorPos P
SetCursorPos 273, 251
mouse_event MOUSEEVENTF_LEFTDOWN Or MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
'SetCursorPos P.X, P.Y
End Sub
vb.net code:
Private Declare PtrSafe Function SetCursorPos Lib "user32.dll" (ByVal X As Integer, ByVal Y As Integer) As Integer
Private Declare PtrSafe Sub mouse_event Lib "user32" (ByVal dwFlags As Integer, ByVal dx As Integer, ByVal dy As Integer, ByVal cButtons As Integer, ByVal dwExtraInfo As Integer)
Private Declare PtrSafe Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Integer
Private Structure POINTAPI
Dim X As Integer
Dim Y As Integer
End Structure
Public Const MOUSEEVENTF_LEFTDOWN = &H2
Public Const MOUSEEVENTF_LEFTUP = &H4
Module xzz_Module
Public Sub xzz()
Dim P As POINTAPI
GetCursorPos(P)
SetCursorPos(273, 251)
mouse_event(MOUSEEVENTF_LEFTDOWN Or MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)
'SetCursorPos(P.X, P.Y)
End Sub
End Module