dcsimg
Results 1 to 21 of 21

Thread: [RESOLVED] DRAW line between two point

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Mar 2005
    Location
    Italy-Napoli
    Posts
    1,881

    Resolved [RESOLVED] DRAW line between two point

    Admit have an Italian Maps in picturebox.

    I need to draw a simple line from Napoli to Milan...

    Idea?

    note:
    the two city are distinguish from little circle in color red
    Attached Files Attached Files
    Last edited by luca90; May 19th, 2019 at 03:53 AM.

  2. #2
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    5,202

    Re: DRAW line between two point

    Were the circles already on the map, or did you draw them?
    I assume you can't just click on the map and pick Napoli and Milan, you want to draw automatically by finding the red circles?

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Mar 2005
    Location
    Italy-Napoli
    Posts
    1,881

    Re: DRAW line between two point

    Posta a simple project

  4. #4

    Thread Starter
    Frenzied Member
    Join Date
    Mar 2005
    Location
    Italy-Napoli
    Posts
    1,881

    Re: DRAW line between two point

    Quote Originally Posted by passel View Post
    Were the circles already on the map, or did you draw them?
    I assume you can't just click on the map and pick Napoli and Milan, you want to draw automatically by finding the red circles?
    Post a simple project

  5. #5
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    5,202

    Re: DRAW line between two point

    With the project given, and the red circles given by shape controls.
    Code:
    Option Explicit
    Private Sub Form_Load()
    'To redefine the coordinates of the origin
    Picture1.Scale (0, 5000)-(5000, 0)
    Picture1.AutoRedraw = True
    End Sub
    
    Private Sub Command2_Click()
      Picture1.Cls
    End Sub
    
    Private Sub Command1_Click()
      Dim x1 As Single, y1 As Single
      Dim x2 As Single, y2 As Single
      x1 = Shape1.Left + Shape1.Width / 2
      y1 = Shape1.Top - Shape1.Height / 2
      x2 = Shape2.Left + Shape2.Width / 2
      y2 = Shape2.Top - Shape2.Height / 2
      Picture1.Line (x1, y1)-(x2, y2), vbBlack
    End Sub

  6. #6

    Thread Starter
    Frenzied Member
    Join Date
    Mar 2005
    Location
    Italy-Napoli
    Posts
    1,881

    Re: DRAW line between two point

    Quote Originally Posted by passel View Post
    With the project given, and the red circles given by shape controls.
    Code:
    Option Explicit
    Private Sub Form_Load()
    'To redefine the coordinates of the origin
    Picture1.Scale (0, 5000)-(5000, 0)
    Picture1.AutoRedraw = True
    End Sub
    
    Private Sub Command2_Click()
      Picture1.Cls
    End Sub
    
    Private Sub Command1_Click()
      Dim x1 As Single, y1 As Single
      Dim x2 As Single, y2 As Single
      x1 = Shape1.Left + Shape1.Width / 2
      y1 = Shape1.Top - Shape1.Height / 2
      x2 = Shape2.Left + Shape2.Width / 2
      y2 = Shape2.Top - Shape2.Height / 2
      Picture1.Line (x1, y1)-(x2, y2), vbBlack
    End Sub
    hi bro! tks for great code...

    but really i need to consider a time and ather city.... example:

    Napoli 12:20
    Milano 10:00
    Torino 09:00
    Firenze 17:15
    ecc

    i need to draw the line based the time...

    in my case:

    Torino draw line to Milan an to the end Milano to Napoli

    In effect consider the time of starting draw.

    sorry for that.

    note:
    the data are stored in access table and i use ADO.

    table structure with the two field:
    City Time
    Last edited by luca90; May 19th, 2019 at 04:40 AM.

  7. #7

    Thread Starter
    Frenzied Member
    Join Date
    Mar 2005
    Location
    Italy-Napoli
    Posts
    1,881

    Re: DRAW line between two point

    Quote Originally Posted by passel View Post
    With the project given, and the red circles given by shape controls.
    Code:
    Option Explicit
    Private Sub Form_Load()
    'To redefine the coordinates of the origin
    Picture1.Scale (0, 5000)-(5000, 0)
    Picture1.AutoRedraw = True
    End Sub
    
    Private Sub Command2_Click()
      Picture1.Cls
    End Sub
    
    Private Sub Command1_Click()
      Dim x1 As Single, y1 As Single
      Dim x2 As Single, y2 As Single
      x1 = Shape1.Left + Shape1.Width / 2
      y1 = Shape1.Top - Shape1.Height / 2
      x2 = Shape2.Left + Shape2.Width / 2
      y2 = Shape2.Top - Shape2.Height / 2
      Picture1.Line (x1, y1)-(x2, y2), vbBlack
    End Sub
    hi bro! tks for great code...

    but really i need to consider a time and ather city.... example:

    Napoli 12:20
    Milano 10:00
    Torino 09:00

    i need to draw the line based the time...

    in my case:

    Torino draw line to Milan an to the end Milano to Napoli

    In effect consider the time of starting draw.

    sorry for that.

  8. #8
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    5,202

    Re: DRAW line between two point

    I guess I'm not going to work on sorting by time.
    But I would consider creating a list of cities with their locations, and maybe creating a route in the proper order from the list, then simply looping through the route and drawing.

    An example using Latitude and Longitude for the coordinates, and using the three cities you mentioned.
    This code will draw the red dot, and print the name, so you don't need shape controls and labels on the picturebox ahead of time.
    Code:
    Option Explicit
    
    Private Type CityInfo
      Name As String
      Lat As Single
      Lng As Single
      Time As Date
    End Type
    
    Dim Route() As CityInfo
    
    Private Sub Form_Load()
    ReDim Route(2)
    With Route(0)
      .Name = "Torino"
      .Lat = 45.076
      .Lng = 7.7
      .Time = CDate("09:00")
    End With
    
    With Route(1)
      .Name = "Milano"
      .Lat = 45.465
      .Lng = 9.186
      .Time = CDate("10:00")
    End With
    
    With Route(2)
      .Name = "Napoli"
      .Lat = 40.855
      .Lng = 14.268
      .Time = CDate("12:20")
    End With
    
    'To redefine the coordinates of the origin
    Picture1.Scale (6.34, 47.2)-(18.64, 37.8)  'longitude, latitude
    Picture1.AutoRedraw = True
    End Sub
    
    Private Sub Command2_Click()
      Picture1.Cls
    End Sub
    
    Private Sub Command1_Click()
      
      Dim i As Integer
      Picture1.FillStyle = vbFSSolid
      Picture1.FillColor = vbRed
      Picture1.ForeColor = vbBlack
      Picture1.FontBold = True
      
      For i = 0 To UBound(Route)
        With Route(i)
          Picture1.Circle (.Lng, .Lat), 0.06, vbRed
          Picture1.CurrentY = Picture1.CurrentY + 0.25
          Picture1.Print .Name
        End With
      Next
      
      Picture1.PSet (Route(0).Lng, Route(0).Lat) 'set initial point
      For i = 1 To UBound(Route)  ' Connecting lines
        With Route(i)
          Picture1.Line -(.Lng, .Lat), vbGreen
        End With
      Next
      
    End Sub

  9. #9

    Thread Starter
    Frenzied Member
    Join Date
    Mar 2005
    Location
    Italy-Napoli
    Posts
    1,881

    Re: DRAW line between two point

    Quote Originally Posted by passel View Post
    I guess I'm not going to work on sorting by time.
    But I would consider creating a list of cities with their locations, and maybe creating a route in the proper order from the list, then simply looping through the route and drawing.

    An example using Latitude and Longitude for the coordinates, and using the three cities you mentioned.
    This code will draw the red dot, and print the name, so you don't need shape controls and labels on the picturebox ahead of time.
    Code:
    Option Explicit
    
    Private Type CityInfo
      Name As String
      Lat As Single
      Lng As Single
      Time As Date
    End Type
    
    Dim Route() As CityInfo
    
    Private Sub Form_Load()
    ReDim Route(2)
    With Route(0)
      .Name = "Torino"
      .Lat = 45.076
      .Lng = 7.7
      .Time = CDate("09:00")
    End With
    
    With Route(1)
      .Name = "Milano"
      .Lat = 45.465
      .Lng = 9.186
      .Time = CDate("10:00")
    End With
    
    With Route(2)
      .Name = "Napoli"
      .Lat = 40.855
      .Lng = 14.268
      .Time = CDate("12:20")
    End With
    
    'To redefine the coordinates of the origin
    Picture1.Scale (6.34, 47.2)-(18.64, 37.8)  'longitude, latitude
    Picture1.AutoRedraw = True
    End Sub
    
    Private Sub Command2_Click()
      Picture1.Cls
    End Sub
    
    Private Sub Command1_Click()
      
      Dim i As Integer
      Picture1.FillStyle = vbFSSolid
      Picture1.FillColor = vbRed
      Picture1.ForeColor = vbBlack
      Picture1.FontBold = True
      
      For i = 0 To UBound(Route)
        With Route(i)
          Picture1.Circle (.Lng, .Lat), 0.06, vbRed
          Picture1.CurrentY = Picture1.CurrentY + 0.25
          Picture1.Print .Name
        End With
      Next
      
      Picture1.PSet (Route(0).Lng, Route(0).Lat) 'set initial point
      For i = 1 To UBound(Route)  ' Connecting lines
        With Route(i)
          Picture1.Line -(.Lng, .Lat), vbGreen
        End With
      Next
      
    End Sub
    BRO...
    i not have dubt your code work:-)
    but i cannot test now, perphas tomorrow.
    tks in other case for your time.

  10. #10

    Thread Starter
    Frenzied Member
    Join Date
    Mar 2005
    Location
    Italy-Napoli
    Posts
    1,881

    Re: DRAW line between two point

    Quote Originally Posted by passel View Post
    I guess I'm not going to work on sorting by time.
    But I would consider creating a list of cities with their locations, and maybe creating a route in the proper order from the list, then simply looping through the route and drawing.

    An example using Latitude and Longitude for the coordinates, and using the three cities you mentioned.
    This code will draw the red dot, and print the name, so you don't need shape controls and labels on the picturebox ahead of time.
    Code:
    Option Explicit
    
    Private Type CityInfo
      Name As String
      Lat As Single
      Lng As Single
      Time As Date
    End Type
    
    Dim Route() As CityInfo
    
    Private Sub Form_Load()
    ReDim Route(2)
    With Route(0)
      .Name = "Torino"
      .Lat = 45.076
      .Lng = 7.7
      .Time = CDate("09:00")
    End With
    
    With Route(1)
      .Name = "Milano"
      .Lat = 45.465
      .Lng = 9.186
      .Time = CDate("10:00")
    End With
    
    With Route(2)
      .Name = "Napoli"
      .Lat = 40.855
      .Lng = 14.268
      .Time = CDate("12:20")
    End With
    
    'To redefine the coordinates of the origin
    Picture1.Scale (6.34, 47.2)-(18.64, 37.8)  'longitude, latitude
    Picture1.AutoRedraw = True
    End Sub
    
    Private Sub Command2_Click()
      Picture1.Cls
    End Sub
    
    Private Sub Command1_Click()
      
      Dim i As Integer
      Picture1.FillStyle = vbFSSolid
      Picture1.FillColor = vbRed
      Picture1.ForeColor = vbBlack
      Picture1.FontBold = True
      
      For i = 0 To UBound(Route)
        With Route(i)
          Picture1.Circle (.Lng, .Lat), 0.06, vbRed
          Picture1.CurrentY = Picture1.CurrentY + 0.25
          Picture1.Print .Name
        End With
      Next
      
      Picture1.PSet (Route(0).Lng, Route(0).Lat) 'set initial point
      For i = 1 To UBound(Route)  ' Connecting lines
        With Route(i)
          Picture1.Line -(.Lng, .Lat), vbGreen
        End With
      Next
      
    End Sub
    hi bro, tested now!
    work perfect!

    But napoli is in the sea!:-) Milano and Torino not in the correct position...

    How to center in correct position?

    in other case sorry for delay.
    Attached Files Attached Files

  11. #11
    PowerPoster
    Join Date
    Jun 2013
    Posts
    4,279

    Re: DRAW line between two point

    Quote Originally Posted by luca90 View Post
    But napoli is in the sea!:-) Milano and Torino not in the correct position...
    The correct ScaleValues depend on the underlying "Italy-Bitmap" you've choosen -
    and also whether you've made the PicBox smaller than the original Bitmap it contains.

    For the Zip-Project you've posted - the following scale-values make it look a bit better to me:
    Code:
      Picture1.AutoSize = True 'make the picbox as large as the underlying bitmap
      Picture1.Scale (6.1, 47.2)-(20, 36.6) 'slight correction for the scale corner-points
    HTH

    Olaf

  12. #12
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    5,202

    Re: DRAW line between two point

    Hopefully, Olaf has gotten you close enough with the given image and scale.
    I didn't look at it, but assume I wouldn't do better.

    Another issue, is type of projection used for the map. You can use the built in Scale capability of VB6 when the projection of latitude and longitude are fairly close to a linear grid, i.e. lines of longitude are parallel and run north-south across the map.
    Such a projection is easy to map points in lat,lng to the map, but are not good for accurate distance measurement, as the maps are distorted in the east-west direction.

    There are many types of projections, to convert the 3D spheroid shape of the earth to the 2D map for viewing on a screen or paper, and they are all compromised in some aspect.

    If you're going to use different maps, usually something I've added to the code is some kind of calibration option, so when you load a map, you enable the calibration mode, then pick two points on the map that are diagonally opposed to each other, (e.g. upper left for a north-west point, and lower right for a south-east point) where you know what the lat,lng is and enter that information. The code can then use the current scales X,Y values for those points vs the lat,lng for those points and set the Scale based on those.

    But, if you need more accuracy and the lines of longitude are not parallel, then you should pick four points, near the corners of the map, and then instead of using a scale that is set to directly match lat,lng, choose a scale of convenience, that should at least give you pixel accuracy, and run a calculation to convert between that scale and lat,lng based on the four corners that were input.
    Typically, the project this would be used for is where the lines of longitude curve in toward the pole, so while the X,Y scale may be close to being correct in distance, the number of degrees of longitude changes with every row of pixels. In the case of Italy, being in the northern hemisphere, the number of degrees of longitude increases as you go north, essentially a function of the Cos of the Latitude.

    What I've done in the past, when the four points are entered, I create a lookup table, with an entry for each pixel vertically in the map, i.e. if the map is 900 pixels high, the table would have 900 entries in it. Each entry would hold what longitude the leftmost pixel of the map at that Y value would be, and what the change in longitude is for 1 pixel horizontally on that line. You could then convert the X value of the mouse input by the equation:
    Lng = LeftLng(Y) + LngDelta(Y) * X

    Likewise, to convert Longitude into an X value, you would convert Latitude to a Y value, then use that Y val to convert the longitude :
    X = (Longitude - LeftLng(Y)) / LngDelta(Y)

    p.s. I looked at your test code, and at the map a bit.
    I'm not sure either of the methods above will work with the map you have. It would probably take more time than I have to prove it, but I think the map you have, the projection is one where neither the lines of latitude or longitude are linear, i.e. the lines of latitude are probably curved, and the lines of longitude are splayed, narrower at the top than the bottom, and not vertical across the project, i.e. the lines of longitude on the left side of the map may slant toward the left, from top to bottom, and the ones on the right may slant toward the right, top to bottom, like the map found at this link: https://www.mapsofworld.com/lat_long...-lat-long.html

    A mercator type projection would be the easiest to plot against since the lat, lng lines would be vertical and horizontal.
    Last edited by passel; Jun 1st, 2019 at 12:53 AM.

  13. #13

    Thread Starter
    Frenzied Member
    Join Date
    Mar 2005
    Location
    Italy-Napoli
    Posts
    1,881

    Re: DRAW line between two point

    Quote Originally Posted by passel View Post
    I guess I'm not going to work on sorting by time.
    But I would consider creating a list of cities with their locations, and maybe creating a route in the proper order from the list, then simply looping through the route and drawing.

    An example using Latitude and Longitude for the coordinates, and using the three cities you mentioned.
    This code will draw the red dot, and print the name, so you don't need shape controls and labels on the picturebox ahead of time.
    Code:
    Option Explicit
    
    Private Type CityInfo
      Name As String
      Lat As Single
      Lng As Single
      Time As Date
    End Type
    
    Dim Route() As CityInfo
    
    Private Sub Form_Load()
    ReDim Route(2)
    With Route(0)
      .Name = "Torino"
      .Lat = 45.076
      .Lng = 7.7
      .Time = CDate("09:00")
    End With
    
    With Route(1)
      .Name = "Milano"
      .Lat = 45.465
      .Lng = 9.186
      .Time = CDate("10:00")
    End With
    
    With Route(2)
      .Name = "Napoli"
      .Lat = 40.855
      .Lng = 14.268
      .Time = CDate("12:20")
    End With
    
    'To redefine the coordinates of the origin
    Picture1.Scale (6.34, 47.2)-(18.64, 37.8)  'longitude, latitude
    Picture1.AutoRedraw = True
    End Sub
    
    Private Sub Command2_Click()
      Picture1.Cls
    End Sub
    
    Private Sub Command1_Click()
      
      Dim i As Integer
      Picture1.FillStyle = vbFSSolid
      Picture1.FillColor = vbRed
      Picture1.ForeColor = vbBlack
      Picture1.FontBold = True
      
      For i = 0 To UBound(Route)
        With Route(i)
          Picture1.Circle (.Lng, .Lat), 0.06, vbRed
          Picture1.CurrentY = Picture1.CurrentY + 0.25
          Picture1.Print .Name
        End With
      Next
      
      Picture1.PSet (Route(0).Lng, Route(0).Lat) 'set initial point
      For i = 1 To UBound(Route)  ' Connecting lines
        With Route(i)
          Picture1.Line -(.Lng, .Lat), vbGreen
        End With
      Next
      
    End Sub
    Hi!
    ... instead to draw a line from Napoli to MIlano to Torino, eccc...
    With the same routine possible to draw a raised line from Napoli to Torino, Napoli to Milano ecc....

  14. #14
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    5,202

    Re: DRAW line between two point

    I'm not sure what you mean by "raised line".

    The given code is just an example, so has hardcoded values. Since you're using a database and have city and times in it, I don't know how you're planning to use the software, i.e. how you separate the data into different routes (if that is what you're asking).

    If you want to draw line segments in pairs, or multiple disjointed routes of any number of points, then you should be able to deconstruct what was done in the example and construct what you need.

    As a minimum example, the last block of code in the command1 button, here,
    Code:
      Picture1.PSet (Route(0).Lng, Route(0).Lat) 'set initial point
      For i = 1 To UBound(Route)  ' Connecting lines
        With Route(i)
          Picture1.Line -(.Lng, .Lat), vbGreen
        End With
      Next
    could be put in a sub, and you would have a process that pulls a number of locations into the Route array, and call that sub to plot the data. You could call the process that fills the array with locations a number of time, and call the sub to plot that route each time, so would be plotting multiple routes of whatever number of points you want.

    Perhaps you would like to add passing a color to the sub, so instead of plotting all the lines using vbGreen, you would have different colors for each route.

    Its up to you to build on what was provided, rather than us to tailor the code for your use. I don't have the time for that kind of entertainment.

  15. #15

    Thread Starter
    Frenzied Member
    Join Date
    Mar 2005
    Location
    Italy-Napoli
    Posts
    1,881

    Re: DRAW line between two point

    Quote Originally Posted by passel View Post
    I'm not sure what you mean by "raised line".

    The given code is just an example, so has hardcoded values. Since you're using a database and have city and times in it, I don't know how you're planning to use the software, i.e. how you separate the data into different routes (if that is what you're asking).

    If you want to draw line segments in pairs, or multiple disjointed routes of any number of points, then you should be able to deconstruct what was done in the example and construct what you need.

    As a minimum example, the last block of code in the command1 button, here,
    Code:
      Picture1.PSet (Route(0).Lng, Route(0).Lat) 'set initial point
      For i = 1 To UBound(Route)  ' Connecting lines
        With Route(i)
          Picture1.Line -(.Lng, .Lat), vbGreen
        End With
      Next
    could be put in a sub, and you would have a process that pulls a number of locations into the Route array, and call that sub to plot the data. You could call the process that fills the array with locations a number of time, and call the sub to plot that route each time, so would be plotting multiple routes of whatever number of points you want.

    Perhaps you would like to add passing a color to the sub, so instead of plotting all the lines using vbGreen, you would have different colors for each route.

    Its up to you to build on what was provided, rather than us to tailor the code for your use. I don't have the time for that kind of entertainment.
    sorry...
    I'm not sure what you mean by "raised line".*
    radius lines

  16. #16
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    5,202

    Re: DRAW line between two point

    Ok, I see.
    Well, what I described should work.
    I would just put the drawing part of the code in a Sub that can be called to draw a route, and then just call it with the various radius lines that you want in the array.
    If you only needed the two points, the origin and the destination, then I would just create an array of two for the two locations, populate the two locations and call the sub, then change the second location and call it again. Continue for all the radii end points.

    If you want to get a bit more productive, perhaps put that logic in a sub itself, and pass two parameters to it, the origin and an array of destinations, and have that sub do the loop on the array, doing the above process.

  17. #17

    Thread Starter
    Frenzied Member
    Join Date
    Mar 2005
    Location
    Italy-Napoli
    Posts
    1,881

    Re: DRAW line between two point

    Quote Originally Posted by passel View Post
    I guess I'm not going to work on sorting by time.
    But I would consider creating a list of cities with their locations, and maybe creating a route in the proper order from the list, then simply looping through the route and drawing.

    An example using Latitude and Longitude for the coordinates, and using the three cities you mentioned.
    This code will draw the red dot, and print the name, so you don't need shape controls and labels on the picturebox ahead of time.
    Code:
    Option Explicit
    
    Private Type CityInfo
      Name As String
      Lat As Single
      Lng As Single
      Time As Date
    End Type
    
    Dim Route() As CityInfo
    
    Private Sub Form_Load()
    ReDim Route(2)
    With Route(0)
      .Name = "Torino"
      .Lat = 45.076
      .Lng = 7.7
      .Time = CDate("09:00")
    End With
    
    With Route(1)
      .Name = "Milano"
      .Lat = 45.465
      .Lng = 9.186
      .Time = CDate("10:00")
    End With
    
    With Route(2)
      .Name = "Napoli"
      .Lat = 40.855
      .Lng = 14.268
      .Time = CDate("12:20")
    End With
    
    'To redefine the coordinates of the origin
    Picture1.Scale (6.34, 47.2)-(18.64, 37.8)  'longitude, latitude
    Picture1.AutoRedraw = True
    End Sub
    
    Private Sub Command2_Click()
      Picture1.Cls
    End Sub
    
    Private Sub Command1_Click()
      
      Dim i As Integer
      Picture1.FillStyle = vbFSSolid
      Picture1.FillColor = vbRed
      Picture1.ForeColor = vbBlack
      Picture1.FontBold = True
      
      For i = 0 To UBound(Route)
        With Route(i)
          Picture1.Circle (.Lng, .Lat), 0.06, vbRed
          Picture1.CurrentY = Picture1.CurrentY + 0.25
          Picture1.Print .Name
        End With
      Next
      
      Picture1.PSet (Route(0).Lng, Route(0).Lat) 'set initial point
      For i = 1 To UBound(Route)  ' Connecting lines
        With Route(i)
          Picture1.Line -(.Lng, .Lat), vbGreen
        End With
      Next
      
    End Sub
    ops..
    Instead a fixed value in array. I have a Access table1 with filds name:

    NOME
    LTD
    LNG
    DATA

    and i needd to loop all value in table, with a simple SQL="select * from my table1 order byDATA"

    how to create now thei new array?
    Tks as usual, bro.

    note:
    assuming the started point is always value of Napoli for all item in array
    Last edited by luca90; Jun 9th, 2019 at 04:15 AM.

  18. #18

    Thread Starter
    Frenzied Member
    Join Date
    Mar 2005
    Location
    Italy-Napoli
    Posts
    1,881

    Re: DRAW line between two point

    Quote Originally Posted by passel View Post
    I guess I'm not going to work on sorting by time.
    But I would consider creating a list of cities with their locations, and maybe creating a route in the proper order from the list, then simply looping through the route and drawing.

    An example using Latitude and Longitude for the coordinates, and using the three cities you mentioned.
    This code will draw the red dot, and print the name, so you don't need shape controls and labels on the picturebox ahead of time.
    Code:
    Option Explicit
    
    Private Type CityInfo
      Name As String
      Lat As Single
      Lng As Single
      Time As Date
    End Type
    
    Dim Route() As CityInfo
    
    Private Sub Form_Load()
    ReDim Route(2)
    With Route(0)
      .Name = "Torino"
      .Lat = 45.076
      .Lng = 7.7
      .Time = CDate("09:00")
    End With
    
    With Route(1)
      .Name = "Milano"
      .Lat = 45.465
      .Lng = 9.186
      .Time = CDate("10:00")
    End With
    
    With Route(2)
      .Name = "Napoli"
      .Lat = 40.855
      .Lng = 14.268
      .Time = CDate("12:20")
    End With
    
    'To redefine the coordinates of the origin
    Picture1.Scale (6.34, 47.2)-(18.64, 37.8)  'longitude, latitude
    Picture1.AutoRedraw = True
    End Sub
    
    Private Sub Command2_Click()
      Picture1.Cls
    End Sub
    
    Private Sub Command1_Click()
      
      Dim i As Integer
      Picture1.FillStyle = vbFSSolid
      Picture1.FillColor = vbRed
      Picture1.ForeColor = vbBlack
      Picture1.FontBold = True
      
      For i = 0 To UBound(Route)
        With Route(i)
          Picture1.Circle (.Lng, .Lat), 0.06, vbRed
          Picture1.CurrentY = Picture1.CurrentY + 0.25
          Picture1.Print .Name
        End With
      Next
      
      Picture1.PSet (Route(0).Lng, Route(0).Lat) 'set initial point
      For i = 1 To UBound(Route)  ' Connecting lines
        With Route(i)
          Picture1.Line -(.Lng, .Lat), vbGreen
        End With
      Next
      
    End Sub
    ops..
    Instead a fixed value in array. I have a Access table1 with filds name:

    NOME
    LTD
    LNG
    DATA

    and i needd to loop all value in table, with a simple SQL="select * from my table1 order byDATA"

    how to create now thei new array?
    Tks as usual, bro.

    note:
    assuming the started point is always value of Napoli for all item in array
    Last edited by luca90; Jun 9th, 2019 at 04:15 AM.

  19. #19
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    5,202

    Re: DRAW line between two point

    I haven't used data bases, so am not experienced with how to access the data from them.
    If you need to know how to access the data in the database, then you should start a new thread and ask a question specific to that task so others with that knowledge may respond.

  20. #20

    Thread Starter
    Frenzied Member
    Join Date
    Mar 2005
    Location
    Italy-Napoli
    Posts
    1,881

    Re: DRAW line between two point

    Quote Originally Posted by passel View Post
    Ok, I see.
    Well, what I described should work.
    I would just put the drawing part of the code in a Sub that can be called to draw a route, and then just call it with the various radius lines that you want in the array.
    If you only needed the two points, the origin and the destination, then I would just create an array of two for the two locations, populate the two locations and call the sub, then change the second location and call it again. Continue for all the radii end points.

    If you want to get a bit more productive, perhaps put that logic in a sub itself, and pass two parameters to it, the origin and an array of destinations, and have that sub do the loop on the array, doing the above process.
    HI bro,
    the project work perfect, mark the post as resolved
    but only one...
    possible to make in green the dot point only for the started city?

    tks passel

  21. #21
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    5,202

    Re: DRAW line between two point

    I would probably do it one of two ways.
    Either at the end after all the lines have been drawn, go back and draw a green circle for the originating point "on top" of the red dot.

    Or, more likely, change the the circle loop to draw the initial point outside the loop, and then the rest of the points in the loop.
    Code:
      With Route(0)  'draw the first point using a green "dot"
          Picture1.Circle (.Lng, .Lat), 0.06, vbGreen
          Picture1.CurrentY = Picture1.CurrentY + 0.25
          Picture1.Print .Name
      End With
    
      For i = 1 To UBound(Route)
        With Route(i)  'draw the rest of the points with a red "dot"
          Picture1.Circle (.Lng, .Lat), 0.06, vbRed
          Picture1.CurrentY = Picture1.CurrentY + 0.25
          Picture1.Print .Name
        End With
      Next

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width