What happened to array management

A few years ago, I used Visual Basic 6 , I was able to create objects with the same name, and then distinguish them by index. for example, we can create TextBox1 and another TextBox1 , but with a different index. Now this feature is no longer available! I am currently using Visual Studio 2012 . Do I need to manipulate VS2012 in order to enable this function again or something similar to it, because it was really useful.

+4
source share
2 answers

An easier way to do this today is to place all of these controls in a common parent control. This parent can be a group box, panel, or even the form itself.

So, if, say, all the checkboxes in your form need to be indexed, without any exceptions, you don’t need to do anything special. If only one flag is different, you need this flag to have a different parent control than the indexed flags. In this case, you can fold the control panel under a group of flags, or you can fold the control panel under a single flag, which is different. Will work.

Later, you still won’t be able to access these checkboxes by index, but you can view them as a collection. Here's how you can do it:

 For Each box As CheckBox In Me.Controls.OfType(Of Checkbox)() 'Do something with each checkbox Next 

Or, if you want to know which ones are marked:

 Dim checkedBoxes As IEnumerable(Of Checkbox) = Me.Controls.OfType(Of Checkbox)().Where(Function(b) b.Checked) 

If you really need an array of flags, you can use this method to get it. Just enter code like this into the form load event:

 Dim checkBoxes() CheckBox = Me.Controls.OfType(Of CheckBox)().OrderBy(Function(b) b.Name).ToArray() 
+4
source

Now it hurts terribly.

MSDN covers this topic now: http://msdn.microsoft.com/en-us/library/aa289500%28v=vs.71%29.aspx

Long live the VB6!

+3
source

Source: https://habr.com/ru/post/1502454/


All Articles