Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Return (x,y) values of 6 clicked locations

Posted on 1998-06-22
3
Medium Priority
?
207 Views
Last Modified: 2010-05-03
I have a PictureBox control opened.

Then, here's what I need to do (Instructions in Human Language) :

1. Click on 6 different locations on the PictureBox using my mouse
button

2. Return the X,Y coordinates of each of the 6 locations and store them
in 2 one-dimension arrays namely,    Dim x(1 to 6), y(1 to 6) as Integer
 

Really glad if you could help.

0
Comment
Question by:xoooox
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 1

Accepted Solution

by:
kesonline earned 400 total points
ID: 1463998
This should be very easy. Here's what you do (i'm assuming you want pixel locations, not twips):
Create a form (frmMain) with two command buttons (cmdStart, cmdShow), a listbox (lstPoints), and a picturebox (picPoints) with scalemode set to pixels (3).
Here's the basic code:
(this is general declarations)
Dim ptsX(1 To 6) As Integer
Dim ptsY(1 To 6) As Integer
Dim clicking As Boolean
Dim clicks As Integer

Private Sub cmdShow_Click()
lstPoints.Clear
For i = 1 To 6
    lstPoints.AddItem CStr(ptsX(i)) + "," + CStr(ptsY(i))
Next i
End Sub

Private Sub cmdStart_Click()
clicking = True

End Sub

Private Sub Form_Load()
clicks = 0
End Sub

Private Sub picPoints_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If clicking Then
    Beep
    clicks = clicks + 1
    ptsX(clicks) = X
    ptsY(clicks) = Y
End If
If clicks = 6 Then
    clicks = 0
    clicking = False
    cmdShow_Click
End If
End Sub



0
 
LVL 9

Expert Comment

by:Dalin
ID: 1463999
xoooox,
Try the following. If you have questions, let me know.
Regards
Dalin

'1. declaration:

          Private Type POINTAPI
              x As Long
              y As Long
          End Type

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

 

 2. In your picture's Click event, add:

          Dim p As POINTAPI
          Static clickCount as Integer
          If ClickCount = 0 then clickcount = 1
          If clickCount >6 then
              'Do what you like, reset or just exit
              ' I am reset it
              Clickcount = 1
             End if
          Call GetCursorPos( p )
          x(clickcount) = p.x
          y(clickCount)= p.y


0
 
LVL 1

Expert Comment

by:kesonline
ID: 1464000
Question for Dalin - why the whole big POINTAPI stuff - you don't need any API calls for this program. Just wondering...
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question