Solved

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

Posted on 2004-07-30
9
5,137 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
  • 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

Suggested Solutions

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:  The Exchange of information …
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…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

773 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