Reputation: 13
This probably will seem like a simple process, but I'm new to programming, so I don't know how to do it.
I'm programming in VB.Net and I want the computer to generate a new set of global variables every time the user presses Button X. Naturally we don't know how many times the button will be pressed, which is why I need the computer to create the variables. Also, how do I tell the computer to assign a new number to each variable? For example:
ButtonX clicked first time: NewVariable1 created
ButtonX clicked a second time: NewVariable2 created.
I hope this makes sense. I can provide more details if necessary. I need the variables generated to be accessible from many different classes, and maybe even from one load to the next, if possible.
Upvotes: 0
Views: 57
Reputation: 22456
Have a look at the List(Of T) class. Create a list that is globally accessible and add another value each time the button is pressed.
globaList.Add(newValue)
This assumes that all the variables are of the same type.
Later on, you can access the list items (=variables) by their index. This retrieves the value that was added last:
Dim value = globalList(globalList.Count - 1)
You can also change values in the list:
globalList(index) = newValue
Upvotes: 1