Draw line between points based on table co ordinates

Fireflyxxl

New member
Local time
Today, 08:08
Joined
Mar 14, 2017
Messages
5
Hi everyone, can someone help please.

I need to programatically draw lines between several points to allow people to compare drop orders. For a fun team building exercise

Example here (Cant hotlink yet due to post count)
postimg.org/image/9vtwuarg7/

My idea on how to do this as follows
The underlying map and locations will be a fixed image on a form
Route sequence boxes will be fixed, users just enter from a drop down which id to populate against stop 1,2,3 etc.

Upon these boxes being populated, how do I draw lines between them?
Im guessing I would need to hold co-ords in a table against each location also? so how do I reference these to draw the lines? And how do I "Find" these co-ords on the form to record into the table

Hope someone can help :-)
 
You can only add controls such as lines to a form in design view. If you do that your application won't work with runtime, i.e., users would need full Access. If you want your application to be able to work with runtime you can add a bunch of lines to your form and keep them hidden until you need them.

To draw the line on the form all you need to do is add the line (or use one already added) and adjust the Top, Left, Width, and Height properties. I've attached a database with a form where you can draw a line on a the form by inputting these properties in text boxes and clicking a button. The button code is simply:
Code:
Me.Line0.Top = Nz(Me.LineTop, 0)
Me.Line0.Left = Nz(Me.LineLeft, 0)
Me.Line0.Width = Nz(Me.LineWidth, 0)
Me.Line0.Height = Nz(Me.LineHeight, 0)
Me.Line0.Visible = True
 

Attachments

Thanks Steve that looks like a good start, though Im not sure it can handle what I need

Going to need a fair bit of help on this if you have the time & patience :0

So we can't draw between 2 co-ords? Correct?
Therefore I would need a mathematical way im guessing to calculate these 4 points from the 2 co-ordinates
And it only goes left to right?

As an example I want to go from 07 to 09, drop 1 to drop 2 how do we do that from just populating the drop boxes

Ive put a bit more detail in the database at the link below
ufile.io/be6fa
 
As an example I want to go from 07 to 09, drop 1 to drop 2 how do we do that from just populating the drop boxes

I don't understand this example but for me to explain in general let's change the code so that we are talking about inches.

Code:
Me.Line0.Top = Nz(Me.LineTop, 0) * 1440
Me.Line0.Left = Nz(Me.LineLeft, 0) * 1440
Me.Line0.Width = Nz(Me.LineWidth, 0) * 1440
Me.Line0.Height = Nz(Me.LineHeight, 0) * 1440
Me.Line0.Visible = True

Now let's say you have a line that starts at 1 inch down, two inches over and ends 3 inches down and 4 inches over

Left would be 1 and Top 2 as specified
Height would be 3 - Top or 2
Width would be 4 - Left or 2
 
did you download the dbase I updated? it may clarify a bit.
See link in my prev post. Its your DBase with my map added

Also leave calculations in Twips, I understand that and need that level of precision to line up with the dots.

Seems the line can only run left to right and top to bottom? So there is no way to do a line that has the angle as follows "/"

Ive calculated some points(Top & Left)
Base (Blue Square on map - We'll call point 00)
00 = 3550, 5050
07 = 1100, 4800
08 = 2250, 1250

As an example, I want to join 00 to 07 onto 08 and back to 00. 1st hurdle is technically the 1st line needs to go from point 00 to point 07
, cant seem to do it in that format as this involves the line going left (cant do negative width). We could try some clever maths to invert this as we can do 07 to 00, but seems a bit messy.

But even if we do that, How do we then do a line that goes from 07 to 08. Whether we draw 07 to 08 or 08 to 07, either width or height need to be negative.

Thanks Lee
 
did you download the dbase I updated? it may clarify a bit.
See link in my prev post. Its your DBase with my map added

I couldn't see how to download it. You can zip and upload your database here.

It appears that I've led you astray and that the place to do this sort of thing would be in a report rather than a form. I don't have time right now to check into the details but if you look at the following links I think you'll see that a report is a better environment for this.

https://msdn.microsoft.com/en-us/library/office/ff835754.aspx
https://msdn.microsoft.com/en-us/library/office/ff198297.aspx
https://msdn.microsoft.com/en-us/library/office/ff193783.aspx
 
It needs to be a form as the lines need drawing dynamically as choices are made

Ive uploaded the DB here
 

Attachments

What you are asking is pretty complex.

I would recommend going here http://www.baldyweb.com/ChrisOSamples.htm and downloading some of the fairly amazing samples posted up by ChrisO and now kindly hosted by the Baldy one.

You will sees some techniques for drawing, dragging and dropping things on forms.
 
Drawing lines on top of an image in a form might have been fairly easy but as you noted
Seems the line can only run left to right and top to bottom? So there is no way to do a line that has the angle as follows "/"

This seems to be true. When I try to assign negative values to any of the properties (Top, Left, Height, Width) I get the error "The control or subform is too large for this location". It seems like there should be some way of displaying a line with a positive slope but I can't find it. If you can't find a way to create these lines and using a report isn't an option then I know of no easy way to do this.

I looked at some of the ChrisO samples and the ones which seemed relevant (DrawForms & DragDropPolygon) use classes that may have come from Leban's PictureBoxA97 . These use an image control for displaying objects. This might work for you but this is beyond my level of expertise but maybe other forum member can help you with this.
 
Thank for your help Steve, appreciate your time & effort. I had looked at ChrisO's stuff before, but it was too advanced for me.

Anyone else have any ideas?
 
I've posted a question about positive sloped lines in this thread.. If you want to be notified on responses to this then go to this thread and in the Thread Tools menu click Subscribe to this Thread.
 
I figured it out. A line object has a LineSlant property. When set to true the lines slope up. I've put a check box on the form to set that property so you can play with it in the attached database.
 

Attachments

I noticed that the MouseDown event of the image control (OLEUnbound11) gives you the X and Y coordinates of the position where you clicked the mouse. You could use this to add the map points to the table. You could put a check box on the form to indicate whether or not a mouse click was to add a point to the table. Then in the mousedown event this would be tested and if false it would just exit. If true then you could prompt the user for a point name with a input box or dialog form. When the code returned from the input box you would do an insert into the table.

For doing inserts into table I suggest using the method outline in post 4 of this thread. This method may take a bit longer to set up but you'll avoid a lot of problems other methods have.
 
I went ahead and implemented what I suggested in my last post in the attached database. If you check the Save Points check box and click on the map it will prompt you for Location Id and will save that location in the Location table. I just noticed that if you click the Cancel button it goes into debug so that needs work.

I also created a subroutine (DrawLine) that draws a line between the points stored in the Locations table. If you select locations in the locations combo boxes and click the Draw 1 to 2 button the DrawLine subroutine is called with the selected locations and the line is drawn between them.

I changed a few thing from the way you had it just to support my way of thinking. They are:

  • The fields Top and Left in the table have been changed to X and Y
  • The name of the image control was changed to MapImage
  • The Drop combo boxes where changed to Location1 and Location2. Note that names like 1_1 are not good as Access renames the to something like Ctrl1_1.
  • I changed the row sources of the combo box to a query of the table

You may not want to look at this version until you had a go at this yourself. You would want to deprive yourself of the challenging and fun part, but this at least lets you know that this much can be done.
 

Attachments

Users who are viewing this thread

Back
Top Bottom