MartinaL Posted September 7, 2006 Posted September 7, 2006 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;
LLXX Posted September 7, 2006 Posted September 7, 2006 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.
MartinaL Posted September 13, 2006 Author Posted September 13, 2006 So how would I write that in vb???
jdoe Posted September 13, 2006 Posted September 13, 2006 (edited) 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 LongDim iCount As LongDim sUnlock As StringDim sSerialNo() As String.........iPrevDigit = 17sUnlock = ""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 September 13, 2006 by jdoe
MartinaL Posted September 13, 2006 Author Posted September 13, 2006 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.
MartinaL Posted September 13, 2006 Author Posted September 13, 2006 Ok i have narrowed it down to these 2 lines of code that are crashing the page;sUnlock = CStr(CInt(sSerialNo(i)) + iPrevDigit) & sUnlockiPrevDigit = 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?
LLXX Posted September 13, 2006 Posted September 13, 2006 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"... 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? )
CoffeeFiend Posted September 13, 2006 Posted September 13, 2006 (edited) . Edited November 7, 2006 by crahak
MartinaL Posted September 13, 2006 Author Posted September 13, 2006 Thanks The only reason it is written in ASP is because it is a pre-existing website, it is definity not by choice!
CoffeeFiend Posted September 14, 2006 Posted September 14, 2006 (edited) . Edited November 7, 2006 by crahak
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now