locked
Multiple Variable getting created within a loop RRS feed

  • Question

  • User-857155513 posted

    tried to do the following and didnt work.  I am basically trying to create the variable month for the number of times it goes through the loop   Any help would be appreciated.

     

    While loopcnt <= numbermonths

      Dim (“Month “ & loopcnt)  as integer

      Loopcnt += 1

    End while

     

    Tuesday, June 3, 2008 2:48 AM

All replies

  • User746351338 posted

     Hi,

    You cannot create variables in this way. I would rethink your approach and use a dictionary based storage mechanism like an ArrayList, HashTable or SortedList:

    Create: 
    Dim months As New SortedList
    For m As Integer = 1 To 12
    months("Month " & m) = m
    Next
    Iterate:
    For Each entry As DictionaryEntry In months
        Response.Write(entry.Key & " = " & entry.Value & "<br />")
    Next
    Tuesday, June 3, 2008 3:30 AM