{"id":327,"date":"2017-07-20T11:28:08","date_gmt":"2017-07-20T15:28:08","guid":{"rendered":"http:\/\/techref.camellarry.com\/?p=327"},"modified":"2017-07-20T11:30:40","modified_gmt":"2017-07-20T15:30:40","slug":"read-values-from-listbox-and-reference-a-2-dimensional-array","status":"publish","type":"post","link":"http:\/\/techref.camellarry.com\/?p=327","title":{"rendered":"Read Values From ListBox and Reference a 2-Dimensional Array"},"content":{"rendered":"<p>This example shows how to read entries from a ListBox and reference an array which contains numeric values corresponding to the selection. \u00a0This is useful if you want to do logic AND statements with the selection from the ListBox.<\/p>\n<p>I used this method to assign numeric tags to the ListBox items. \u00a0This allowed me to assign a unique value to each combination of selections made.<\/p>\n<pre>Public Class Form1\r\n Dim arrTag(2, 5) As String, arrTagMax As Integer\r\n\r\n<strong>Private Sub Form1_Load<\/strong>(sender As System.Object, e As System.EventArgs) Handles MyBase.Load\r\n LoadArray()\r\n<strong> End Sub<\/strong>\r\n\r\n<strong>Private Sub ListBox1_SelectedIndexChanged<\/strong>(sender As System.Object, e As System.EventArgs) Handles lstACLGroups.SelectedIndexChanged\r\n Dim txt As String = \"\"\r\n Dim acc As Integer = 0\r\n\r\nFor i = 0 To lstACLGroups.SelectedItems.Count - 1\r\n txt += lstACLGroups.SelectedItems(i).ToString &amp; vbCrLf\r\n\r\nFor j = 1 To 5\r\n If lstACLGroups.SelectedItems(i).ToString = arrTag(2, j) Then\r\n acc = acc + CInt(arrTag(1, j))\r\n End If\r\n Next\r\n Next\r\n\r\n TextBox1.Text = txt\r\n TextBox2.Text = acc.ToString\r\n<strong> End Sub<\/strong>\r\n\r\n<strong>Sub LoadArray()<\/strong>\r\n Dim i As Integer\r\n\r\narrTag(1, 1) = 1\r\narrTag(2, 1) = \"1 apple\"\r\n\r\narrTag(1, 2) = 2\r\narrTag(2, 2) = \"2 banana\"\r\n\r\narrTag(1, 3) = 4\r\narrTag(2, 3) = \"4 coconut\"\r\n\r\narrTag(1, 4) = 8\r\narrTag(2, 4) = \"8 dog\"\r\n\r\narrTag(1, 5) = 16\r\narrTag(2, 5) = \"16 elephant\"\r\n\r\nlstACLGroups.Items.Clear()\r\n For i = 1 To 5\r\n   lstACLGroups.Items.Add(arrTag(2, i))\r\n Next\r\n\r\n<strong>End Sub<\/strong>\r\nEnd Class<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>This example shows how to read entries from a ListBox and reference an array which contains numeric values corresponding to the selection. \u00a0This is useful if you want to do logic AND statements with the selection from the ListBox. I used this method to assign numeric tags to the ListBox items. \u00a0This allowed me to [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[9],"tags":[99,29,100,72,77,78],"class_list":["post-327","post","type-post","status-publish","format-standard","hentry","category-vb-net","tag-array","tag-example","tag-listbox","tag-syntax","tag-vb-net","tag-visualbasic"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p9t3oE-5h","_links":{"self":[{"href":"http:\/\/techref.camellarry.com\/index.php?rest_route=\/wp\/v2\/posts\/327","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/techref.camellarry.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/techref.camellarry.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/techref.camellarry.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/techref.camellarry.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=327"}],"version-history":[{"count":4,"href":"http:\/\/techref.camellarry.com\/index.php?rest_route=\/wp\/v2\/posts\/327\/revisions"}],"predecessor-version":[{"id":331,"href":"http:\/\/techref.camellarry.com\/index.php?rest_route=\/wp\/v2\/posts\/327\/revisions\/331"}],"wp:attachment":[{"href":"http:\/\/techref.camellarry.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=327"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/techref.camellarry.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=327"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/techref.camellarry.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=327"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}