Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 9043
  • Last Modified:

Using CLng gives overflow?

I'm using CLng ie CLng(myval)
but it seems to cause a crash when values are not  between -2147483648 and 2147483647.

Is there any function around I could use?

Should I write my own - if the value is greater than 9 convert it to a CDbl?
Any ideas?
Thanks
AM
0
amoran
Asked:
amoran
1 Solution
 
dr_binksCommented:
im assuming 'myval' is a string?
if so:

if len(myval) > 9 then
     CDbl(myval)
else
    CLng(myval)
end if

hope that helps

~Binks
0
 
svgharmodeCommented:
Dear Friend,

Please try this out............

Cdbl(myval) for converting the large value into number............


Cheers

Sanjeev
0
 
amoranAuthor Commented:
dr_binks

I do this


Function ValidateIntegerLocal(strValue)
      If ContainsInvalidCharacters(strValue,INTEGER_CHARACTER_SET) Then AspError "ValidateIntegerLocal: Invalid characters were found in input parameter ='" & Server.HtmlEncode(strValue) & "'"
      If not IsNumeric(strValue) And Len(strValue) > 0 then AspError "ValidateIntegerLocal: Non numeric characters found in input parameter ='" & Server.HtmlEncode(strValue) & "'"
      If len(strValue) > 20 Then AspError "ValidateIntegerLocal: Length of value in input parameter was too long ='" & Server.HtmlEncode(strValue) & "'"
      If Len(strValue) > 0 then
            If Len(strValue) > 10 Then
                  ValidateIntegerLocal = CDbl(strValue)
            Else
                  ValidateIntegerLocal = CLng(strValue)
            End If      
      Else
            ValidateIntegerLocal = ""
      End if
End Function


but for some reason i'm getting this error?

ValidateIntegerLocal: Non numeric characters found in input parameter ='1'

Thanks
AM
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
danataylorCommented:
Trim strValue to remove any leading/trailing spaces before you do the conversion.
0
 
Vinod_VijayanVinCommented:


   Use     CLng(trim(myval))
0
 
Vinod_VijayanVinCommented:

if that also crashes Use  CDbl(trim(myval))
0
 
svgharmodeCommented:
Dear Friend,

I suggest you a simple thing To use CDBL(strValue)........... :)

    If Len(strValue) > 0 then
          If Len(strValue) > 10 Then
               ValidateIntegerLocal = CDbl(strValue)
          Else
               ValidateIntegerLocal = CLng(strValue)
          End If    
     Else
          ValidateIntegerLocal = ""
     End if

Instead of following This code.............. USE FOLLOWING CODE

    If Len(trim(strValue)) > 0 then
          ValidateIntegerLocal = CDbl(strValue)
     Else
          ValidateIntegerLocal = ""
     End if


No Need to use CLng() function.

Cheers
Sanjeev
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now