Solved

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

Posted on 2004-07-30
9
5,076 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
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/…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This is a video that shows how the OnPage alerts system integrates into ConnectWise, how a trigger is set, how a page is sent via the trigger, and how the SENT, DELIVERED, READ & REPLIED receipts get entered into the internal tab of the ConnectWise …

919 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

20 Experts available now in Live!

Get 1:1 Help Now