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
Solved

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

Posted on 2004-07-30
9
5,173 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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
API works for 1 result, need to make it many 30 92
is this a cms? 8 65
Adjust an existing ASP Query 45 15
Set time on Session (ASP) 14 21
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…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

789 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