\r\n\r\n
Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > General > Simplifying... (Arrays and Mod help)


\r\n \r\n
 
 
Thread Tools Display Modes

\r\n\r\n\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:
\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 [vb] and [/vb] tags make the world go \'round\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 Reply With Quote\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\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\r\n\r\n'; pd[617277] = '\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 \r\n\r\n\r\n\r\n \r\n
\r\n
\r\n  \r\n #2  \r\n \r\n \r\n \r\n \r\n \r\n
\r\n\r\n
\r\n \r\n Old\r\n \r\n 01-16-2004, 10:30 PM\r\n \r\n \r\n \r\n
\r\n
\r\n \r\n \r\n \r\n \r\n \r\n
passel\'s Avatar\r\n\r\n
\r\n \r\n passel\r\n passel is offline\r\n\r\n\r\n
Prev Previous Post   Next Post Next
  #1  
Old 01-16-2004, 10:08 PM
spamonkey8's Avatar
spamonkey8 spamonkey8 is offline
Junior Contributor
 
Join Date: Apr 2003
Location: Between Your Ears
Posts: 337
Default Simplifying... (Arrays and Mod help)


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
Reply With Quote
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
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
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->