Jump to content

Convert Delphi Code to VB (ASP)


Recommended Posts

I am a VB programmer and I have been given some code that is written in Delphi that I need to use on an ASP website so I need to re-write it as VB.

Does anyone know how the following code should be written in VB?

iPrevDigit := 17;

sUnlock := '';

for iCount := length(sSerialNo) downto 1 do begin

sUnlock := chr(ord(sSerialNo[iCount]) + iPrevDigit) + sUnlock;

iPrevDigit := StrToInt(sSerialNo[iCount]) + 17 + trunc(iCount/2);

end;

Link to comment
Share on other sites


Looks like a serial-checking algorithm to me... a somewhat familiar one too, the "+ 17 + trunc(iCount/2);" reminded me of it.

If you specify what sSerialNo is an array of, as well as the types of the other variables, I think it's possible to simplify the resulting code significantly.

Link to comment
Share on other sites

I am a VB programmer and I have been given some code that is written in Delphi that I need to use on an ASP website so I need to re-write it as VB.

Does anyone know how the following code should be written in VB?

iPrevDigit := 17;

sUnlock := '';

for iCount := length(sSerialNo) downto 1 do begin

sUnlock := chr(ord(sSerialNo[iCount]) + iPrevDigit) + sUnlock;

iPrevDigit := StrToInt(sSerialNo[iCount]) + 17 + trunc(iCount/2);

end;

For VB6 I think it should look like this...

Option Base 1 'Not sure but...

Dim iPrevDigit As Long
Dim iCount As Long
Dim sUnlock As String
Dim sSerialNo() As String

...
...
...

iPrevDigit = 17
sUnlock = ""

For iCount = UBound(sSerialNo) To 1 Step-1

sUnlock = CStr(CInt(sSerialNo(iCount)) + iPrevDigit) & sUnlock
iPrevDigit = CLng(sSerialNo(iCount)) + 17 + Int(iCount / 2)

Next iCount

...
...
...

I don't know Delphi or very few, so I can be wrong.

Edited by jdoe
Link to comment
Share on other sites

First I get the error;

Microsoft VBScript compilation error '800a0401'

Expected end of statement

/testdelphi.asp, line 27

Next iCount

-----^

So I took the iCount off the end and now I get this error;

Microsoft VBScript runtime error '800a000d'

Type mismatch: 'UBound'

/testdelphi.asp, line 22

This is being run in a subroutine in an asp website.

Link to comment
Share on other sites

Ok i have narrowed it down to these 2 lines of code that are crashing the page;

sUnlock = CStr(CInt(sSerialNo(i)) + iPrevDigit) & sUnlock

iPrevDigit = CLng(sSerialNo(i)) + 17 + Int(iCount / 2)

All i know is they are supposed to return and unlock number based on the Serial Number submited.

HELP!

Anyone know why this would crash the page?

Link to comment
Share on other sites

VBScript is NOT VB.

Also, are you running this in a clientside script? If so... I don't think that's much of a "protection"... :P

You still haven't specified the data type of sUnlock... but from what I can see, it's taking each digit of the serial nunber, adding the previous 'accumulation', then adding a previous sUnlock... ? Then it updates the accumulation with the serial # + 17 and its index, but this goes against what the serial number array type was, as in previous line serial array is an array of integer but is now number in ASCII chars?

(why does this code look SO familiar, especially the constant 17? :lol:)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...