{"id":7165,"date":"2015-09-05T10:07:30","date_gmt":"2015-09-05T02:07:30","guid":{"rendered":"http:\/\/www.vbtutor.net\/?page_id=7165"},"modified":"2018-06-22T18:13:54","modified_gmt":"2018-06-22T10:13:54","slug":"visual-basic-2015-lesson-21-working-with-checkboxes","status":"publish","type":"page","link":"https:\/\/www.vbtutor.net\/index.php\/visual-basic-2015-lesson-21-working-with-checkboxes\/","title":{"rendered":"Visual Basic 2015 Lesson 21: Working with Check Boxes"},"content":{"rendered":"<h4 style=\"text-align: center;\"><a href=\"http:\/\/www.vbtutor.net\/index.php\/visual-basic-2015-lesson-20-format-functions\/\">[Lesson 20] <\/a>&lt;&lt; <a href=\"http:\/\/www.vbtutor.net\/index.php\/visual-basic-2015-tutorial\/\">[Contents]<\/a> &gt;&gt; <a href=\"http:\/\/www.vbtutor.net\/index.php\/visual-basic-2015-lesson-22-working-radio-buttons\/\">[Lesson 22]<\/a><\/h4>\n<p>In this lesson, we shall learn a how to use the checkbox. The\u00a0Checkbox allows the user to select one or more items by checking the checkbox or checkboxes concerned. For example, in the Font dialog box of any Microsoft Text editor like Microsoft Words, there are many\u00a0checkboxes\u00a0under the Effects section. The user can choose to underline, subscript, small caps, superscript, blink and etc.<\/p>\n<p>In Visual Basic 2015, you can create a shopping cart where the user can click on\u00a0checkboxes\u00a0that correspond to the items they intend to buy, and the total payment can be computed at the same time.<\/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=\"4768455349\"><\/ins><br \/>\n<script>\n     (adsbygoogle = window.adsbygoogle || []).push({});\n<\/script><\/p>\n<h3><strong>Example 21.1: Shopping Cart<\/strong><\/h3>\n<p>In this example, we add a few labels, two buttons, and six checkboxes. We declare the price of each item using the Const keyword. If a checkbox is being ticked, its state is True else its state is False. To calculate the total amount of purchase, we use the mathematical operator +=. For example, sum+=BN is actually sum=sum+BN. Finally, we use the ToString is a Visual Basic 2015 method to display the amount in currency.<\/p>\n<p><strong><span style=\"line-height: 1.714285714; font-size: 1rem;\">The Code<\/span><\/strong><\/p>\n<pre style=\"font-size: 110%;\">Public Class Form1\r\n\r\nPrivate Sub BtnCal_Click(sender As Object, e As EventArgs) Handles BtnCal.Click\r\nConst LX As Integer = 100\r\nConst BN As Integer = 500\r\nConst SD As Integer = 200\r\nConst HD As Integer = 80\r\nConst HM As Integer = 300\r\nConst AM As Integer = 150\r\nDim sum As Integer\r\nIf CheckBox1.Checked = True Then\r\nsum += LX\r\nEnd If\r\n\r\nIf CheckBox2.Checked = True Then\r\nsum += BN\r\nEnd If\r\n\r\nIf CheckBox3.Checked = True Then\r\nsum += SD\r\nEnd If\r\nIf CheckBox4.Checked = True Then\r\nsum += HD\r\nEnd If\r\n\r\nIf CheckBox5.Checked = True Then\r\nsum += HM\r\nEnd If\r\n\r\nIf CheckBox6.Checked = True Then\r\nsum += AM\r\nEnd If\r\nLblTotal.Text = sum.ToString(\"c\")\r\nEnd Sub\r\n\r\nPrivate Sub BtnReset_Click(sender As Object, e As EventArgs) Handles BtnReset.Click\r\nCheckBox1.Checked = False\r\nCheckBox2.Checked = False\r\nCheckBox3.Checked = False\r\nCheckBox4.Checked = False\r\nCheckBox5.Checked = False\r\nCheckBox6.Checked = False\r\n\r\nEnd Sub\r\nEnd Class\r\n<\/pre>\n<p>The Runtime Interface<br \/>\n<a href=\"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2014\/01\/vb2013_figure20.11.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4772\" src=\"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2014\/01\/vb2013_figure20.11.jpg\" alt=\"vb2013_figure20.1\" width=\"553\" height=\"353\" \/><\/a><\/p>\n<h4 style=\"text-align: center;\">\u00a0<strong>Figure 21.1: Shopping Cart<\/strong><\/h4>\n<p>&nbsp;<\/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=\"4768455349\"><\/ins><br \/>\n<script>\n     (adsbygoogle = window.adsbygoogle || []).push({});\n<\/script><\/p>\n<h3><strong>Example 21.2<\/strong><\/h3>\n<pre style=\"font-size: 110%;\">Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click\r\n\r\nConst large As Integer = 10.0\r\nConst medium As Integer = 8\r\nConst small As Integer = 5\r\nDim sum As Integer\r\n\r\nIf CheckBox1.Checked = True Then\r\nsum += large\r\nEnd If\r\n\r\nIf CheckBox2.Checked = True Then\r\nsum += medium\r\nEnd If\r\n\r\nIf CheckBox3.Checked = True Then\r\nsum += small\r\nEnd If\r\nLabel5.Text = sum.ToString(\u201cc\u201d)\r\n\r\nEnd Sub\r\n<\/pre>\n<h4><strong>Example 21.3<\/strong><\/h4>\n<p>In this example, the text on the label can be formatting using the three check boxes that represent bold, italic and underline.<\/p>\n<h4><strong>The Code<\/strong><\/h4>\n<pre style=\"font-size: 110%;\">Public Class Form1\r\n\r\nPrivate Sub ChkBold_CheckedChanged(sender As Object, e As EventArgs) Handles ChkBold.CheckedChanged\r\nIf ChkBold.Checked Then\r\nLblDisplay.Font = New Font(LblDisplay.Font, LblDisplay.Font.Style Or FontStyle.Bold)\r\nElse\r\nLblDisplay.Font = New Font(LblDisplay.Font, LblDisplay.Font.Style And Not FontStyle.Bold)\r\n\r\nEnd If\r\nEnd Sub\r\n\r\nPrivate Sub ChkItalic_CheckedChanged(sender As Object, e As EventArgs) Handles ChkItalic.CheckedChanged\r\nIf ChkItalic.Checked Then\r\nLblDisplay.Font = New Font(LblDisplay.Font, LblDisplay.Font.Style Or FontStyle.Italic)\r\nElse\r\nLblDisplay.Font = New Font(LblDisplay.Font, LblDisplay.Font.Style And Not FontStyle.Italic)\r\n\r\nEnd If\r\nEnd Sub\r\n\r\nPrivate Sub ChkUnder_CheckedChanged(sender As Object, e As EventArgs) Handles ChkUnder.CheckedChanged\r\nIf ChkUnder.Checked Then\r\nLblDisplay.Font = New Font(LblDisplay.Font, LblDisplay.Font.Style Or FontStyle.Underline)\r\nElse\r\nLblDisplay.Font = New Font(LblDisplay.Font, LblDisplay.Font.Style And Not FontStyle.Underline)\r\n\r\nEnd If\r\nEnd Sub\r\nEnd Class\r\n<\/pre>\n<p>* The above visual basic 2015 program uses the CheckedChanged event to respond to the user selection by checking a particular checkbox, it is similar to the click event. The statement<\/p>\n<pre style=\"font-size: 110%;\">LblDisplay.Font = New Font(LblDisplay.Font, LblDisplay.Font.Style Or FontStyle.Italic)<\/pre>\n<p>will retain the original font type but change it to italic font style.<\/p>\n<pre style=\"font-size: 110%;\">LblDisplay.Font = New Font(LblDisplay.Font, LblDisplay.Font.Style And Not FontStyle.Italic)\r\n<\/pre>\n<p>will also retain the original font type but change it to regular font style. (The other statements employ the same logic)<\/p>\n<h4>The Output<\/h4>\n<p><a href=\"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2014\/01\/vb2013_figure20.2.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4776\" src=\"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2014\/01\/vb2013_figure20.2.jpg\" alt=\"vb2013_figure20.2\" width=\"300\" height=\"300\" \/><\/a><\/p>\n<p style=\"text-align: center;\"><strong>Figure 21.2<\/strong><\/p>\n<p><script async src=\"\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js\"><\/script><br \/>\n<ins class=\"adsbygoogle\"\n     style=\"display:block\"\n     data-ad-format=\"autorelaxed\"\n     data-ad-client=\"ca-pub-3033628290023372\"\n     data-ad-slot=\"5090773108\"><\/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-20-format-functions\/\">[Lesson 20]\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-2015-lesson-22-working-radio-buttons\/\">[Lesson 22]<\/a><\/h4>\n","protected":false},"excerpt":{"rendered":"<p>[Lesson 20] &lt;&lt; [Contents] &gt;&gt; [Lesson 22] In this lesson, we shall learn a how to use the checkbox. The\u00a0Checkbox allows the user to select one or more items by checking the checkbox or checkboxes concerned. For example, in the Font dialog box of any Microsoft Text editor like Microsoft Words, there are many\u00a0checkboxes\u00a0under the &hellip; <a href=\"https:\/\/www.vbtutor.net\/index.php\/visual-basic-2015-lesson-21-working-with-checkboxes\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Visual Basic 2015 Lesson 21: Working with Check Boxes<\/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-7165","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 2015 Lesson 21: Working with Check Boxes - Learn Visual Basic Programming \u2013 VB.NET, VBA &amp; Classic VB<\/title>\n<meta name=\"description\" content=\"This article discusses how to work with checkboxes in visual basic 2015\" \/>\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\/vb2015\/vb2015_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 2015 Lesson 21: Working with Check Boxes - Learn Visual Basic Programming \u2013 VB.NET, VBA &amp; Classic VB\" \/>\n<meta property=\"og:description\" content=\"This article discusses how to work with checkboxes in visual basic 2015\" \/>\n<meta property=\"og:url\" content=\"http:\/\/www.vbtutor.net\/vb2015\/vb2015_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-22T10:13:54+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2014\/01\/vb2013_figure20.11.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-2015-lesson-21-working-with-checkboxes\/\",\"url\":\"http:\/\/www.vbtutor.net\/vb2015\/vb2015_lesson21.html\",\"name\":\"Visual Basic 2015 Lesson 21: Working with Check Boxes - Learn Visual Basic Programming \u2013 VB.NET, VBA &amp; Classic VB\",\"isPartOf\":{\"@id\":\"https:\/\/www.vbtutor.net\/#website\"},\"primaryImageOfPage\":{\"@id\":\"http:\/\/www.vbtutor.net\/vb2015\/vb2015_lesson21.html#primaryimage\"},\"image\":{\"@id\":\"http:\/\/www.vbtutor.net\/vb2015\/vb2015_lesson21.html#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2014\/01\/vb2013_figure20.11.jpg\",\"datePublished\":\"2015-09-05T02:07:30+00:00\",\"dateModified\":\"2018-06-22T10:13:54+00:00\",\"description\":\"This article discusses how to work with checkboxes in visual basic 2015\",\"breadcrumb\":{\"@id\":\"http:\/\/www.vbtutor.net\/vb2015\/vb2015_lesson21.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"http:\/\/www.vbtutor.net\/vb2015\/vb2015_lesson21.html\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/www.vbtutor.net\/vb2015\/vb2015_lesson21.html#primaryimage\",\"url\":\"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2014\/01\/vb2013_figure20.11.jpg\",\"contentUrl\":\"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2014\/01\/vb2013_figure20.11.jpg\",\"width\":553,\"height\":353},{\"@type\":\"BreadcrumbList\",\"@id\":\"http:\/\/www.vbtutor.net\/vb2015\/vb2015_lesson21.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.vbtutor.net\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Visual Basic 2015 Lesson 21: Working with Check Boxes\"}]},{\"@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 2015 Lesson 21: Working with Check Boxes - Learn Visual Basic Programming \u2013 VB.NET, VBA &amp; Classic VB","description":"This article discusses how to work with checkboxes in visual basic 2015","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\/vb2015\/vb2015_lesson21.html","og_locale":"en_US","og_type":"article","og_title":"Visual Basic 2015 Lesson 21: Working with Check Boxes - Learn Visual Basic Programming \u2013 VB.NET, VBA &amp; Classic VB","og_description":"This article discusses how to work with checkboxes in visual basic 2015","og_url":"http:\/\/www.vbtutor.net\/vb2015\/vb2015_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-22T10:13:54+00:00","og_image":[{"url":"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2014\/01\/vb2013_figure20.11.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-2015-lesson-21-working-with-checkboxes\/","url":"http:\/\/www.vbtutor.net\/vb2015\/vb2015_lesson21.html","name":"Visual Basic 2015 Lesson 21: Working with Check Boxes - Learn Visual Basic Programming \u2013 VB.NET, VBA &amp; Classic VB","isPartOf":{"@id":"https:\/\/www.vbtutor.net\/#website"},"primaryImageOfPage":{"@id":"http:\/\/www.vbtutor.net\/vb2015\/vb2015_lesson21.html#primaryimage"},"image":{"@id":"http:\/\/www.vbtutor.net\/vb2015\/vb2015_lesson21.html#primaryimage"},"thumbnailUrl":"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2014\/01\/vb2013_figure20.11.jpg","datePublished":"2015-09-05T02:07:30+00:00","dateModified":"2018-06-22T10:13:54+00:00","description":"This article discusses how to work with checkboxes in visual basic 2015","breadcrumb":{"@id":"http:\/\/www.vbtutor.net\/vb2015\/vb2015_lesson21.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["http:\/\/www.vbtutor.net\/vb2015\/vb2015_lesson21.html"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/www.vbtutor.net\/vb2015\/vb2015_lesson21.html#primaryimage","url":"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2014\/01\/vb2013_figure20.11.jpg","contentUrl":"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2014\/01\/vb2013_figure20.11.jpg","width":553,"height":353},{"@type":"BreadcrumbList","@id":"http:\/\/www.vbtutor.net\/vb2015\/vb2015_lesson21.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.vbtutor.net\/"},{"@type":"ListItem","position":2,"name":"Visual Basic 2015 Lesson 21: Working with Check Boxes"}]},{"@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\/7165","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=7165"}],"version-history":[{"count":35,"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/pages\/7165\/revisions"}],"predecessor-version":[{"id":13037,"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/pages\/7165\/revisions\/13037"}],"wp:attachment":[{"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/media?parent=7165"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/categories?post=7165"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/tags?post=7165"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}