Array controls exactly as we had them with VB6 at design time are unavailable in VB.Net. There are however a number of ways to do the same task.
The first is to add more controls to the handles statement of the procedure. My Calculator solution uses this technique. The second method of simulating Array Controls is using the Index number for each control that VB.Net sets in a project. In the Flippin project I use the method used in the calculator as well as setting properties of labels via their Control Index number.
The Mine Scout game takes Array controls further by programmatically creating labels and reading and changing their properties via their Control Index number only. It also has a recursive procedure that calls itself. This tremendously reduced the amount of code.
|
After much research I've found the way to in effect create a Control Array at design time the same as per VB6.
It is possible to manipulate Array Controls via their quasi Index number such as ("NameOfControl" & Index).Text = "Hello" and to loop through the Control Array via the Index number. The difference is that the index number is embedded in the control name such as Label23. This results in the code ("Label" & 23).Text = "Hello". I've used this technique in the Slot Machine project. :) |
Here is the quick cute Snake game to code and play. The snake is an array of Labels that grows as it eats food.
Since the Labels are created at Run time I use Snake(i) to loop through the Labels.
The arrow keys change the direction of the slithering snake and the N key starts a new game.
Since the Labels are created at Run time I use Snake(i) to loop through the Labels.
The arrow keys change the direction of the slithering snake and the N key starts a new game.