Solved

Val in ASP

Posted on 2003-12-01
5
5,357 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
Comment Utility
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 50 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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 Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:  The Exchange of information …
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…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

771 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

12 Experts available now in Live!

Get 1:1 Help Now