Solved

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

Posted on 2004-07-30
9
5,041 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
 
LVL 7

Accepted Solution

by:
j2nku earned 150 total points
ID: 11675348
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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 …
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

760 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now