Wrox Programmer Forums Problem with function
 |
 Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
 Welcome to the p2p.wrox.com Forums. You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com

July 11th, 2005, 06:56 PM
 mat41 Friend of Wrox Join Date: Jan 2004 Posts: 1,870 Thanks: 12 Thanked 20 Times in 20 Posts
Problem with function

To briefly explain what I am doing: I am taking lat and longatude values EG 34 54.5N , 139 24.5E These values are required to be stored as integers (allows for searching coords etc) I apply a calculation to them to make them integers, they end up as either positive integers (Lat East ot Long north values) or negative integers (Lat West or Long South values)

(LAT) 34 54.5N gets stored as 20945
(LONG)139 24.5E gets stored as 83645

When I display the numbers I reverse the calculation using two functions:

function latToString(intValue)
dim nORs
nORs = "N"
if int(intValue) < 0 then
nORs = "S"
latToString = abs(latToString)
end if
latToString = fix(intValue / 600) & "&nbsp;" & ((intValue mod 600) / 10) & nORs
end function

function longToString(intValue)
dim eORw
eORw = "E"
if int(intValue) < 0 then
eORw = "W"
longToString = abs(longToString)
end if
longToString = fix(intValue / 600) & "&nbsp;" & ((intValue mod 600) / 10) & eORw
end function

When I pass 20945 into the latToString function it returns the value it should: 34 54.5N

When I pass 83645 into the longToString function it returns the figures it should however they are negative numbers: -139 -24.5W

From what I can see I am using the abs function correctly, can anybody spot what I am doing wrong?

TYIA

Matt
__________________
Matt

July 14th, 2005, 02:06 PM
 Ron Howerton Friend of Wrox Join Date: Jun 2003 Posts: 428 Thanks: 57 Thanked 2 Times in 2 Posts

You don't indicate whether this is VBScript or ASP code so this is only a guess. But the first thing that occurs to me is that this reminds me of an old overflow error.

If this is not VBScript, I'd suggest that the problem may be associated with a failure to identify the type of the function arguments/result used. if it is VBScript, you may want to verify the upper end of possible values.

July 15th, 2005, 04:24 AM
 pgtips Friend of Wrox Join Date: Jun 2003 Posts: 1,212 Thanks: 0 Thanked 1 Time in 1 Post

look again Mat, you're using the input 'intValue' in your calculation so you're not actually using the result of the Abs function.

rgds
Phil

July 16th, 2005, 01:19 AM
 mat41 Friend of Wrox Join Date: Jan 2004 Posts: 1,870 Thanks: 12 Thanked 20 Times in 20 Posts

Ahhh so I am, cheers pgtips. I left this the other day and hadnt been back to it. All good now - thanking you

Matt

 Similar Threads Thread Thread Starter Forum Replies Last Post Problem with Round Function darrenb Access 3 May 22nd, 2007 05:45 PM Date Function problem beetle_jaipur Classic ASP Basics 5 July 6th, 2006 01:08 PM Msgbox Function Problem theokrtz Classic ASP Basics 4 July 4th, 2006 03:35 AM shell function problem bml Excel VBA 1 February 12th, 2005 05:42 PM Problem with a Javascript function SuMajestad PHP How-To 4 August 17th, 2004 09:04 PM