{"id":4771,"date":"2014-03-30T15:17:48","date_gmt":"2014-03-30T15:17:48","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/control-array-vb-net-collection-of-common-programming-errors\/"},"modified":"2014-03-30T15:17:48","modified_gmt":"2014-03-30T15:17:48","slug":"control-array-vb-net-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/control-array-vb-net-collection-of-common-programming-errors\/","title":{"rendered":"control array vb.net-Collection of common programming errors"},"content":{"rendered":"<p>VB.NET does not support control arrays, in the same sense as VB6. You can do similar things, though. For instance, if you want to handle events from multiple controls with the same method, you can do so like this:<\/p>\n<pre><code>Private Sub MyClickHandler(sender As Object, e As EventArgs) Handles _\n    Button1.Click, _\n    Button2.Click, _\n    Button3.Click\n\n    Dim buttonThatWasClicked As Button = CType(sender, Button)\n    ' Do something...\nEnd Sub\n<\/code><\/pre>\n<p>If you want to create an array of controls that you can loop through, you can do that to, like this:<\/p>\n<pre><code>Dim myTextBoxes() As TextBox = New TextBox() { TextBox1, TextBox2, TextBox3 }\nFor i As Integer = 0 to myTextBoxes.Length - 1\n    myTextBoxes(i).Text = ...\nNext\n<\/code><\/pre>\n<p>Alternatively, if you name your controls consistently, you can find them by name in your form&#8217;s <code>Controls<\/code> collection. For instance, if you had three text boxes named <code>TextBox1<\/code>, <code>TextBox2<\/code>, and <code>TextBox3<\/code>, you could loop through them like this:<\/p>\n<pre><code>For i As Integer = 1 to 3\n    Dim t As TextBox = CType(Me.Controls(\"TextBox\" &amp; i.ToString()), TextBox)\n    t.Text = ...\nNext\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>VB.NET does not support control arrays, in the same sense as VB6. You can do similar things, though. For instance, if you want to handle events from multiple controls with the same method, you can do so like this: Private Sub MyClickHandler(sender As Object, e As EventArgs) Handles _ Button1.Click, _ Button2.Click, _ Button3.Click Dim [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-4771","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/4771","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=4771"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/4771\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=4771"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=4771"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=4771"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}