{"id":10086,"date":"2017-04-09T15:21:18","date_gmt":"2017-04-09T07:21:18","guid":{"rendered":"http:\/\/www.vbtutor.net\/?page_id=10086"},"modified":"2018-06-22T14:04:16","modified_gmt":"2018-06-22T06:04:16","slug":"visual-basic-2017-lesson-22-working-radio-buttons","status":"publish","type":"page","link":"https:\/\/www.vbtutor.net\/index.php\/visual-basic-2017-lesson-22-working-radio-buttons\/","title":{"rendered":"Visual Basic 2017 Lesson 22: Working with Radio Buttons"},"content":{"rendered":"<h4 style=\"text-align: center;\"><a href=\"http:\/\/www.vbtutor.net\/index.php\/visual-basic-2017-lesson-21-working-checkboxes\/\">[Lesson 21] <\/a>&lt;&lt; <a href=\"http:\/\/www.vbtutor.net\/index.php\/visual-basic-2017-tutorial\/\">[Contents]<\/a> &gt;&gt; <a href=\"http:\/\/www.vbtutor.net\/index.php\/visual-basic-2017-lesson-23-creating-web-browser\/\">[Lesson 23]<\/a><\/h4>\n<p>We have learned how to use the checkbox control in the previous lesson. In this lesson, we shall learn how to write code for another control in visual basic 2017, the radio button.Though closely related to the checkbox control, the radio buttons operate differently from the checkboxes. The difference is check boxes work independently and\u00a0allow the user to select one or more items, radio buttons only allow the user to select one item out of a number of choices. It means radio buttons are mutually exclusive. Examples of the usage of radio buttons are survey questions related to gender, age, income and more of an individual.<br \/>\n<script async src=\"\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js\"><\/script><br \/>\n<ins class=\"adsbygoogle\" style=\"display: block; text-align: center;\" data-ad-layout=\"in-article\" data-ad-format=\"fluid\" data-ad-client=\"ca-pub-3033628290023372\" data-ad-slot=\"3393818013\"><\/ins><br \/>\n<script>\n     (adsbygoogle = window.adsbygoogle || []).push({});\n<\/script><\/p>\n<h4><strong>Example 22.1<\/strong><\/h4>\n<p>In this example, \u00a0the user can only choose one T-shirt color. To design the interface, add three radio buttons and name them as RadioRed, RadioGreen and RadioYellow respectively. Besides that, add a button to confirm the chosen color and a label control to display the chosen color. Name the button as BtnConfirm and the label as LblDisplay. We use the <strong>If&#8230;Then&#8230;Else<\/strong> decisions making structure to construct the program. The state of the radio button is indicated by its checked property.<\/p>\n<h4>The code<\/h4>\n<pre style=\"font-size: 100%;\">Private Sub BtnConfirm_Click(sender As Object, e As EventArgs) Handles BtnConfirm.Click\r\nDim Tcolor As String\r\nIf RadioRed.Checked \u00a0Then\r\nTcolor = \"Red Color\"\r\nLblDisplay.ForeColor = Color.Red\r\nElseIf RadioGreen.Checked \u00a0Then\r\nTcolor = \"Green Color\"\r\nLblDisplay.ForeColor = Color.Green\r\nElse\r\nTcolor = \"Yellow Color\"\r\nLblDisplay.ForeColor = Color.Yellow\r\n\r\nEnd If\r\n\r\nLblDisplay.Text = Tcolor\r\n\r\nEnd Sub\r\n<\/pre>\n<h4>The Runtime Interface<\/h4>\n<p><a href=\"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2014\/01\/vb2013_figure21.1.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4789\" src=\"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2014\/01\/vb2013_figure21.1.jpg\" alt=\"vb2013_figure21.1\" width=\"300\" height=\"300\" \/><\/a><\/p>\n<p style=\"text-align: center;\">\u00a0<strong>Figure 22.1<\/strong><\/p>\n<p><script async src=\"\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js\"><\/script><br \/>\n<ins class=\"adsbygoogle\" style=\"display: block; text-align: center;\" data-ad-layout=\"in-article\" data-ad-format=\"fluid\" data-ad-client=\"ca-pub-3033628290023372\" data-ad-slot=\"3393818013\"><\/ins><br \/>\n<script>\n     (adsbygoogle = window.adsbygoogle || []).push({});\n<\/script><br \/>\n(adsbygoogle = window.adsbygoogle || []).push({});<\/p>\n<h4 style=\"text-align: left;\"><strong>Example 22.2<\/strong><\/h4>\n<p>Although the user may only select one item at a time, he may make more than one selection if those items belong to different categories. For example, the user wishes to choose T-shirt size and color, he needs to select one color and one size, which means one selection in each category. In this case, we need to group the radio buttons together according to the categories. This is easily achieved in Visual Basic 2017 using the Groupbox control under the containers categories.<\/p>\n<p>In the Visual Basic 2017 IDE, after inserting the Groupbox from the tool box into the form, you can proceed to insert the radio buttons into the Groupbox. Only the radio buttons inside the Groupbox are mutually exclusive, they are not mutually exclusive with the radio buttons outside the Groupbox. In this example, the user can select one color and one size of the T-shirt. To design the interface, insert two group boxes. In the first group box, add four radio buttons and name them as RadioXL, RadioL, RadioM and Radio S respectively. In the second group box, add three radio buttons and name them RadioRed, RadioBlue and RadioBeige respectively. Besides that, insert two label control to display the chosen size and color, name them LblSize and LblColor respectively. Finally, add a button and name it as BtnConfirm. In the\u00a0Visual Basic 2017\u00a0code, we shall declare two variables, TSize to indicate the T-shirt size and TColor to indicate the T-shirt color.<\/p>\n<h4><strong>The Code<\/strong><\/h4>\n<pre style=\"font-size: 100%;\">Private Sub BtnConfirm_Click(sender As Object, e As EventArgs) Handles BtnConfirm.Click\r\nDim TSize, TColor As String\r\n\r\nIf RadioXL.Checked Then\r\nTSize = \"XL\"\r\nElseIf RadioL.Checked Then\r\nTSize = \"L\"\r\nElseIf RadioM.Checked Then\r\nTSize = \"M\"\r\nElse : TSize = \"S\"\r\n\r\nEnd If\r\nIf RadioRed.Checked Then\r\nTColor = \"Red\"\r\nElseIf RadioBlue.Checked Then\r\nTColor = \"Blue\"\r\nElse : TColor = \"Beige\"\r\nEnd If\r\nLblSize.Text = TSize\r\nLblcolor.Text = TColor\r\nEnd Sub\r\n<\/pre>\n<h4>The Runtime Interface<\/h4>\n<p style=\"text-align: center;\"><a href=\"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2014\/01\/vb2013_figure21.2.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4798\" src=\"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2014\/01\/vb2013_figure21.2.jpg\" alt=\"vb2013_figure21.2\" width=\"313\" height=\"341\" \/><\/a><strong>Figure 22.2<\/strong><\/p>\n<p><script async src=\"\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js\"><\/script><br \/>\n<ins class=\"adsbygoogle\" style=\"display: block;\" data-ad-format=\"autorelaxed\" data-ad-client=\"ca-pub-3033628290023372\" data-ad-slot=\"9961025909\"><\/ins><br \/>\n<script>\n     (adsbygoogle = window.adsbygoogle || []).push({});\n<\/script><\/p>\n<h4 style=\"text-align: center;\"><a href=\"http:\/\/www.vbtutor.net\/index.php\/visual-basic-2015-lesson-21-working-with-checkboxes\/\">[Lesson 21]\u00a0<\/a>&lt;&lt;\u00a0<a href=\"http:\/\/www.vbtutor.net\/index.php\/visual-basic-2015-tutorial\/\">[Contents]<\/a>\u00a0&gt;&gt; <a href=\"http:\/\/www.vbtutor.net\/index.php\/visual-basic-2017-lesson-23-creating-web-browser\/\">[Lesson 23]<\/a><\/h4>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>[Lesson 21] &lt;&lt; [Contents] &gt;&gt; [Lesson 23] We have learned how to use the checkbox control in the previous lesson. In this lesson, we shall learn how to write code for another control in visual basic 2017, the radio button.Though closely related to the checkbox control, the radio buttons operate differently from the checkboxes. The &hellip; <a href=\"https:\/\/www.vbtutor.net\/index.php\/visual-basic-2017-lesson-22-working-radio-buttons\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Visual Basic 2017 Lesson 22: Working with Radio Buttons<\/span><\/a><\/p>\n","protected":false},"author":23013,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-10086","page","type-page","status-publish","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.0 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Visual Basic 2017 Lesson 22: Working with Radio Buttons - Learn Visual Basic Programming \u2013 VB.NET, VBA &amp; Classic VB<\/title>\n<meta name=\"description\" content=\"Learn how to work with radio buttons in visual basic 2017\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"http:\/\/www.vbtutor.net\/vb2017\/vb2017_lesson22.html\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Visual Basic 2017 Lesson 22: Working with Radio Buttons - Learn Visual Basic Programming \u2013 VB.NET, VBA &amp; Classic VB\" \/>\n<meta property=\"og:description\" content=\"Learn how to work with radio buttons in visual basic 2017\" \/>\n<meta property=\"og:url\" content=\"http:\/\/www.vbtutor.net\/vb2017\/vb2017_lesson22.html\" \/>\n<meta property=\"og:site_name\" content=\"Learn Visual Basic Programming \u2013 VB.NET, VBA &amp; Classic VB\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/Vbtutor\" \/>\n<meta property=\"article:modified_time\" content=\"2018-06-22T06:04:16+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2014\/01\/vb2013_figure21.1.jpg\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:site\" content=\"@liewvk\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.vbtutor.net\/index.php\/visual-basic-2017-lesson-22-working-radio-buttons\/\",\"url\":\"http:\/\/www.vbtutor.net\/vb2017\/vb2017_lesson22.html\",\"name\":\"Visual Basic 2017 Lesson 22: Working with Radio Buttons - Learn Visual Basic Programming \u2013 VB.NET, VBA &amp; Classic VB\",\"isPartOf\":{\"@id\":\"https:\/\/www.vbtutor.net\/#website\"},\"primaryImageOfPage\":{\"@id\":\"http:\/\/www.vbtutor.net\/vb2017\/vb2017_lesson22.html#primaryimage\"},\"image\":{\"@id\":\"http:\/\/www.vbtutor.net\/vb2017\/vb2017_lesson22.html#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2014\/01\/vb2013_figure21.1.jpg\",\"datePublished\":\"2017-04-09T07:21:18+00:00\",\"dateModified\":\"2018-06-22T06:04:16+00:00\",\"description\":\"Learn how to work with radio buttons in visual basic 2017\",\"breadcrumb\":{\"@id\":\"http:\/\/www.vbtutor.net\/vb2017\/vb2017_lesson22.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"http:\/\/www.vbtutor.net\/vb2017\/vb2017_lesson22.html\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/www.vbtutor.net\/vb2017\/vb2017_lesson22.html#primaryimage\",\"url\":\"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2014\/01\/vb2013_figure21.1.jpg\",\"contentUrl\":\"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2014\/01\/vb2013_figure21.1.jpg\",\"width\":300,\"height\":300},{\"@type\":\"BreadcrumbList\",\"@id\":\"http:\/\/www.vbtutor.net\/vb2017\/vb2017_lesson22.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.vbtutor.net\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Visual Basic 2017 Lesson 22: Working with Radio Buttons\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.vbtutor.net\/#website\",\"url\":\"https:\/\/www.vbtutor.net\/\",\"name\":\"Learn Visual Basic Programming \u2013 VB.NET, VBA &amp; Classic VB\",\"description\":\"Start learning Visual Basic from beginner to advanced. Includes VB.NET, VBA, and classic VB tutorials for students and professionals.\",\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Visual Basic 2017 Lesson 22: Working with Radio Buttons - Learn Visual Basic Programming \u2013 VB.NET, VBA &amp; Classic VB","description":"Learn how to work with radio buttons in visual basic 2017","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"http:\/\/www.vbtutor.net\/vb2017\/vb2017_lesson22.html","og_locale":"en_US","og_type":"article","og_title":"Visual Basic 2017 Lesson 22: Working with Radio Buttons - Learn Visual Basic Programming \u2013 VB.NET, VBA &amp; Classic VB","og_description":"Learn how to work with radio buttons in visual basic 2017","og_url":"http:\/\/www.vbtutor.net\/vb2017\/vb2017_lesson22.html","og_site_name":"Learn Visual Basic Programming \u2013 VB.NET, VBA &amp; Classic VB","article_publisher":"https:\/\/www.facebook.com\/Vbtutor","article_modified_time":"2018-06-22T06:04:16+00:00","og_image":[{"url":"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2014\/01\/vb2013_figure21.1.jpg","type":"","width":"","height":""}],"twitter_card":"summary_large_image","twitter_site":"@liewvk","twitter_misc":{"Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.vbtutor.net\/index.php\/visual-basic-2017-lesson-22-working-radio-buttons\/","url":"http:\/\/www.vbtutor.net\/vb2017\/vb2017_lesson22.html","name":"Visual Basic 2017 Lesson 22: Working with Radio Buttons - Learn Visual Basic Programming \u2013 VB.NET, VBA &amp; Classic VB","isPartOf":{"@id":"https:\/\/www.vbtutor.net\/#website"},"primaryImageOfPage":{"@id":"http:\/\/www.vbtutor.net\/vb2017\/vb2017_lesson22.html#primaryimage"},"image":{"@id":"http:\/\/www.vbtutor.net\/vb2017\/vb2017_lesson22.html#primaryimage"},"thumbnailUrl":"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2014\/01\/vb2013_figure21.1.jpg","datePublished":"2017-04-09T07:21:18+00:00","dateModified":"2018-06-22T06:04:16+00:00","description":"Learn how to work with radio buttons in visual basic 2017","breadcrumb":{"@id":"http:\/\/www.vbtutor.net\/vb2017\/vb2017_lesson22.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["http:\/\/www.vbtutor.net\/vb2017\/vb2017_lesson22.html"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/www.vbtutor.net\/vb2017\/vb2017_lesson22.html#primaryimage","url":"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2014\/01\/vb2013_figure21.1.jpg","contentUrl":"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2014\/01\/vb2013_figure21.1.jpg","width":300,"height":300},{"@type":"BreadcrumbList","@id":"http:\/\/www.vbtutor.net\/vb2017\/vb2017_lesson22.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.vbtutor.net\/"},{"@type":"ListItem","position":2,"name":"Visual Basic 2017 Lesson 22: Working with Radio Buttons"}]},{"@type":"WebSite","@id":"https:\/\/www.vbtutor.net\/#website","url":"https:\/\/www.vbtutor.net\/","name":"Learn Visual Basic Programming \u2013 VB.NET, VBA &amp; Classic VB","description":"Start learning Visual Basic from beginner to advanced. Includes VB.NET, VBA, and classic VB tutorials for students and professionals.","inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/pages\/10086","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/users\/23013"}],"replies":[{"embeddable":true,"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/comments?post=10086"}],"version-history":[{"count":18,"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/pages\/10086\/revisions"}],"predecessor-version":[{"id":12997,"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/pages\/10086\/revisions\/12997"}],"wp:attachment":[{"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/media?parent=10086"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/categories?post=10086"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/tags?post=10086"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}