Search code examples
vb.netfor-loopint32

How to use a for loop with an integer


I'm trying to add an option to do something a set amount of times, but I couldn't get an int32 to work with it. I'm using

dim Int As Int32() For i = 0 To Int 'code Next i

Any help is appreciated. Thanks.


Solution

  • Besides being poorly named, with the parenthesis after Int32() you're actually declaring an Array of Int32. You probably just wanted a single Int32, in which case you should get rid of the parenthesis and also give it a value:

        Dim NumberOfTimes As Int32 = 3
        For i As Int32 = 1 To NumberOfTimes
            MessageBox.Show("Hello " & i.ToString)
        Next i