• 0

VB Loops And Arrays


Question

I'm writing a little sub procedure that takes an 2d array, and adds a string to it exactly three times (in a random position). Every time I run this code, I end up with an infinite loop.

Note: The array is dimmed 1 to 5, 1 to 5 (25 total), hence the Random Statements are only from 1 to 5.

<pre>

Sub GenerateArray(ByRef strArray() As String, ByVal strGameType As String)

Dim intCounter As Integer, intRows As Integer, intColumns As Integer, intRandom As Integer

Randomize

intRows = Int((5) * Rnd - 1)

intColumns = Int((5) * Rnd - 1)

intCounter = 0

Do Until intCounter = 3

    If strArray(intRows, intColumns) = "" Then

    strArray(intRows, intColumns) = strGameType

    intCounter = intCounter + 1

    Else

    intCounter = intCounter

    End If

Loop

End Sub

</pre>

Anyone happen to see any errors?

Link to comment
https://www.neowin.net/forum/topic/21211-vb-loops-and-arrays/
Share on other sites

6 answers to this question

Recommended Posts

  • 0

yeah

everything after DO til Loop happens over and over again

so whats before DO doesnt really apply

unless you're applying a setting or something

ex:

Do:

blah = blah + 1

Loop until blah = 3

that would work because blah is w/in the do and loop

make any sense?

but if it were like

blah

Do until blah = 3

yada yada

Loop

its like ok....im doing what until blah = 3

because blah is before the do

lol

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.