{"id":4765,"date":"2014-01-24T22:02:17","date_gmt":"2014-01-24T14:02:17","guid":{"rendered":"http:\/\/www.vbtutor.net\/?page_id=4765"},"modified":"2018-06-24T16:52:46","modified_gmt":"2018-06-24T08:52:46","slug":"visual-basic-2013-lesson-20-using-check-box","status":"publish","type":"page","link":"https:\/\/www.vbtutor.net\/index.php\/visual-basic-2013-lesson-20-using-check-box\/","title":{"rendered":"Visual Basic 2013 Lesson 20: Using Check Box"},"content":{"rendered":"<h4 style=\"text-align: center;\"><a href=\"http:\/\/www.vbtutor.net\/index.php\/visual-basic-2013-lesson-19-formatting-functions\/\">[Lesson 19] <\/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-21-using-radio-button\/\">[Lesson 21]<\/a><\/h4>\n<p>In this lesson, we shall learn how to write code for the checkbox. The Checkbox allows the user to select one or more items by checking the check box or check boxes 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 more. In Visual Basic 2013, you may 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\"\n     style=\"display:block; text-align:center;\"\n     data-ad-layout=\"in-article\"\n     data-ad-format=\"fluid\"\n     data-ad-client=\"ca-pub-3033628290023372\"\n     data-ad-slot=\"3914691604\"><\/ins><br \/>\n<script>\n     (adsbygoogle = window.adsbygoogle || []).push({});\n<\/script><\/p>\n<h4>Example 20.1: Shopping Cart<\/h4>\n<p>In this example, we add a few labels, two buttons, and six check boxes. 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 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\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\n If CheckBox1.Checked = True Then\r\n  sum += LX\r\n End If\r\n\r\n If CheckBox2.Checked = True Then\r\n  sum += BN\r\n End If\r\n\r\n If CheckBox3.Checked = True Then\r\n  sum += SD\r\n End If\r\n If CheckBox4.Checked = True Then\r\n  sum += HD\r\n End If\r\n\r\n If CheckBox5.Checked = True Then\r\n  sum += HM\r\n End If\r\n\r\n If CheckBox6.Checked = True Then\r\n  sum += AM\r\n End If\r\n  LblTotal.Text = sum.ToString(\"c\")\r\nEnd Sub\r\n\r\nPrivate Sub BtnReset_Click(sender As Object, e As EventArgs) Handles BtnReset.Click\r\n CheckBox1.Checked = False\r\n CheckBox2.Checked = False\r\n CheckBox3.Checked = False\r\n CheckBox4.Checked = False\r\n CheckBox5.Checked = False\r\n CheckBox6.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<p style=\"text-align: center;\">\u00a0<strong>Figure 20.1: Shopping Cart<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>Here is another example<\/p>\n<p><strong>Example 20.2<\/strong><\/p>\n<pre style=\"font-size: 110%;\">Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click\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 If CheckBox1.Checked = True Then\r\n  sum += large\r\n End If\r\n\r\n If CheckBox2.Checked = True Then\r\n  sum += medium\r\n End If\r\n\r\n If CheckBox3.Checked = True Then\r\n  sum += small\r\n End If\r\n  Label5.Text = sum.ToString(\u201cc\u201d)\r\n\r\nEnd Sub\r\n<\/pre>\n<p><strong>Example 20.3<\/strong><\/p>\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<p><strong>The Code<\/strong><\/p>\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\n If ChkBold.Checked Then\r\n  LblDisplay.Font = New Font(LblDisplay.Font, LblDisplay.Font.Style Or FontStyle.Bold)\r\n Else\r\n  LblDisplay.Font = New Font(LblDisplay.Font, LblDisplay.Font.Style And Not FontStyle.Bold)\r\n\r\n End If\r\nEnd Sub\r\n\r\nPrivate Sub ChkItalic_CheckedChanged(sender As Object, e As EventArgs) Handles ChkItalic.CheckedChanged\r\n If ChkItalic.Checked Then\r\n  LblDisplay.Font = New Font(LblDisplay.Font, LblDisplay.Font.Style Or FontStyle.Italic)\r\n Else\r\n  LblDisplay.Font = New Font(LblDisplay.Font, LblDisplay.Font.Style And Not FontStyle.Italic)\r\n End If\r\nEnd Sub\r\n\r\nPrivate Sub ChkUnder_CheckedChanged(sender As Object, e As EventArgs) Handles ChkUnder.CheckedChanged\r\n If ChkUnder.Checked Then\r\n  LblDisplay.Font = New Font(LblDisplay.Font, LblDisplay.Font.Style Or FontStyle.Underline)\r\n Else\r\n  LblDisplay.Font = New Font(LblDisplay.Font, LblDisplay.Font.Style And Not FontStyle.Underline)\r\n End If\r\nEnd Sub\r\nEnd Class\r\n<\/pre>\n<p>* The above 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)\r\n<\/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<p>The Output<\/p>\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 20.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; text-align:center;\"\n     data-ad-layout=\"in-article\"\n     data-ad-format=\"fluid\"\n     data-ad-client=\"ca-pub-3033628290023372\"\n     data-ad-slot=\"3914691604\"><\/ins><br \/>\n<script>\n     (adsbygoogle = window.adsbygoogle || []).push({});\n<\/script><br \/>\n<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=\"2306771905\"><\/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-19-formatting-functions\/\">[Lesson 19]\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-21-using-radio-button\/\">[Lesson 21]<\/a><\/h4>\n","protected":false},"excerpt":{"rendered":"<p>[Lesson 19] &lt;&lt; [Contents] &gt;&gt; [Lesson 21] In this lesson, we shall learn how to write code for the checkbox. The Checkbox allows the user to select one or more items by checking the check box or check boxes concerned. For example, in the Font dialog box of any Microsoft Text editor like Microsoft Words, &hellip; <a href=\"https:\/\/www.vbtutor.net\/index.php\/visual-basic-2013-lesson-20-using-check-box\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Visual Basic 2013 Lesson 20: Using Check Box<\/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-4765","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 20: Using Check Box - Learn Visual Basic Programming \u2013 VB.NET, VBA &amp; Classic VB<\/title>\n<meta name=\"description\" content=\"This article discusses the use of check box 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_Lesson20.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 20: Using Check Box - Learn Visual Basic Programming \u2013 VB.NET, VBA &amp; Classic VB\" \/>\n<meta property=\"og:description\" content=\"This article discusses the use of check box visual basic 2013\" \/>\n<meta property=\"og:url\" content=\"http:\/\/www.vbtutor.net\/vb2013\/vb2013_Lesson20.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:52:46+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-2013-lesson-20-using-check-box\/\",\"url\":\"http:\/\/www.vbtutor.net\/vb2013\/vb2013_Lesson20.html\",\"name\":\"Visual Basic 2013 Lesson 20: Using Check Box - 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_Lesson20.html#primaryimage\"},\"image\":{\"@id\":\"http:\/\/www.vbtutor.net\/vb2013\/vb2013_Lesson20.html#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2014\/01\/vb2013_figure20.11.jpg\",\"datePublished\":\"2014-01-24T14:02:17+00:00\",\"dateModified\":\"2018-06-24T08:52:46+00:00\",\"description\":\"This article discusses the use of check box visual basic 2013\",\"breadcrumb\":{\"@id\":\"http:\/\/www.vbtutor.net\/vb2013\/vb2013_Lesson20.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"http:\/\/www.vbtutor.net\/vb2013\/vb2013_Lesson20.html\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/www.vbtutor.net\/vb2013\/vb2013_Lesson20.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\/vb2013\/vb2013_Lesson20.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.vbtutor.net\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Visual Basic 2013 Lesson 20: Using Check Box\"}]},{\"@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 20: Using Check Box - Learn Visual Basic Programming \u2013 VB.NET, VBA &amp; Classic VB","description":"This article discusses the use of check box 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_Lesson20.html","og_locale":"en_US","og_type":"article","og_title":"Visual Basic 2013 Lesson 20: Using Check Box - Learn Visual Basic Programming \u2013 VB.NET, VBA &amp; Classic VB","og_description":"This article discusses the use of check box visual basic 2013","og_url":"http:\/\/www.vbtutor.net\/vb2013\/vb2013_Lesson20.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:52:46+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-2013-lesson-20-using-check-box\/","url":"http:\/\/www.vbtutor.net\/vb2013\/vb2013_Lesson20.html","name":"Visual Basic 2013 Lesson 20: Using Check Box - 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_Lesson20.html#primaryimage"},"image":{"@id":"http:\/\/www.vbtutor.net\/vb2013\/vb2013_Lesson20.html#primaryimage"},"thumbnailUrl":"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2014\/01\/vb2013_figure20.11.jpg","datePublished":"2014-01-24T14:02:17+00:00","dateModified":"2018-06-24T08:52:46+00:00","description":"This article discusses the use of check box visual basic 2013","breadcrumb":{"@id":"http:\/\/www.vbtutor.net\/vb2013\/vb2013_Lesson20.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["http:\/\/www.vbtutor.net\/vb2013\/vb2013_Lesson20.html"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/www.vbtutor.net\/vb2013\/vb2013_Lesson20.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\/vb2013\/vb2013_Lesson20.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.vbtutor.net\/"},{"@type":"ListItem","position":2,"name":"Visual Basic 2013 Lesson 20: Using Check Box"}]},{"@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\/4765","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=4765"}],"version-history":[{"count":35,"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/pages\/4765\/revisions"}],"predecessor-version":[{"id":13074,"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/pages\/4765\/revisions\/13074"}],"wp:attachment":[{"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/media?parent=4765"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/categories?post=4765"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/tags?post=4765"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}