Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Val in ASP

Posted on 2003-12-01
5
Medium Priority
?
5,666 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 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

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…
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…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

664 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