Calculating GPS points

Amorre
09-02-2003, 07:34 AM
Hello, my problem with Visual Basic 6.0 is this:

reading from web, i get latitude points as "6000,0161" or so on..
with that, 60 is no problem atm, it's read as it is, but then for 00,0161
i need to perform an calculation as:

lat = ("00,0161" * 100) / 60

where correct answer is: 00,026833333..., i get 2,6833333333...

then i add 60 to and it shall be 60,000268

problem again is that visual basic is taking the zero's away from it, is there any way I could get my correct answer ?

again for example: lat = ("16,5267" * 100) / 60 gives 27,5445
so it shall be 60,275445 which is correct, only thing is the vanishing zeroes

Thank you.

SpaceFrog
09-02-2003, 07:48 AM
lat = (val("16,5267") * 100 / 60 ????

you are trying to divide alphas ?

DeX
09-02-2003, 07:56 AM
Check that vb does not convert the number into scientific format. You can use the Format function to convert numbers into various formats. Look it up in help for more detail.

samr
09-02-2003, 07:56 AM
I'm not fully sure what you are trying do do, as the "," is taken to mean different things - a thousands sepperator on an English PC, or a decimal point on a some other systems, so I don't know exactly what you are trying to do with your code. I think though that the "," in this case is used as a section sepperator for the number, so the numbers should be used seperately. Try splitting the number up into the 2 seperate section:
Lng = left("6000,0161", 4)
Lat = Right("6000,0161", 4)
then doing whatever you want to do with the numbers.

Amorre
09-02-2003, 07:58 AM
[QUOTEPOST='SpaceFrog']lat = (val("16,5267") * 100 / 60 ????

it is actually like that atm
lat = val(latfromweb)
lat = mid(lat, 3, 8)
lat = (lat *100) / 60

but if latfromweb is "6000,0161" then after val(latfromweb) it is given only 6000..

but if latfromweb is "6000,0161" then after CDbl(latfromweb) it is given 6000,0161

so atm:

lat = CDbl(latfromweb) '"6000,0161"
lat = mid(lat, 3, 8)
lat = (lat * 100) / 60

answer: 2,683333...

crabby
09-02-2003, 07:59 AM
at first replace this coma with a dot and then have a look at the results again

Amorre
09-02-2003, 08:01 AM
at first replace this coma with a dot and then have a look at the results again

i changed regionalsettings to use dot, still same answer

SpaceFrog
09-02-2003, 08:10 AM
use replace(mystring,",",".")

Amorre
09-02-2003, 08:15 AM
Lat = CDbl("6000,0161")
Lat = Replace(Lat, ",", ".")
Lat = Mid(Lat, 3, 8)
Lat = (Lat * 100) / 60
Text1.Text = Lat

Crashed on calculation line: Run-Time error '13': Type Mismatch

Lat = CDbl("6000,0161")
Lat = Replace(Lat, ",", ".")
Lat = Mid(Lat, 3, 8)
Lat = ((Val(Lat)) * 100) / 60
Text1.Text = Lat

still same thing, 2,68333......

SpaceFrog
09-02-2003, 08:15 AM
this should not crush :
latfromweb = "6000,0161"
lat = mid(latfromweb, 3, 8)
lat = replace(lat,",",".")
lat = CDbl(lat)
lat = (lat * 100) / 60

SpaceFrog
09-02-2003, 08:17 AM
replace works on strings, so replace before converting to double ...

crabby
09-02-2003, 08:24 AM
Private Sub Command2_Click()
lat = "6000.0161"
MsgBox lat
lat = Mid(lat, 3, 8)
MsgBox lat
latint = Val(lat)
MsgBox latint
latint = (latint * 100) / 60
MsgBox latint
End Sub

Amorre
09-02-2003, 08:25 AM
Lat = "6000,0161"
Lat = Mid(Lat, 3, 8)
Lat = Replace(Lat, ",", ".")
Lat = Val(Lat)
Lat = (Lat * 100) / 60
Text1.Text = Lat

using CDbl I get Type Mismatch, using Val(Lat) it's still the same 2,68333.....

Amorre
09-02-2003, 08:29 AM
Private Sub Command2_Click()
lat = "6000.0161"
MsgBox lat <-------- 6000.0161
lat = Mid(lat, 3, 8)
MsgBox lat <-------- 00.0161
latint = Val(lat)
MsgBox latint <--------- 0,0161
latint = (latint * 100) / 60
MsgBox latint <--------- 2,68333333333333333333E-02
End Sub

DeX
09-02-2003, 08:30 AM
Are you sure you get 2,68333 Amorre?

Because I get 2.68333333333333E-02 which is equivelent to 0.0268333333333333 and is the 'correct' value you stated in your first post.

Amorre
09-02-2003, 08:31 AM
Are you sure you get 2,68333 Amorre?

Because I get 2.68333333333333E-02 which is equivelent to 0.0268333333333333.

nice, i'm not an guru of math ;) but that helps abit, tho now howto show the result as 00.02683333 ?

DeX
09-02-2003, 08:32 AM
nice, i'm not an guru of math ;) but that helps abit, tho now howto show the result as 00.02683333 ?

Read my first post in this thread.

SpaceFrog
09-02-2003, 08:37 AM
can you round the number ?
or formatnumber ...

Amorre
09-02-2003, 08:38 AM
rounding the lat/lon values are not possible for accurate gps values,
looking for format help on web, vb help says msdn not installed, d'uh

crabby
09-02-2003, 08:41 AM
msdn can be accessed over tihe internet why would you want to change the nice scientific format into some dodgy string stuff

samr
09-02-2003, 08:46 AM
Format("2.68333333333333E-02", "00.0000")

passel
09-02-2003, 11:14 AM
Dim lat As Double, Lati As Double, Latf As Double

lat = CDbl("6000,0161")
Latf = (lat - Fix(lat)) / 60
lafi = Fix(lat) / 100
lat = lafi + Latf

Debug.Print lat

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum