Solved

Val in ASP

Posted on 2003-12-01
5
5,488 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 50 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

Independent Software Vendors: 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!

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/…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

749 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