{"id":4786,"date":"2014-01-25T07:11:21","date_gmt":"2014-01-24T23:11:21","guid":{"rendered":"http:\/\/www.vbtutor.net\/?page_id=4786"},"modified":"2018-06-24T16:53:35","modified_gmt":"2018-06-24T08:53:35","slug":"visual-basic-2013-lesson-21-using-radio-button","status":"publish","type":"page","link":"https:\/\/www.vbtutor.net\/index.php\/visual-basic-2013-lesson-21-using-radio-button\/","title":{"rendered":"Visual Basic 2013 Lesson 21: Using Radio Button"},"content":{"rendered":"<h4 style=\"text-align: center;\"><a href=\"http:\/\/www.vbtutor.net\/index.php\/visual-basic-2013-lesson-20-using-check-box\/\">[Lesson 20] <\/a>&lt;&lt; <a href=\"http:\/\/www.vbtutor.net\/index.php\/visual-basic-2013-tutorial\/\">[Contents]<\/a> &gt;&gt; <a href=\"http:\/\/www.vbtutor.net\/index.php\/visual-basic-2013-lesson-22-errors-handling\/\">[Lesson 22]<\/a><\/h4>\n<p>In Visual Basic 2013, the radio buttons operate differently from the checkboxes. While the checkboxes work independently and allow the user to select one or more items, the radio buttons are mutually exclusive. It means that the user can only choose one item only out of a number of choices from the radio buttons.<\/p>\n<h4>Example 21.1<\/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. Now, name the button as BtnConfirm and the label as LblDisplay. Furthermore, we use the If&#8230;Then&#8230;Else decision-making structure to construct the program. In addition, the state of the radio button is indicated by its checked property.<\/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=\"3914691604\"><\/ins><br \/>\n<script>\n     (adsbygoogle = window.adsbygoogle || []).push({});\n<\/script><\/p>\n<h4>The code:<\/h4>\n<pre style=\"font-size: 110%;\">Private Sub BtnConfirm_Click(sender As Object, e As EventArgs) Handles BtnConfirm.Click\r\nDim Tcolor As String\r\n If RadioRed.Checked \u00a0Then\r\n  Tcolor = \"Red Color\"\r\n  LblDisplay.ForeColor = Color.Red\r\n ElseIf RadioGreen.Checked \u00a0Then\r\n  Tcolor = \"Green Color\"\r\n  LblDisplay.ForeColor = Color.Green\r\n Else\r\n  Tcolor = \"Yellow Color\"\r\n  LblDisplay.ForeColor = Color.Yellow\r\n End If\r\n LblDisplay.Text = Tcolor\r\nEnd Sub\r\n<\/pre>\n<p>The Runtime Interface<br \/>\n<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 21.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=\"3914691604\"><\/ins><br \/>\n<script>\n     (adsbygoogle = window.adsbygoogle || []).push({});\n<\/script><\/p>\n<h4 style=\"text-align: left;\"><strong>Example 21.2<\/strong><\/h4>\n<p>Although the user may only select one item at a time, he might want to make more than one selection from different categories. For example, the user wishes to choose the T-shirt size and color, he might want to choose 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 2013 using the Groupbox control under the containers categories.In the Visual Basic 2013 IDE, after inserting the Groupbox from the toolbox 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.<\/p>\n<p>To design the interface, you need to insert two group boxes. In the first group box, add four radio buttons and name them as RadioXL, RadioL, RadioM and RadioS 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 code, we shall declare two variables, TSize to indicate the T-shirt size and TColor to indicate the T-shirt color.<\/p>\n<p><strong>The Code<\/strong><\/p>\n<pre style=\"font-size: 110%;\">Private Sub BtnConfirm_Click(sender As Object, e As EventArgs) Handles BtnConfirm.Click\r\nDim TSize, TColor As String\r\n If RadioXL.Checked Then\r\n  TSize = \"XL\"\r\n ElseIf RadioL.Checked Then\r\n  TSize = \"L\"\r\n ElseIf RadioM.Checked Then\r\n  TSize = \"M\"\r\n Else : TSize = \"S\"\r\n End If\r\n If RadioRed.Checked Then\r\n  TColor = \"Red\"\r\n ElseIf RadioBlue.Checked Then\r\n  TColor = \"Blue\"\r\n Else : TColor = \"Beige\"\r\n End If\r\n  LblSize.Text = TSize\r\n  Lblcolor.Text = TColor\r\nEnd Sub\r\n<\/pre>\n<p>The Runtime Interface<\/p>\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 21.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=\"3644929102\"><\/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-2013-lesson-20-using-check-box\/\">[Lesson 20]\u00a0<\/a>&lt;&lt;\u00a0<a href=\"http:\/\/www.vbtutor.net\/index.php\/visual-basic-2013-tutorial\/\">[Contents]<\/a>\u00a0&gt;&gt; <a href=\"http:\/\/www.vbtutor.net\/index.php\/visual-basic-2013-lesson-22-errors-handling\/\">[Lesson 22]<\/a><\/h4>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>[Lesson 20] &lt;&lt; [Contents] &gt;&gt; [Lesson 22] In Visual Basic 2013, the radio buttons operate differently from the checkboxes. While the checkboxes work independently and allow the user to select one or more items, the radio buttons are mutually exclusive. It means that the user can only choose one item only out of a number &hellip; <a href=\"https:\/\/www.vbtutor.net\/index.php\/visual-basic-2013-lesson-21-using-radio-button\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Visual Basic 2013 Lesson 21: Using Radio Button<\/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-4786","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 2013 Lesson 21: Using Radio Button - Learn Visual Basic Programming \u2013 VB.NET, VBA &amp; Classic VB<\/title>\n<meta name=\"description\" content=\"This article explains the usage of radio buttons in visual basic 2013\" \/>\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\/vb2013\/vb2013_lesson21.html\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Visual Basic 2013 Lesson 21: Using Radio Button - Learn Visual Basic Programming \u2013 VB.NET, VBA &amp; Classic VB\" \/>\n<meta property=\"og:description\" content=\"This article explains the usage of radio buttons in visual basic 2013\" \/>\n<meta property=\"og:url\" content=\"http:\/\/www.vbtutor.net\/vb2013\/vb2013_lesson21.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-24T08:53:35+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-2013-lesson-21-using-radio-button\/\",\"url\":\"http:\/\/www.vbtutor.net\/vb2013\/vb2013_lesson21.html\",\"name\":\"Visual Basic 2013 Lesson 21: Using Radio Button - Learn Visual Basic Programming \u2013 VB.NET, VBA &amp; Classic VB\",\"isPartOf\":{\"@id\":\"https:\/\/www.vbtutor.net\/#website\"},\"primaryImageOfPage\":{\"@id\":\"http:\/\/www.vbtutor.net\/vb2013\/vb2013_lesson21.html#primaryimage\"},\"image\":{\"@id\":\"http:\/\/www.vbtutor.net\/vb2013\/vb2013_lesson21.html#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2014\/01\/vb2013_figure21.1.jpg\",\"datePublished\":\"2014-01-24T23:11:21+00:00\",\"dateModified\":\"2018-06-24T08:53:35+00:00\",\"description\":\"This article explains the usage of radio buttons in visual basic 2013\",\"breadcrumb\":{\"@id\":\"http:\/\/www.vbtutor.net\/vb2013\/vb2013_lesson21.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"http:\/\/www.vbtutor.net\/vb2013\/vb2013_lesson21.html\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/www.vbtutor.net\/vb2013\/vb2013_lesson21.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\/vb2013\/vb2013_lesson21.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.vbtutor.net\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Visual Basic 2013 Lesson 21: Using Radio Button\"}]},{\"@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 2013 Lesson 21: Using Radio Button - Learn Visual Basic Programming \u2013 VB.NET, VBA &amp; Classic VB","description":"This article explains the usage of radio buttons in visual basic 2013","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\/vb2013\/vb2013_lesson21.html","og_locale":"en_US","og_type":"article","og_title":"Visual Basic 2013 Lesson 21: Using Radio Button - Learn Visual Basic Programming \u2013 VB.NET, VBA &amp; Classic VB","og_description":"This article explains the usage of radio buttons in visual basic 2013","og_url":"http:\/\/www.vbtutor.net\/vb2013\/vb2013_lesson21.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-24T08:53:35+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-2013-lesson-21-using-radio-button\/","url":"http:\/\/www.vbtutor.net\/vb2013\/vb2013_lesson21.html","name":"Visual Basic 2013 Lesson 21: Using Radio Button - Learn Visual Basic Programming \u2013 VB.NET, VBA &amp; Classic VB","isPartOf":{"@id":"https:\/\/www.vbtutor.net\/#website"},"primaryImageOfPage":{"@id":"http:\/\/www.vbtutor.net\/vb2013\/vb2013_lesson21.html#primaryimage"},"image":{"@id":"http:\/\/www.vbtutor.net\/vb2013\/vb2013_lesson21.html#primaryimage"},"thumbnailUrl":"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2014\/01\/vb2013_figure21.1.jpg","datePublished":"2014-01-24T23:11:21+00:00","dateModified":"2018-06-24T08:53:35+00:00","description":"This article explains the usage of radio buttons in visual basic 2013","breadcrumb":{"@id":"http:\/\/www.vbtutor.net\/vb2013\/vb2013_lesson21.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["http:\/\/www.vbtutor.net\/vb2013\/vb2013_lesson21.html"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/www.vbtutor.net\/vb2013\/vb2013_lesson21.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\/vb2013\/vb2013_lesson21.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.vbtutor.net\/"},{"@type":"ListItem","position":2,"name":"Visual Basic 2013 Lesson 21: Using Radio Button"}]},{"@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\/4786","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=4786"}],"version-history":[{"count":39,"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/pages\/4786\/revisions"}],"predecessor-version":[{"id":13075,"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/pages\/4786\/revisions\/13075"}],"wp:attachment":[{"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/media?parent=4786"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/categories?post=4786"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/tags?post=4786"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}