Solved

Larger than Long? Can ASP(VBScript) hance huge integers?

Posted on 2004-07-30
9
5,230 Views
Last Modified: 2008-01-09
Hi all,

I'm currently adding a piece of bandwidth measuring functionality for a web app.

The bandwidth used by each session is stored in a database (SQL Server) as a bigint (32-bit integer allowing number up to, er, 9,223,372,036,854,775,807).

However, ASPs standard INT data type is only 8-bit I believe (therefore can only store numbers up to 32,000). And the Long datatype only goes up to just over 2,000,000,000.
(CDec doesn't work either)

What I may have to do is write some functions for SQL Server that play with the numbers server side - but ya get no points for telling me this.

So:
  How do you handle large integers in ASP? (points specified for quick answer)

if there is no way

  does anyone know of a collection of functions, com components etc that will allow this? (points will go up if it's more complicated)
0
Comment
Question by:JagC
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
  • +1
9 Comments
 
LVL 14

Expert Comment

by:puranik_p
ID: 11675200
 There are no datatypes in ASP (VBScript). Everything is Variant.
  If you are doing your data related stuff in a dll (created with VB6), this will be useful..
  http://www.able-consulting.com/ADODataTypeEnum.htm

  All the best !
0
 
LVL 12

Expert Comment

by:ill
ID: 11675220
are you doing somewhat with number received from DB? why not variant data type?

<html>
<body>
<%= 9223372036854775807+1 %>
</body>
</html>
0
 
LVL 3

Author Comment

by:JagC
ID: 11675324
OK, yeah all variables are of type variant in VBSCript.

BUT some functions require certain datatypes which is why you cast them (if EVERYTHING was a variant and functions didn't care you would never use CInt, CStr etc etc).

I added a value to the database - type bigint, value 4000000000

this was retrieved in ASP and displayed on teh screen ( response.write("number = " & iNumber)

This worked fine. BUT when I tried to do:

response.write("number = " & iNumber / 1024) I recieved an error.

Odd I thought, so I cast the number as an int

iNumber = CInt(iNumber)

and recieved an overflow.

The reason this happened is that arrithmetic operations ( +, - etc) require integers - VBScript will TRY to convert it to the appropriate type

so if
a = 2
b = 4

a + b = 6

If
a = "2"
b = "4"
a + b = 6

See? VBScript tries to convert it.

So when trying to divide, add etc with 4000000000 it looks at it and says 'aha, it's a number, I'll make it an int' and then fails because ints only go up to 32,000

The result is that VB is not being used (Just VBScript in ASP). All I want to do is make the divide the damned number by 1024 but I can't convert it to any datatype that a) can use arrithmetic operations AND b) can hold one of that size.

If I have to write a custom component I think I'll just alter the SQL data as it's written - it's easier :)
0
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 
LVL 7

Accepted Solution

by:
j2nku earned 150 total points
ID: 11675348
0
 
LVL 14

Expert Comment

by:puranik_p
ID: 11675373
Tested this. Working fine.

Response.Write CVar("4000000000") / CVar(1024)
0
 
LVL 12

Expert Comment

by:ill
ID: 11675376
' what is your problem with ?
set rs= x("select ""x""= 9223372036854775807")
 response.write(cDBL(rs(0)) / 1024)

0
 
LVL 14

Expert Comment

by:puranik_p
ID: 11675378
Idea is - explicitly convert evreything to Variant.(wherever you are doing calculations with them)
0
 
LVL 12

Expert Comment

by:ill
ID: 11675406
rem double is only suptype of variant too.
but imo,  SQL server should return final result of calculation.
0
 
LVL 3

Author Comment

by:JagC
ID: 11675647
I didn't think of using double cos I assumed that a set amount of bits would be kept for after the decimal point.
It handled everything I threw at it and kept giving right answered so it's good enough :)
So cheers j2nku.

puranik_P
makes sense, unfortunately I got a variable undefined when using CVar

ill
I'm just playing about with ideas atm. Eventually I'll do most of the processing on SQL Server but for now I just gotta get the concept working :)

Cheers for your help all.
0

Featured Post

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

697 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question