Question

I'm using VBScript in ASP on IIS and I cannot seem to get the annoying error to go anyway so this makes debugging so much harder not to mention it does not tell me the exact error except the same error message so I can only assume what's wrong in my code.

My question is: Using the logical operators AND,XOR,NOT,OR in VBScript , is there a limit on the range to what the operands can be? I have implemented a bit shift right function and used the mod operator and I didn't notice until now that my function was causing the error.

My right shift function

function rshift(number,n)

'Shifts a number's bits n bits to the right
for i=1 to n
    if number mod 2 = 0 then
        number = number / 2
    else
        number = (number - 1) / 2
    end if 
next
rshift = number

end function 

'Fails
rshift(1125899906842624,2) 

I think for values larger than 2^32 ( or 31) - 1 that the operators do not work. Tried googling for the range of the operands but couldn't find anything helpful. I saw someone posted a topic about logical operators not working on large values but I can't seem to find that anymore.

Can someone verify this ?

Edit: Found a topic which gives more information on using the mod operator on signed 32 bit integers http://blogs.msdn.com/b/ericlippert/archive/2004/12/01/integer-arithmetic-in-vbscript-part-one.aspx

Was it helpful?

Solution

In VBScript there are several subtypes for integers including integer and long. VBScript will attempt to determine what type of value you are using and use the appropriate subtype.

Integer can store a value between -32,768 to 32,767 and long can store a value between -2,147,483,648 to 2,147,483,647. That value that you are using is greater than this and will result in an overflow.

You can use the VarType function to see what type your number is interpreted as. You may use Double to represent larger values.

This answer looks interesting. Maybe you can use it as part of your function.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top