Integers

1. Senior Member
Join Date
Dec 1969
Posts
135

## Integers

Here&#039;s my code... I am taking a Latitude/Longitude in DDDMMSS version and converting to decimal... I need to be able to break up the string and turn the DDD into an integer, MM into an integer and SS into an integer...I am getting a type mismatch error.... I have also use Integer and Clng instead of Cint..Here&#039;s some code..<BR><BR>LongDec = (Cint(mid(LongStr, 1, 3))) + (Cint(mid(LongStr, 4, 2)) / 60) + (Cint(mid(LongStr, 6, 2)) / 3600) &#039;here are my errors... <BR><BR><BR>if mid(LongStr, 8, 1) = "W" then<BR> LongDec = LongDec * -1<BR>end if<BR><BR>LongDec = round(LongDec, 4)<BR><BR>Any ideas why this is happening?

2. Senior Member
Join Date
Dec 1969
Posts
96,118

## Maybe break it into pieces?

dg = mid(LongStr, 1, 3)<BR>Response.Write "DEBUG: degrees as string=[" & dg & "]&#060;br/&#062;"<BR>dg = CDBL( dg ) <BR><BR>mn = mid(LongStr, 4, 2)<BR>Response.Write "DEBUG: minutes as string=[" & mn & "]&#060;br/&#062;"<BR>mn = CDBL( mn )<BR>mn = mn / 60.0<BR><BR>sc = mid(LongStr, 6, 2)<BR>Response.Write "DEBUG: seconds as string=[" & sc & "]&#060;br/&#062;"<BR>sc = CDBL( sc )<BR>sc = sc / 3600.0<BR><BR>LongDec = dg + mn + sc<BR>...<BR><BR>****************<BR><BR>I used CDBL instead of CINT, because you don&#039;t *really* want to do any integer arithmetic, so why not convert to double ASAP? I don&#039;t think it matters in this case, but what can it hurt?<BR><BR>Naturally, you can pull out the DEBUG when you figure out what is happening.<BR><BR><BR>

3. Senior Member
Join Date
Dec 1969
Posts
1,686

## Try

to convert LongStr before you break it up...

4. Senior Member
Join Date
Dec 1969
Posts
96,118

## HUH?

Convert it to what???<BR><BR>Or are you suggesting that it is not a string to begin with? Hmmm...a real possibility.<BR><BR>Still, MID should *force* it to be converted to a string. <BR><BR>Ehhh...but not a bad idea to use CSTR on it before starting.<BR><BR> LongStr = CSTR( LongStr ) &#039; just for safety<BR><BR>

5. Senior Member
Join Date
Dec 1969
Posts
135

## Cool, thanks it worked great! <EOP>

.

6. Senior Member
Join Date
Dec 1969
Posts
96,118

## NO FAIR!

What was the bug?????<BR><BR>

7. Senior Member
Join Date
Dec 1969
Posts
135

## There's no crying in ASP...

When i changed it to CDBL it worked just fine... <BR><BR>Now the tricky part of this program is to go back from a Decimal to String.. stupid latitude and longitudes... I&#039;ll never win...<BR><BR>_Abs

8. Senior Member
Join Date
Dec 1969
Posts
96,118

## You mean like this?

&#060;%<BR>dms = 7.1811111<BR><BR>dg = Int(dms)<BR>dms = 60 * ( dms - dg )<BR>mn = Int(dms)<BR>sc = Round( 60 * (dms - mn) )<BR>If sc = 60 Then mn = mn + 1<BR>If mn = 60 Then dg = dg + 1<BR><BR>strDMS = dg & "° " & mn & "&#039; " & sc & """"<BR>...<BR>%&#062;<BR>

9. Senior Member
Join Date
Dec 1969
Posts
96,118

SOrry!<BR><BR>FOrgot to set the values back to zero!<BR><BR>&#060;%<BR>dms = 7.1811111<BR><BR>dg = Int(dms)<BR>dms = 60 * ( dms - dg )<BR>mn = Int(dms)<BR>sc = Round( 60 * (dms - mn) )<BR>If sc = 60 Then <BR> mn = mn + 1<BR> sc = 0<BR>End If<BR>If mn = 60 Then <BR> dg = dg + 1<BR> mn = 0<BR>End If<BR><BR>strDMS = dg & "° " & mn & "&#039; " & sc & """"<BR>...<BR>%&#062;<BR>

10. Senior Member
Join Date
Dec 1969
Location
Los Angeles, CA
Posts
21,192

## Tell us something about you

we dont already know<BR><BR>sorry just could not resist<BR><BR>:p<BR><BR>

#### Posting Permissions

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