ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Mouse Move Event (https://www.excelbanter.com/excel-programming/424321-mouse-move-event.html)

Roger

Mouse Move Event
 
I use the X & Y values in the mouse move event to make a comments box follow
the mouse pointer - how can I pass the X & Y values to a different sub - I
have declared them as public to no avail - they only work when they are used
in the actual mouse move routine

I could reduce the amount of code I am using by a significant amount if this
is possible - thanks in anticipation

--
Roger

Tim Zych

Mouse Move Event
 
This worked for me.

' In a regular module
Public gX As Single, gY As Single

' In a userform
Private Sub UserForm_MouseMove(ByVal Button As Integer, ByVal Shift As
Integer, ByVal X As Single, ByVal Y As Single)
gX = X
gY = Y
Debug.Print CStr("Does " & CStr(X) & " = " & CStr(gX) & "?")
Debug.Print CStr("Does " & CStr(Y) & " = " & CStr(gY) & "?")
End Sub


--
Tim Zych
http://www.higherdata.com


"Roger" wrote in message
...
I use the X & Y values in the mouse move event to make a comments box
follow
the mouse pointer - how can I pass the X & Y values to a different sub - I
have declared them as public to no avail - they only work when they are
used
in the actual mouse move routine

I could reduce the amount of code I am using by a significant amount if
this
is possible - thanks in anticipation

--
Roger




Gary''s Student

Mouse Move Event
 
Declare Function GetCursorPos Lib "user32" _
(lpPoint As POINTAPI) As Long


Type POINTAPI
x As Long
y As Long
End Type


Sub ShowPos()
Dim lRetVal As Long
Dim Pos As POINTAPI
lRetVal = GetCursorPos(Pos)
MsgBox Pos.x & ", " & Pos.y
End Sub

This will retrieve and display the coordinates.
--
Gary''s Student - gsnu200834


"Roger" wrote:

I use the X & Y values in the mouse move event to make a comments box follow
the mouse pointer - how can I pass the X & Y values to a different sub - I
have declared them as public to no avail - they only work when they are used
in the actual mouse move routine

I could reduce the amount of code I am using by a significant amount if this
is possible - thanks in anticipation

--
Roger


Tim Zych

Mouse Move Event
 
That was an example. Here is how I might implement this (not using globals).

' In a regular module
Sub DisplayMouseCoordinates(ByVal X As Single, ByVal Y As Single)
Debug.Print "X = " & CStr(X)
Debug.Print "Y = " & CStr(Y)
End Sub

' In a userform:
Private Sub UserForm_MouseMove(ByVal Button As Integer, ByVal Shift As
Integer, ByVal X As Single, ByVal Y As Single)
Call DisplayMouseCoordinates(X, Y)
End Sub

--
Tim Zych
http://www.higherdata.com


"Tim Zych" <feedback at higherdata dt com wrote in message
...
This worked for me.

' In a regular module
Public gX As Single, gY As Single

' In a userform
Private Sub UserForm_MouseMove(ByVal Button As Integer, ByVal Shift As
Integer, ByVal X As Single, ByVal Y As Single)
gX = X
gY = Y
Debug.Print CStr("Does " & CStr(X) & " = " & CStr(gX) & "?")
Debug.Print CStr("Does " & CStr(Y) & " = " & CStr(gY) & "?")
End Sub


--
Tim Zych
http://www.higherdata.com


"Roger" wrote in message
...
I use the X & Y values in the mouse move event to make a comments box
follow
the mouse pointer - how can I pass the X & Y values to a different sub -
I
have declared them as public to no avail - they only work when they are
used
in the actual mouse move routine

I could reduce the amount of code I am using by a significant amount if
this
is possible - thanks in anticipation

--
Roger






Roger

Mouse Move Event
 
Thanks for the 2 suggestions - I'll give them a try

--
Roger


"Roger" wrote:

I use the X & Y values in the mouse move event to make a comments box follow
the mouse pointer - how can I pass the X & Y values to a different sub - I
have declared them as public to no avail - they only work when they are used
in the actual mouse move routine

I could reduce the amount of code I am using by a significant amount if this
is possible - thanks in anticipation

--
Roger


Roger

Mouse Move Event
 
They work - thanks a lot - I am impressed
--
Roger


"Roger" wrote:

Thanks for the 2 suggestions - I'll give them a try

--
Roger


"Roger" wrote:

I use the X & Y values in the mouse move event to make a comments box follow
the mouse pointer - how can I pass the X & Y values to a different sub - I
have declared them as public to no avail - they only work when they are used
in the actual mouse move routine

I could reduce the amount of code I am using by a significant amount if this
is possible - thanks in anticipation

--
Roger


Roger

Mouse Move Event
 
I have implemented your solution with great effect - I have reduced the
amount of code required considerably - thankyou for your help





--
Roger


"Gary''s Student" wrote:

Declare Function GetCursorPos Lib "user32" _
(lpPoint As POINTAPI) As Long


Type POINTAPI
x As Long
y As Long
End Type


Sub ShowPos()
Dim lRetVal As Long
Dim Pos As POINTAPI
lRetVal = GetCursorPos(Pos)
MsgBox Pos.x & ", " & Pos.y
End Sub

This will retrieve and display the coordinates.
--
Gary''s Student - gsnu200834


"Roger" wrote:

I use the X & Y values in the mouse move event to make a comments box follow
the mouse pointer - how can I pass the X & Y values to a different sub - I
have declared them as public to no avail - they only work when they are used
in the actual mouse move routine

I could reduce the amount of code I am using by a significant amount if this
is possible - thanks in anticipation

--
Roger



All times are GMT +1. The time now is 08:02 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com