{"id":2392,"date":"2013-02-13T12:24:24","date_gmt":"2013-02-13T04:24:24","guid":{"rendered":"http:\/\/www.vbtutor.net\/index.php\/"},"modified":"2018-06-24T18:05:29","modified_gmt":"2018-06-24T10:05:29","slug":"visual-basic-2012-lesson-17","status":"publish","type":"page","link":"https:\/\/www.vbtutor.net\/index.php\/visual-basic-2012-lesson-17\/","title":{"rendered":"Visual Basic 2012 Lesson 17- The Checkbox"},"content":{"rendered":"<h4 align=\"center\"><strong><a href=\"http:\/\/www.vbtutor.net\/index.php\/visual-basic-2012-lesson-16\/\">[Lesson 16]<\/a> <\/strong>&lt;&lt;\u00a0<strong><a href=\"http:\/\/www.vbtutor.net\/index.php\/visual-basic-2012-tutorial\/\">[CONTENTS]<\/a> &gt;&gt;<a href=\"http:\/\/www.vbtutor.net\/index.php\/visual-basic-2012-lesson-18\/\"> [Lesson 18]<\/a><\/strong><\/h4>\n<p>The checkbox is a control that allows the user to select multiple items. For example, in the Font dialog box of Microsoft Words, there are many\u00a0checkboxes\u00a0under the Effects section,\u00a0 such as that shown in the Figure 17.1 below. The user can choose to format\u00a0the text with an underline, subscript, small caps, superscript, blink and more.<\/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=\"1777484012\"><\/ins><br \/>\n<script>\n     (adsbygoogle = window.adsbygoogle || []).push({});\n<\/script><br \/>\n<img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" src=\"https:\/\/www.vbtutor.net\/vb2008\/Images\/vb2008_17.1.gif\" alt=\"Visual Basic 2012\" width=\"434\" height=\"479\" \/><\/p>\n<h4 style=\"text-align: center;\">Figure 17.1<\/h4>\n<h3>Example 17.1 Shopping Cart<\/h3>\n<p>In Visual Basic 2012, you may create a shopping cart where the user can click on\u00a0checkboxes\u00a0that correspond to the items they intend to purchase, and the total payment can be calculated simultaneously, as shown in Figure 17.1.<\/p>\n<p style=\"text-align: left;\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" src=\"https:\/\/www.vbtutor.net\/vb2008\/Images\/vb2008_17.2.gif\" alt=\"\" width=\"420\" height=\"300\" \/><\/p>\n<h4 style=\"text-align: center;\">Figure 17.2<\/h4>\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=\"1777484012\"><\/ins><br \/>\n<script>\n     (adsbygoogle = window.adsbygoogle || []).push({});\n<\/script><br \/>\nThe program code for the shopping cart is as follows:<\/p>\n<pre style=\"font-size: 110%; width: 70%;\">Private Sub BtnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnCalculate.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\r\nIf CheckBox1.Checked = True Then\r\n sum += LX\r\nEnd If\r\n\r\nIf CheckBox2.Checked = True Then\r\n sum += BN\r\nEnd If\r\n\r\nIf CheckBox3.Checked = True Then\r\n sum += SD\r\nEnd If\r\n\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\n sum += AM\r\n End If\r\n Label5.Text = sum.ToString(\"c\")\r\n<\/pre>\n<p>Here is another example<\/p>\n<h4>Example 17.2<\/h4>\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\r\nIf CheckBox1.Checked = True Then\r\n sum += large\r\nEnd If\r\n\r\nIf CheckBox2.Checked = True Then\r\n sum += medium\r\nEnd If\r\n\r\nIf CheckBox3.Checked = True Then\r\n sum += small\r\nEnd If\r\n Label5.Text = sum.ToString(\"c\")\r\n<\/pre>\n<h4>Example 17.3<\/h4>\n<p>In this example, the user can enter text into a text box and format the font using the three checkboxes that represent bold, italic and underline.<br \/>\n<img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" src=\"https:\/\/www.vbtutor.net\/vb2010\/vb2010_Image\/vb2010_lesson%2017.3.jpg\" alt=\"\" width=\"300\" height=\"300\" \/><\/p>\n<h4 style=\"text-align: center;\">Figure 17.3<\/h4>\n<h4>The code<\/h4>\n<pre style=\"font-size: 110%;\">Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged\r\nIf CheckBox1.Checked Then\r\n TextBox1.Font = New Font(TextBox1.Font, TextBox1.Font.Style Or FontStyle.Bold)\r\nElse\r\n TextBox1.Font = New Font(TextBox1.Font, TextBox1.Font.Style And Not FontStyle.Bold)\r\n\r\nEnd If\r\nEnd Sub\r\n\r\nPrivate Sub CheckBox2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox2.CheckedChanged\r\nIf CheckBox2.Checked Then\r\n TextBox1.Font = New Font(TextBox1.Font, TextBox1.Font.Style Or FontStyle.Italic)\r\nElse\r\n TextBox1.Font = New Font(TextBox1.Font, TextBox1.Font.Style And Not FontStyle.Italic)\r\n\r\nEnd If\r\nEnd Sub\r\n\r\nPrivate Sub CheckBox3_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox3.CheckedChanged\r\nIf CheckBox2.Checked Then\r\n TextBox1.Font = New Font(TextBox1.Font, TextBox1.Font.Style Or FontStyle.Underline)\r\nElse\r\n TextBox1.Font = New Font(TextBox1.Font, TextBox1.Font.Style And Not FontStyle.Underline)\r\n\r\nEnd If\r\nEnd Sub\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%;\">TextBox1.Font = New Font(TextBox1.Font, TextBox1.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%;\">TextBox1.Font = New Font(TextBox1.Font, TextBox1.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><a href=\"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2012\/04\/table17.1.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-1313\" title=\"table17.1\" src=\"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2012\/04\/table17.1.jpg\" alt=\"\" width=\"660\" height=\"139\" srcset=\"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2012\/04\/table17.1.jpg 660w, https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2012\/04\/table17.1-300x63.jpg 300w\" sizes=\"auto, (max-width: 660px) 100vw, 660px\" \/><\/a><br \/>\n* Instead of &#8220;General date&#8221;, you can also use the abbreviated format &#8220;G&#8221;, i.e. Format (Now, &#8220;G&#8221;). And for &#8220;Long Time&#8221;, you can use the abbreviated format &#8220;T&#8221;. As for &#8220;Short Time&#8221;, you may use the abbreviated format &#8220;t&#8221;<\/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=\"6598395509\"><\/ins><br \/>\n<script>\n     (adsbygoogle = window.adsbygoogle || []).push({});\n<\/script><\/p>\n<h4 style=\"text-align: center;\"><strong><a href=\"http:\/\/www.vbtutor.net\/index.php\/visual-basic-2012-lesson-16\/\">[Lesson 16]<\/a> &lt;&lt;<a href=\"http:\/\/www.vbtutor.net\/index.php\/visual-basic-2012-tutorial\/\">[CONTENTS]<\/a> &gt;&gt;<a href=\"http:\/\/www.vbtutor.net\/index.php\/visual-basic-2010-lesson-18\/\"> [Lesson 18]<\/a><\/strong><\/h4>\n<p><strong><br \/>\n<\/strong><\/p>\n<p><strong><br \/>\n<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>[Lesson 16] &lt;&lt;\u00a0[CONTENTS] &gt;&gt; [Lesson 18] The checkbox is a control that allows the user to select multiple items. For example, in the Font dialog box of Microsoft Words, there are many\u00a0checkboxes\u00a0under the Effects section,\u00a0 such as that shown in the Figure 17.1 below. The user can choose to format\u00a0the text with an underline, subscript, &hellip; <a href=\"https:\/\/www.vbtutor.net\/index.php\/visual-basic-2012-lesson-17\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Visual Basic 2012 Lesson 17- The Checkbox<\/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-2392","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 2012 Lesson 17- The Checkbox - Learn Visual Basic Programming \u2013 VB.NET, VBA &amp; Classic VB<\/title>\n<meta name=\"description\" content=\"This visual basic 2012 lesson demonstrates the use of check box in visual basic 2012\" \/>\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\/vb2012\/vb2012_lesson17.html\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Visual Basic 2012 Lesson 17- The Checkbox - Learn Visual Basic Programming \u2013 VB.NET, VBA &amp; Classic VB\" \/>\n<meta property=\"og:description\" content=\"This visual basic 2012 lesson demonstrates the use of check box in visual basic 2012\" \/>\n<meta property=\"og:url\" content=\"http:\/\/www.vbtutor.net\/vb2012\/vb2012_lesson17.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-24T10:05:29+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.vbtutor.net\/vb2008\/Images\/vb2008_17.1.gif\" \/>\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-2012-lesson-17\/\",\"url\":\"http:\/\/www.vbtutor.net\/vb2012\/vb2012_lesson17.html\",\"name\":\"Visual Basic 2012 Lesson 17- The Checkbox - Learn Visual Basic Programming \u2013 VB.NET, VBA &amp; Classic VB\",\"isPartOf\":{\"@id\":\"https:\/\/www.vbtutor.net\/#website\"},\"primaryImageOfPage\":{\"@id\":\"http:\/\/www.vbtutor.net\/vb2012\/vb2012_lesson17.html#primaryimage\"},\"image\":{\"@id\":\"http:\/\/www.vbtutor.net\/vb2012\/vb2012_lesson17.html#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.vbtutor.net\/vb2008\/Images\/vb2008_17.1.gif\",\"datePublished\":\"2013-02-13T04:24:24+00:00\",\"dateModified\":\"2018-06-24T10:05:29+00:00\",\"description\":\"This visual basic 2012 lesson demonstrates the use of check box in visual basic 2012\",\"breadcrumb\":{\"@id\":\"http:\/\/www.vbtutor.net\/vb2012\/vb2012_lesson17.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"http:\/\/www.vbtutor.net\/vb2012\/vb2012_lesson17.html\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/www.vbtutor.net\/vb2012\/vb2012_lesson17.html#primaryimage\",\"url\":\"https:\/\/www.vbtutor.net\/vb2008\/Images\/vb2008_17.1.gif\",\"contentUrl\":\"https:\/\/www.vbtutor.net\/vb2008\/Images\/vb2008_17.1.gif\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"http:\/\/www.vbtutor.net\/vb2012\/vb2012_lesson17.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.vbtutor.net\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Visual Basic 2012 Lesson 17- The Checkbox\"}]},{\"@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 2012 Lesson 17- The Checkbox - Learn Visual Basic Programming \u2013 VB.NET, VBA &amp; Classic VB","description":"This visual basic 2012 lesson demonstrates the use of check box in visual basic 2012","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\/vb2012\/vb2012_lesson17.html","og_locale":"en_US","og_type":"article","og_title":"Visual Basic 2012 Lesson 17- The Checkbox - Learn Visual Basic Programming \u2013 VB.NET, VBA &amp; Classic VB","og_description":"This visual basic 2012 lesson demonstrates the use of check box in visual basic 2012","og_url":"http:\/\/www.vbtutor.net\/vb2012\/vb2012_lesson17.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-24T10:05:29+00:00","og_image":[{"url":"https:\/\/www.vbtutor.net\/vb2008\/Images\/vb2008_17.1.gif","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-2012-lesson-17\/","url":"http:\/\/www.vbtutor.net\/vb2012\/vb2012_lesson17.html","name":"Visual Basic 2012 Lesson 17- The Checkbox - Learn Visual Basic Programming \u2013 VB.NET, VBA &amp; Classic VB","isPartOf":{"@id":"https:\/\/www.vbtutor.net\/#website"},"primaryImageOfPage":{"@id":"http:\/\/www.vbtutor.net\/vb2012\/vb2012_lesson17.html#primaryimage"},"image":{"@id":"http:\/\/www.vbtutor.net\/vb2012\/vb2012_lesson17.html#primaryimage"},"thumbnailUrl":"https:\/\/www.vbtutor.net\/vb2008\/Images\/vb2008_17.1.gif","datePublished":"2013-02-13T04:24:24+00:00","dateModified":"2018-06-24T10:05:29+00:00","description":"This visual basic 2012 lesson demonstrates the use of check box in visual basic 2012","breadcrumb":{"@id":"http:\/\/www.vbtutor.net\/vb2012\/vb2012_lesson17.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["http:\/\/www.vbtutor.net\/vb2012\/vb2012_lesson17.html"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/www.vbtutor.net\/vb2012\/vb2012_lesson17.html#primaryimage","url":"https:\/\/www.vbtutor.net\/vb2008\/Images\/vb2008_17.1.gif","contentUrl":"https:\/\/www.vbtutor.net\/vb2008\/Images\/vb2008_17.1.gif"},{"@type":"BreadcrumbList","@id":"http:\/\/www.vbtutor.net\/vb2012\/vb2012_lesson17.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.vbtutor.net\/"},{"@type":"ListItem","position":2,"name":"Visual Basic 2012 Lesson 17- The Checkbox"}]},{"@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\/2392","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=2392"}],"version-history":[{"count":37,"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/pages\/2392\/revisions"}],"predecessor-version":[{"id":13108,"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/pages\/2392\/revisions\/13108"}],"wp:attachment":[{"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/media?parent=2392"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/categories?post=2392"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/tags?post=2392"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}