Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Val in ASP

Posted on 2003-12-01
5
Medium Priority
?
5,748 Views
Last Modified: 2009-05-12
I am trying to convert some of the ActiveLock Visual Basic code to classic ASP (not ASP.NET). The SHA1 hashing algorithm to be precise. Everything seems fine except the 11 calls to the Val function. In VB this will return the numerical value of a string, up until the first non-space, non-numerical character. You can read the MS description for more detail about Val.
CInt and CLng are not quite the same as Val because I suspect that more than numerical values are included.

If I remove the Val function the script runs fine but does not return the desired result of the hash. Does anyone have a Val alternative in ASP?
0
Comment
Question by:Kitsune
  • 3
  • 2
5 Comments
 
LVL 28

Expert Comment

by:sybe
ID: 9856379
In VBScript there is no Val() function

But there is:
Cint() - returns integer
Clng() - returns long
Csng() - returns single
Cdbl() - returns double
0
 
LVL 28

Accepted Solution

by:
sybe earned 100 total points
ID: 9856413
those conversion functions will give an error is the string can't be converted to a numeric value.

to get the functionality of Val() - return a numeric value from a string until the first non-numeric character, you have to write your own function

Function Val(ByVal s)
    Dim i, sTemp, iTemp
    iTemp = 0
    For i = 0 To Len(s)
        sTemp = Mid(s,1,i)
        If IsNumeric(sTemp) Then
            iTemp = Clng(sTemp)
        Else
            Val = iTemp
            Exit Function
        End If
    Next
End Function
0
 
LVL 1

Author Comment

by:Kitsune
ID: 9865247
sybe

The function you supplied will convert a number and stop when it reaches a non-numerical number but it does not replicate the Val function. The Val function ignores spaces and handles hexadecimal numbers, etc. The hashing algorithms used in SHA1 must match the exact output of Val or the serial numbers generated won't match properly.

I wrote a quick VB program to take a string and compares Val with your function. Also tried it with Clng - which was the same on some occasions but not others. If you supply a string like "&HFF" they both output 255 but if I supply "&HFF23" I get different responses. The MS documentation mentions that Val will return -1 for "&HFFFF" which is true it does, however Clng returns 65535. I can't work out exactly what Val is doing otherwise I would write the function myself.

This can't be hard and I'm sure someone must know.
0
 
LVL 28

Expert Comment

by:sybe
ID: 9865290
Hmm, i am not sure that it isn't that hard.
I am thinking of some maybe workable work-around. MS Acces knows the VAL function. What you could do is use an Access database. If you put "SELECT VAL('134xyt')" in an Access query, you get what you want.
0
 
LVL 1

Author Comment

by:Kitsune
ID: 9872974
Thanks for trying sybe. Points are yours.

I think I would prefer a more elegant solution and will most likely add the ActiveLock source code to the source code of my application and modify it so that it does not use Val and I would therefore not have to use Val in my ASP page.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
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/…
Screencast - Getting to Know the Pipeline
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…

772 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