I have a little bit of code that I\'d like to simplify in a project about permutations. It\'s a loop that, i\'m sure, can be replaced by just the right Mod statement. There are two arrays, one large and one much smaller. What the loop does is for every byte in the larger array, the smaller is incremented one. When the position reaches the upper boundary of the smaller array, it goes back to zero. This is it: \r\n
\r\n
Code:
\r\n
For i = 1 To UBound(bytLarge())\r\n If lPosition = UBound(bytSmall()) Then\r\n lPosition = 0\r\n Else\r\n lPosition = lPosition + 1\r\n End If\r\nNext\r\n\'I messed around with it and I found a statement that worked for many\r\n\'array dimensions, but it fails for some values, such as if the upper\r\n\'bounds are 41 and 5 for bytLarge and bytSmall, respectively\r\nlPosition = ((UBound(bytLarge()) + 1) Mod (UBound(bytSmall()) + 1)) - 1
\r\n
\r\nThanks everybody
\r\n \r\n\r\n
\r\n
\r\n
\r\n \r\n\r\n \r\n \r\n\r\n \r\n \r\n
\r\n __________________ \r\n [vb] and [/vb] tags make the world go \'round\r\n
I have a little bit of code that I'd like to simplify in a project about permutations. It's a loop that, i'm sure, can be replaced by just the right Mod statement. There are two arrays, one large and one much smaller. What the loop does is for every byte in the larger array, the smaller is incremented one. When the position reaches the upper boundary of the smaller array, it goes back to zero. This is it:
Code:
For i = 1 To UBound(bytLarge())
If lPosition = UBound(bytSmall()) Then
lPosition = 0
Else
lPosition = lPosition + 1
End If
Next
'I messed around with it and I found a statement that worked for many
'array dimensions, but it fails for some values, such as if the upper
'bounds are 41 and 5 for bytLarge and bytSmall, respectively
lPosition = ((UBound(bytLarge()) + 1) Mod (UBound(bytSmall()) + 1)) - 1
Thanks everybody
__________________
[vb] and [/vb] tags make the world go 'round
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET. subscribe