{"id":1102,"date":"2012-04-06T16:44:08","date_gmt":"2012-04-06T08:44:08","guid":{"rendered":"http:\/\/www.vbtutor.net\/index.php\/"},"modified":"2018-06-24T20:24:15","modified_gmt":"2018-06-24T12:24:15","slug":"visual-basic-2010-lesson-17","status":"publish","type":"page","link":"https:\/\/www.vbtutor.net\/index.php\/visual-basic-2010-lesson-17\/","title":{"rendered":"Visual Basic 2010 Lesson 17 &#8211; Using Check Box"},"content":{"rendered":"<h4 align=\"center\"><strong><a href=\"http:\/\/www.vbtutor.net\/index.php\/visual-basic-2010-lesson-16\/\">[Lesson 16]<\/a> <\/strong>&lt;&lt;\u00a0<strong><a href=\"http:\/\/www.vbtutor.net\/index.php\/visual-basic-2010-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>A Checkbox allows the user to select one or more items by checking the checkbox\/check boxes concerned. For example, in the Font dialog box of any Microsoft Text editor like MS Words, there are many\u00a0checkboxes\u00a0under the Effects section such as that shown in the figure below. The user can choose to underline, subscript, small caps, superscript, blink and more. In Visual Basic 2010, you may create a shopping cart. In Example 17.1, \u00a0the user can click on\u00a0checkboxes\u00a0on the shopping cart that correspond to the items they intend to buy, where the total payment can be computed at the same time.<br \/>\n<img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" src=\"https:\/\/www.vbtutor.net\/vb2008\/Images\/vb2008_17.1.gif\" alt=\"Visual Basic 2010\" width=\"434\" height=\"479\" \/><br \/>\n<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=\"1723562988\"><\/ins><br \/>\n<script>\n     (adsbygoogle = window.adsbygoogle || []).push({});\n<\/script><\/p>\n<h4>Example 17.1 Shopping Cart<\/h4>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" src=\"https:\/\/www.vbtutor.net\/vb2008\/Images\/vb2008_17.2.gif\" alt=\"Visual Basic 2010\" width=\"420\" height=\"300\" \/><br \/>\n<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=\"1723562988\"><\/ins><br \/>\n<script>\n     (adsbygoogle = window.adsbygoogle || []).push({});\n<\/script><br \/>\nThe code for shopping cart:<\/p>\n<pre style=\"font-size: 110%;\">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\n sum += HD\r\nEnd If\r\n\r\nIf CheckBox5.Checked = True Then\r\n sum += HM\r\nEnd If\r\n\r\nIf CheckBox6.Checked = True Then\r\n sum += AM\r\nEnd 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 check boxes that represent bold, italic and underline.<\/p>\n<p><center><br \/>\n<img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" src=\"https:\/\/www.vbtutor.net\/vb2010\/vb2010_Image\/vb2010_lesson%2017.3.jpg\" alt=\"Visual Basic 2010\" width=\"300\" height=\"300\" \/><\/center>The code is as follow:<\/p>\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\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\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\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><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" src=\"https:\/\/www.vbtutor.net\/vb2008\/Images\/vb2008_17.1.gif\" alt=\"Visual Basic 2010\" width=\"434\" height=\"479\" \/><\/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=\"Visual Basic 2010\" 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;<br \/>\n<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=\"8075128701\"><\/ins><br \/>\n<script>\n     (adsbygoogle = window.adsbygoogle || []).push({});\n<\/script><\/p>\n<h4 align=\"center\"><strong><a href=\"http:\/\/www.vbtutor.net\/index.php\/visual-basic-2010-lesson-16\/\">[Lesson 16]<\/a> &lt;&lt;<a href=\"http:\/\/www.vbtutor.net\/index.php\/visual-basic-2010-tutorial\/\">[CONTENTS]<\/a> &gt;&gt;<a href=\"http:\/\/www.vbtutor.net\/index.php\/visual-basic-2010-lesson-18\/\"> [Lesson 18]<\/a><\/strong><\/h4>\n","protected":false},"excerpt":{"rendered":"<p>[Lesson 16] &lt;&lt;\u00a0[CONTENTS] &gt;&gt; [Lesson 18] A Checkbox allows the user to select one or more items by checking the checkbox\/check boxes concerned. For example, in the Font dialog box of any Microsoft Text editor like MS Words, there are many\u00a0checkboxes\u00a0under the Effects section such as that shown in the figure below. The user can &hellip; <a href=\"https:\/\/www.vbtutor.net\/index.php\/visual-basic-2010-lesson-17\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Visual Basic 2010 Lesson 17 &#8211; 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-1102","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 2010 Lesson 17 - Using Check Box - Learn Visual Basic Programming \u2013 VB.NET, VBA &amp; Classic VB<\/title>\n<meta name=\"description\" content=\"This Visual Basic 2010 demonstrates the usage of check box in Visual Basic 2010\" \/>\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\/vb2010\/vb2010_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 2010 Lesson 17 - Using Check Box - Learn Visual Basic Programming \u2013 VB.NET, VBA &amp; Classic VB\" \/>\n<meta property=\"og:description\" content=\"This Visual Basic 2010 demonstrates the usage of check box in Visual Basic 2010\" \/>\n<meta property=\"og:url\" content=\"http:\/\/www.vbtutor.net\/vb2010\/vb2010_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-24T12:24:15+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-2010-lesson-17\/\",\"url\":\"http:\/\/www.vbtutor.net\/vb2010\/vb2010_lesson17.html\",\"name\":\"Visual Basic 2010 Lesson 17 - 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\/vb2010\/vb2010_lesson17.html#primaryimage\"},\"image\":{\"@id\":\"http:\/\/www.vbtutor.net\/vb2010\/vb2010_lesson17.html#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.vbtutor.net\/vb2008\/Images\/vb2008_17.1.gif\",\"datePublished\":\"2012-04-06T08:44:08+00:00\",\"dateModified\":\"2018-06-24T12:24:15+00:00\",\"description\":\"This Visual Basic 2010 demonstrates the usage of check box in Visual Basic 2010\",\"breadcrumb\":{\"@id\":\"http:\/\/www.vbtutor.net\/vb2010\/vb2010_lesson17.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"http:\/\/www.vbtutor.net\/vb2010\/vb2010_lesson17.html\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/www.vbtutor.net\/vb2010\/vb2010_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\/vb2010\/vb2010_lesson17.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.vbtutor.net\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Visual Basic 2010 Lesson 17 &#8211; 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 2010 Lesson 17 - Using Check Box - Learn Visual Basic Programming \u2013 VB.NET, VBA &amp; Classic VB","description":"This Visual Basic 2010 demonstrates the usage of check box in Visual Basic 2010","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\/vb2010\/vb2010_lesson17.html","og_locale":"en_US","og_type":"article","og_title":"Visual Basic 2010 Lesson 17 - Using Check Box - Learn Visual Basic Programming \u2013 VB.NET, VBA &amp; Classic VB","og_description":"This Visual Basic 2010 demonstrates the usage of check box in Visual Basic 2010","og_url":"http:\/\/www.vbtutor.net\/vb2010\/vb2010_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-24T12:24:15+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-2010-lesson-17\/","url":"http:\/\/www.vbtutor.net\/vb2010\/vb2010_lesson17.html","name":"Visual Basic 2010 Lesson 17 - 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\/vb2010\/vb2010_lesson17.html#primaryimage"},"image":{"@id":"http:\/\/www.vbtutor.net\/vb2010\/vb2010_lesson17.html#primaryimage"},"thumbnailUrl":"https:\/\/www.vbtutor.net\/vb2008\/Images\/vb2008_17.1.gif","datePublished":"2012-04-06T08:44:08+00:00","dateModified":"2018-06-24T12:24:15+00:00","description":"This Visual Basic 2010 demonstrates the usage of check box in Visual Basic 2010","breadcrumb":{"@id":"http:\/\/www.vbtutor.net\/vb2010\/vb2010_lesson17.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["http:\/\/www.vbtutor.net\/vb2010\/vb2010_lesson17.html"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/www.vbtutor.net\/vb2010\/vb2010_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\/vb2010\/vb2010_lesson17.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.vbtutor.net\/"},{"@type":"ListItem","position":2,"name":"Visual Basic 2010 Lesson 17 &#8211; 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\/1102","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=1102"}],"version-history":[{"count":39,"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/pages\/1102\/revisions"}],"predecessor-version":[{"id":13137,"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/pages\/1102\/revisions\/13137"}],"wp:attachment":[{"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/media?parent=1102"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/categories?post=1102"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/tags?post=1102"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}