{"id":8522,"date":"2016-08-30T17:59:29","date_gmt":"2016-08-30T09:59:29","guid":{"rendered":"http:\/\/www.vbtutor.net\/?page_id=8522"},"modified":"2018-06-22T22:26:24","modified_gmt":"2018-06-22T14:26:24","slug":"visual-basic-2015-lesson-38-building-console-application-part-2","status":"publish","type":"page","link":"https:\/\/www.vbtutor.net\/index.php\/visual-basic-2015-lesson-38-building-console-application-part-2\/","title":{"rendered":"Visual Basic 2015 Lesson 38: Building Console Application Part 2"},"content":{"rendered":"<h4 style=\"text-align: center;\"><a href=\"http:\/\/www.vbtutor.net\/index.php\/visual-basic-2015-lesson-37-building-console-application-part-1\/\">[Lesson 37]<\/a>&lt;&lt; <a href=\"http:\/\/www.vbtutor.net\/index.php\/visual-basic-2015-tutorial\/\">[Contents]<\/a><\/h4>\n<p>In this lesson, we shall learn how to create Visual Basic 2015 console applications using the <strong>If..Then&#8230;Else<\/strong> control structure and the <strong>Select Case<\/strong> control structure.<\/p>\n<h3>38.1 Using If&#8230;.Then&#8230;.Else<\/h3>\n<p>The \u00a0If&#8230;Then&#8230;.Else structure is as follows:<\/p>\n<pre style=\"font-size: 110%;\">If\u00a0conditions Then \r\n VB expressions\r\nElse\r\n VB expressions\r\nEnd If<\/pre>\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<h4>Example 38.1<\/h4>\n<p>The following code uses If&#8230;.Then&#8230;.Else control structure to evaluate the answer entered by the user .<\/p>\n<pre style=\"font-size: 110%;\">Sub Main()\r\nDim x, y, z, total As Single\r\nDim firstnum As String\r\nDim secondnum As String\r\nDim sum As String\r\nfirstnum = InputBox(\"Enter a Number\")\r\nsecondnum = InputBox(\"Enter a number\")\r\nsum = InputBox(\"The answer is\")\r\ntotal = Val(firstnum) + Val(secondnum)\r\nIf total = Val(sum) Then\r\nMsgBox(\"Correct\")\r\nElse\r\nMsgBox(\"Wrong\")\r\nEnd If\r\nEnd Sub\r\n<\/pre>\n<p>When we run the application, you will be presented with an input box as shown in Figure 38.1<\/p>\n<p><a href=\"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2016\/08\/figure38.1.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-8525\" src=\"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2016\/08\/figure38.1.jpg\" alt=\"figure38.1\" width=\"353\" height=\"158\" srcset=\"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2016\/08\/figure38.1.jpg 353w, https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2016\/08\/figure38.1-300x134.jpg 300w\" sizes=\"auto, (max-width: 353px) 100vw, 353px\" \/><\/a><\/p>\n<p><strong>Figure 38.1<\/strong><\/p>\n<p>After entering a number, you will be presented a second input box where you are required to enter the second number. After that, you will be presented with a third input box that prompts you to enter the answer which supposes to be the sum of the two numbers entered, as shown in Figure 38.2<\/p>\n<p><a href=\"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2016\/08\/figure38.1.2.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-8526\" src=\"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2016\/08\/figure38.1.2.jpg\" alt=\"figure38.1.2\" width=\"358\" height=\"152\" srcset=\"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2016\/08\/figure38.1.2.jpg 358w, https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2016\/08\/figure38.1.2-300x127.jpg 300w\" sizes=\"auto, (max-width: 358px) 100vw, 358px\" \/><\/a><\/p>\n<p><strong>Figure 38.2<\/strong><\/p>\n<p>If the answer is correct, a message box will display the word &#8216;Correct&#8217;, otherwise, it will show the word &#8216;Wrong&#8217;, as shown in Figure 38.3<\/p>\n<p><a href=\"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2016\/08\/figure38.1.3.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-8527\" src=\"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2016\/08\/figure38.1.3.jpg\" alt=\"figure38.1.3\" width=\"156\" height=\"148\" \/><\/a><\/p>\n<p><strong>Figure 38.3<\/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=\"4768455349\"><\/ins><br \/>\n<script>\n     (adsbygoogle = window.adsbygoogle || []).push({});\n<\/script><\/p>\n<h3>38.2 Using Select Case<\/h3>\n<p>The Select Case control structure evaluates one expression for multiple values. Select Case is preferred when there exist multiple conditions.<\/p>\n<p>The Select Case control structure is shown below:<\/p>\n<pre style=\"font-size: 110%;\">Select Case  expression\r\n\r\n Case value1\r\n\u00a0 Block of one or more VB statements\r\n Case value2\r\n Block of one or more VB Statements\r\n Case Else\r\n Block of one or more VB Statements\r\n\r\nEnd Select<\/pre>\n<h4>Example 38.2<\/h4>\n<p>This application allows the user to input an examination grade and it will display the result in a message box, as shown in the figures below:<\/p>\n<p><a href=\"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2016\/08\/figure38.2.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-8531\" src=\"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2016\/08\/figure38.2.jpg\" alt=\"figure38.2\" width=\"355\" height=\"152\" srcset=\"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2016\/08\/figure38.2.jpg 355w, https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2016\/08\/figure38.2-300x128.jpg 300w\" sizes=\"auto, (max-width: 355px) 100vw, 355px\" \/><\/a><\/p>\n<p><strong>Figure 38.4<\/strong><\/p>\n<p><a href=\"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2016\/08\/figure38.3.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-8532\" src=\"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2016\/08\/figure38.3.jpg\" alt=\"figure38.3\" width=\"140\" height=\"148\" \/><\/a><\/p>\n<p><strong>Figure 38.5<\/strong><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=\"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-37-building-console-application-part-1\/\">[Lesson 37]<\/a>&lt;&lt; <a href=\"http:\/\/www.vbtutor.net\/index.php\/visual-basic-2015-tutorial\/\">[Contents]<\/a><\/h4>\n","protected":false},"excerpt":{"rendered":"<p>[Lesson 37]&lt;&lt; [Contents] In this lesson, we shall learn how to create Visual Basic 2015 console applications using the If..Then&#8230;Else control structure and the Select Case control structure. 38.1 Using If&#8230;.Then&#8230;.Else The \u00a0If&#8230;Then&#8230;.Else structure is as follows: If\u00a0conditions Then VB expressions Else VB expressions End If Example 38.1 The following code uses If&#8230;.Then&#8230;.Else control structure &hellip; <a href=\"https:\/\/www.vbtutor.net\/index.php\/visual-basic-2015-lesson-38-building-console-application-part-2\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Visual Basic 2015 Lesson 38: Building Console Application Part 2<\/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-8522","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 console programming<\/title>\n<meta name=\"description\" content=\"Visual basic 2015 tutorial\" \/>\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_lesson38.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 console programming\" \/>\n<meta property=\"og:description\" content=\"Visual basic 2015 tutorial\" \/>\n<meta property=\"og:url\" content=\"http:\/\/www.vbtutor.net\/vb2015\/vb2015_lesson38.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-22T14:26:24+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2016\/08\/figure38.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=\"2 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-38-building-console-application-part-2\/\",\"url\":\"http:\/\/www.vbtutor.net\/vb2015\/vb2015_lesson38.html\",\"name\":\"Visual Basic 2015 console programming\",\"isPartOf\":{\"@id\":\"https:\/\/www.vbtutor.net\/#website\"},\"primaryImageOfPage\":{\"@id\":\"http:\/\/www.vbtutor.net\/vb2015\/vb2015_lesson38.html#primaryimage\"},\"image\":{\"@id\":\"http:\/\/www.vbtutor.net\/vb2015\/vb2015_lesson38.html#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2016\/08\/figure38.1.jpg\",\"datePublished\":\"2016-08-30T09:59:29+00:00\",\"dateModified\":\"2018-06-22T14:26:24+00:00\",\"description\":\"Visual basic 2015 tutorial\",\"breadcrumb\":{\"@id\":\"http:\/\/www.vbtutor.net\/vb2015\/vb2015_lesson38.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"http:\/\/www.vbtutor.net\/vb2015\/vb2015_lesson38.html\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/www.vbtutor.net\/vb2015\/vb2015_lesson38.html#primaryimage\",\"url\":\"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2016\/08\/figure38.1.jpg\",\"contentUrl\":\"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2016\/08\/figure38.1.jpg\",\"width\":353,\"height\":158},{\"@type\":\"BreadcrumbList\",\"@id\":\"http:\/\/www.vbtutor.net\/vb2015\/vb2015_lesson38.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.vbtutor.net\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Visual Basic 2015 Lesson 38: Building Console Application Part 2\"}]},{\"@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 console programming","description":"Visual basic 2015 tutorial","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_lesson38.html","og_locale":"en_US","og_type":"article","og_title":"Visual Basic 2015 console programming","og_description":"Visual basic 2015 tutorial","og_url":"http:\/\/www.vbtutor.net\/vb2015\/vb2015_lesson38.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-22T14:26:24+00:00","og_image":[{"url":"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2016\/08\/figure38.1.jpg","type":"","width":"","height":""}],"twitter_card":"summary_large_image","twitter_site":"@liewvk","twitter_misc":{"Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.vbtutor.net\/index.php\/visual-basic-2015-lesson-38-building-console-application-part-2\/","url":"http:\/\/www.vbtutor.net\/vb2015\/vb2015_lesson38.html","name":"Visual Basic 2015 console programming","isPartOf":{"@id":"https:\/\/www.vbtutor.net\/#website"},"primaryImageOfPage":{"@id":"http:\/\/www.vbtutor.net\/vb2015\/vb2015_lesson38.html#primaryimage"},"image":{"@id":"http:\/\/www.vbtutor.net\/vb2015\/vb2015_lesson38.html#primaryimage"},"thumbnailUrl":"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2016\/08\/figure38.1.jpg","datePublished":"2016-08-30T09:59:29+00:00","dateModified":"2018-06-22T14:26:24+00:00","description":"Visual basic 2015 tutorial","breadcrumb":{"@id":"http:\/\/www.vbtutor.net\/vb2015\/vb2015_lesson38.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["http:\/\/www.vbtutor.net\/vb2015\/vb2015_lesson38.html"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/www.vbtutor.net\/vb2015\/vb2015_lesson38.html#primaryimage","url":"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2016\/08\/figure38.1.jpg","contentUrl":"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2016\/08\/figure38.1.jpg","width":353,"height":158},{"@type":"BreadcrumbList","@id":"http:\/\/www.vbtutor.net\/vb2015\/vb2015_lesson38.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.vbtutor.net\/"},{"@type":"ListItem","position":2,"name":"Visual Basic 2015 Lesson 38: Building Console Application Part 2"}]},{"@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\/8522","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=8522"}],"version-history":[{"count":27,"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/pages\/8522\/revisions"}],"predecessor-version":[{"id":13054,"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/pages\/8522\/revisions\/13054"}],"wp:attachment":[{"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/media?parent=8522"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/categories?post=8522"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/tags?post=8522"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}