Solved

Val in ASP

Posted on 2003-12-01
5
5,507 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

Industry Leaders: 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

Suggested Solutions

Title # Comments Views Activity
Cannot open file from ASP if user is "logged in" 13 40
Obtain data from database .mdb 4 35
Extracting nodes  using classical ASP 3 41
Add Rows on a Table 8 54
I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
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…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

751 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