# Thread: A very simple array (A2000)

1. ## A very simple array (A2000)

Here is something I'm trying to understand.
Function newArray()
Dim myarray()
Dim i, x
ReDim myarray(5, 10)
For i = 0 To 5
For x = 0 To 10
Debug.Print myarray(i, x)
Next
Next
End Function

Can someone make this work? What I want to do is determine whether the mouse pointer is within a certain predetermined block of Twips on a Form. In my case it is
upper left corner
(1300, 600)
lower right corner
(3500, 6000)
So I figure a two dimensional array might do it but I'm a total dope when it comes to arrays. If someone would prefer to point me to a book that would be fine. I did do a search before posting. Thanks for any help.

Paul

2. ## Re: A very simple array (A2000)

It is not clear to me at all what the array has to do with determining the mouse position. You can get the mouse coordinates using the MouseDown, MouseUp and MouseMove events; these events occur for the form, for each section of the form and for the controls on the form.

Perhaps somebody can help if explain why you want to do this and what you hope to accomplish.

3. ## Re: A very simple array (A2000)

Thank you Hans. There is an event in VB called MouseOver that allows you to determine if the mouse is hovering over an object like a command button. Access doesn't have MouseOver, but they have (as you pointed out) MouseMove. It will do the same thing to a certain extent by combining the MouseMove events for the Form Detail section and the Control. For example if you want to change the Caption on a button, you can use the Control MouseMove Event to change it to "XYZ" and the Detail MouseMove event to change it back to it's original value. But this lead to a discussion between some of us about using the Control coordinates to determine if the mouse is over an object like a button. So if the upper left coordinates for my button are (x, y) and the lower right coordinates are (x1,y1), then it seems you should be able to say,
If myPointer > (x,y) and myPointer < (x1,y1) Then
ctl.Caption = "XYZ"
Else
ctl.Caption = "ABC"
End If

So knowing very little about arrays, I tried to start simple with just getting a small function to run. Then maybe I could piece things together from there.
Hope that explains it a little more.

Paul

4. ## Re: A very simple array (A2000)

I can recommend the following article which you can find on the smart access web site .
You will need to take up their free subscription offer and then search for the following article.

"Create Map Interfaces Without Getting Lost" (online subscribers only) 07/1996 by Michael Kaplan

I didn't realise I had been subscribed to smart access for so long! I remember when I first read this article I didn't understand even 1% of it, but now I can understand it a little better.

This is not the first time I have directed people to the smart access site, but I still haven't been offered a free subscription! <img src=/S/innocent.gif border=0 alt=innocent width=20 height=20> <img src=/S/grin.gif border=0 alt=grin width=15 height=15>

5. ## Re: A very simple array (A2000)

In view of this extra info you might find this thread of interest...

6. ## Re: A very simple array (A2000)

Thanks Rupert. I will follow up on your information.

Paul

7. ## Re: A very simple array (A2000)

Seems simpler to test:

MouseX >= control.left
MouseX <= control.left + control.width
MouseY >= control.top
MouseY <= control.top + control.height

In some efficient way rather than do higher math. <img src=/S/grin.gif border=0 alt=grin width=15 height=15>

8. ## Re: A very simple array (A2000)

Well actually I did start with that basic idea. I did not use the specific control properties you are mentioning but I did use
If X > 3500 and X < 6000 and Y >600 and Y < 1305 Then
Do This
Else
Do That
End If

Doesn't work. Actually I've been playing with this for a few hours and it appears that my other method my not work either. When the mouse pointer is over the control, the X,Y coordinates no longer read out value changes. So it may not do any good anyway. It was mainly an adventure in stretching my own understanding of how the MouseMove event works and how I might use arrays to accomplish it.
But I am still interested in anyone being about to get my original function to Debug.Print the array values if that's possible. I may not be able to use it for the MouseOver event, but it would still be nice to know how the array works.

Thanks for the suggestions.

Paul

9. ## Re: A very simple array (A2000)

1. You don't need to check coordinates to determine if the mouse pointer is over a control. I have attached a very simple zipped Access 97 database that displays info about the mouse pointer in the status bar.

2. In your first post in this thread, you declare an array and then immediately output its elements to the Immediate window, without ever assigning values to the array elements. Moreover, you have written a function that doesn't return a value. And the array is only defined within the function; it can't be referenced outside it. I am willing to help, but I don't have the slightest idea what you want.

10. ## Re: A very simple array (A2000)

Good day Hans. Thank you for the database. I must apologize for any confusion about this thread. I am fairly familiar with the MouseMove event and how it works as demonstrated by your database but wanting to try and learn more, I tried using an array (which it is obvious I don't know much about) to see if I could follow the pointer that way. The MouseMove event returns the (x, y) coordinates of the Mouse Pointer at any given time and that is where I started from. I tried writing my posted function without any real understanding of how to return the values from an array. I know I can do this
Dim MyArray() As Integer
Redim MyArray(5)
For I = 1 To 5
MyArray(I) = I
Debug.Print MyArray(I)
Next I

My post was simply a bad attempt at trying to find out how to do it with two dimensions (if that's the correct phrase). Hoping to return the values from (x1, y1).....(x5, y10)
I know this would do it
For x = 1 to 5
For y = 1 to 10
debug.print x & ", " & y
Next
Next
but I assumed that would not give me what I needed to determine what I wanted.
I'm seeing it's not so simple. I don't want to make you responsible for teaching me about arrays. I thought that if I could get the original function "corrected" then it would give me another piece to the puzzle to study on my own.

Thank you for your time and interest.

Paul

11. ## Re: A very simple array (A2000)

Dear Hans,

Your code interested me in that the data displayed in the status bar changed automatically without the use of the timer event.

I searched the notorious Access help files for acSysCmdSetStatus without any success! If you could advise me on a suitable search word to return information on this I would be most grateful.

My interest stems from the following problem which I have not yet solved to my satisfaction.
Partly for experience and partly for commercial gain, I have in my spare time I been trying to write a database for handling bookings and journeys for a taxi firm. I have seen several programmes already written to do this, but most are dated. My problem is that taxi firms tend to operate on a 24-hour basis this means that if you have a subform showing "today's" journeys, when you pass midnight the form needs refreshing. I have used the timer event of the form to update the information every 15 minutes or so but I am told it is not good idea to use the timer event as it uses resources. I wondered if there is a similar command to the one you've shown used that could interrogate the date and force a re-query, or at least pop-up a warning message. Or is this yet another case of me barking madly up the wrong tree!

12. ## Re: A very simple array (A2000)

Hi Rupert,

acSysCmdSetStatus is just an argument of the SysCmd instruction. If you type SysCmd in a module or in the Immediate window and press F1, you should get help, but it is much less clear than the Access 97 help was.

The form in my Mouse Position demo doesn't need a Timer routine because it uses the MouseMove event of the various parts of the form. This event fires automatically if the user moves the mouse pointer over that part. That's the beauty of events: they occur automatically when something happens; you don't have to check for them periodically.

Using a Timer does use some resources, but that shouldn't be a problem in itself. If the Timer Interval is small (how small exactly depends on the complexity of your On timer event procedure), normal operation of the form may be slow and/or independable, but firing it every 10 or 15 minutes is not likely to be problematic. I'm not sure whether a forced Requery is a good idea - it is disconcerting to the user if this happens while he/she is editing data. Popping up a reminder is probably a better idea.

Good luck with your application.

13. ## Re: A very simple array (A2000)

After looking at Hans' sample database and commenting out the event handler for the CommandButton, it appears that Access does not "bubble" events like other forms environments. That is, Access seems to be sending the event only to the front-most control, and if that control is not interested in handling it, it is not then passed to the next object in the Z-order. At least in Access 2000 that is what seems to happen. Maybe that's good, because otherwise, programming would become significantly more complicated.

If you want to report to a procedure the mouse position relative to the form, you have to use the control's MouseMove event, but you can calculate it from the control's Top and Left properties:

Private Sub cmdTest_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
'InformOnMouse "Command Button" & " [x=" & X & ",y=" & Y & "]"
InformOnMouse "Command Btn " & "[x=" & X + (Round(Me.cmdTest.Left / 15, 0) * 15) & _
",y=" & Y + (Round(Me.cmdTest.Top / 15, 0) * 15) & "] Relative to Detail"
End Sub
Private Sub Detail_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
InformOnMouse "Detail Section" & " [x=" & X & ",y=" & Y & "]"
End Sub

I "rounded" the coordinates of the control so that the transition on the status bar would be seamless on my system (twips are reported in intervals of 15).

14. ## Re: A very simple array (A2000)

Hi Jefferson,

The "unit" of 15 twips is 1 pixel on your screen. If your screen is set to Normal Fonts, resolution is 96 pixels per inch; 1 inch = 1440 twips, so 1 pixel = 1440/96 twips = 15 twips. If your screen had been set to Large Fonts, the resolution would have been 120 pixels per inch, so 1 pixel = 1440/120 twips = 12 twips. With a custom setting, the resolution would be different from both.

You can use Windows API calls to get the number of pixels per inch:

<img src=/w3timages/blueline.gif width=33% height=2>

Global Const TWIPSPERINCH = 1440

Declare Function apiGetDC Lib "user32" Alias "GetDC" (ByVal hWnd As Long) As Long
Declare Function apiReleaseDC Lib "user32" Alias "ReleaseDC" (ByVal hWnd As Long, ByVal hDC As Long) As Long
Declare Function apiGetDeviceCaps Lib "gdi32" Alias "GetDeviceCaps" (ByVal hDC As Long, ByVal nIndex As Long) As Long

Dim hDC As Long, hWnd As Long, RetVal As Long
Dim XPIXELSPERINCH, YPIXELSPERINCH
Const LOGPIXELSX = 88
Const LOGPIXELSY = 90

' Retrieve the current number of pixels per inch, which is resolution-dependent.
hDC = apiGetDC(0)
XPIXELSPERINCH = apiGetDeviceCaps(hDC, LOGPIXELSX)
YPIXELSPERINCH = apiGetDeviceCaps(hDC, LOGPIXELSY)
RetVal = apiReleaseDC(0, hDC)

<img src=/w3timages/blueline.gif width=33% height=2>

15. ## Re: A very simple array (A2000)

Not to put too fine a point upon it, Jefferson, I keep pointing out that Access forms and controls are NOT like the forms and controls in other Office apps and VB. <img src=/S/grin.gif border=0 alt=grin width=15 height=15> The fact is, the each control has its own MouseMove event and those events are independent of the MouseMove events of other controls and of the Form.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•