I'm hoping I could maybe get some help with this small problem. Basically I'm trying to access the elements of a string array in vb.net using a negative number.
Here is the problematic piece of code:
If p < filestring.Length Then
c = (c << 8) Or Asc(filestring(p))
p += 1
Dim m = (c >> 3) And 2047
Dim n = (c And 7) + 3
If (m > n) Then
o += o(-m)
o += o(n - m)
Else
For value = 0 To n
o += o(m)
Next
End If
I get an index out of range exception when I try to use -m to access an array element. -m is always negative and always smaller than the size of the string array yet I still get that error. Does anyone have any suggestions on how to work around this please?
I should have added that I'm trying to port python code to vb.net so the original python version of the above would look like this:
if p < len(i):
c = (c << 8) | ord(i[p])
p += 1
m = (c >> 3) & 0x07ff
n = (c & 7) + 3
if (m > n):
o += o[-m:n-m]
else:
for _ in xrange(n):
o += o[-m]
I hope this maybe sheds some more light on the problem and apologise for not posting it the first time around.