4 Replies - 691 Views - Last Post: 13 October 2011 - 08:22 PM Rate Topic: -----

#1 sujit.4108  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 16-July 08

sql querry for distance calculation (vb6/access)

Posted 11 October 2011 - 10:29 PM

I want to calculate the distance between two given cities.
in access table "distance", which stores distnce values between 2 cities, one column is named "location" which contains all the cities. And rest of the columns are named with those cities (which are actually rows in column "location").

LOCATION   PUNE   MUMBAI    DELHI   ...    ...
-------------------------------------------------
PUNE         0      200      700
MUMBAI       200    0        900        
DELHI        700    900      0
...
...



Now at VB6 side, I want to show the distance from 2 given cities. For that I've combo1 (for source city) and combo2(dest. city). Both combo boxes gain names of the cities from above table, by this code

Dim rs2 As ADODB.Recordset
Private Sub Form_Load()
Set con = New ADODB.Connection
Set rs2 = New ADODB.Recordset

con.Provider = "Microsoft.Jet.OLEDB.4.0"
con.Open "E:\3rd Sem\vb project\frs.mdb"
rs2.Open "distance", con, adOpenStatic, adLockOptimistic

Me.WindowState = 2

Dim i As Integer
'set comboboxes
While Not rs2.EOF
  Combo1.List(i) = rs2.Fields(0)
  Combo2.List(i) = rs2.Fields(0)
  rs2.MoveNext
  i = i + 1
Wend
End Sub


So, I am not getting how to write that sql querry which will return the distance between 2 cities.

Is This A Good Question/Topic? 0
  • +

Replies To: sql querry for distance calculation (vb6/access)

#2 smohd  Icon User is offline

  • Critical Section
  • member icon


Reputation: 1819
  • View blog
  • Posts: 4,627
  • Joined: 14-March 10

Re: sql querry for distance calculation (vb6/access)

Posted 11 October 2011 - 11:57 PM

I have an idea but it may not be the best, since your rows and column are arranged in the same order of names, we may do the following: after someone has made his selection, get the name selected from source query for it to get is row from database, then use the index selected fromdest + 1 to get the index of the column/cell to get your value. I think this may do a trick a little
Was This Post Helpful? 0
  • +
  • -

#3 olibenu  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 45
  • View blog
  • Posts: 537
  • Joined: 31-December 08

Re: sql querry for distance calculation (vb6/access)

Posted 12 October 2011 - 12:35 AM

sujit, you are not using sql queries.
i've used this way of querying dbs in vb6 before, it gets slow very quickly! just saying.
Was This Post Helpful? 0
  • +
  • -

#4 sujit.4108  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 16-July 08

Re: sql querry for distance calculation (vb6/access)

Posted 13 October 2011 - 08:12 PM

So you mean, I should use sql querries instead of these recordset and all?
Was This Post Helpful? 0
  • +
  • -

#5 sujit.4108  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 16-July 08

Re: sql querry for distance calculation (vb6/access)

Posted 13 October 2011 - 08:22 PM

smohd,
Ok. Seems little tricky but let's see if it works! I'll reply if affirmative!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1