{"id":5852,"date":"2015-03-18T17:17:00","date_gmt":"2015-03-18T09:17:00","guid":{"rendered":"http:\/\/www.vbtutor.net\/?page_id=5852"},"modified":"2018-06-22T16:19:46","modified_gmt":"2018-06-22T08:19:46","slug":"visual-basic-2015-lesson-5-working-controls","status":"publish","type":"page","link":"https:\/\/www.vbtutor.net\/index.php\/visual-basic-2015-lesson-5-working-controls\/","title":{"rendered":"Visual Basic 2015 Lesson 5: Working with Controls"},"content":{"rendered":"<h4 style=\"text-align: center;\"><strong><a title=\"visual basic 2015 Lesson 4\" href=\"http:\/\/www.vbtutor.net\/index.php\/visual-basic-2015-lesson-4-writing-code\/\">[Lesson 4]<\/a>&lt;&lt;<a title=\"Visual Basic 2015\" href=\"http:\/\/www.vbtutor.net\/index.php\/visual-basic-2015-tutorial\/\">[Contents]<\/a>&gt;&gt;<a title=\"visual basic 2015 lesson 6\" href=\"http:\/\/www.vbtutor.net\/index.php\/visual-basic-2015-lesson-6-list-box-combo-box\/\">[Lesson 6]<\/a><\/strong><\/h4>\n<h3>5.1 TextBox<\/h3>\n<p>In this lesson, we shall learn how to work with some common controls in Visual Basic 2015. Among the commonly used controls are the label, text box, button, list box, combo box, picture box, timer and more. However, in this lesson, we shall only deal with the text box and the label. The text box is for accepting input from the user as well as to display the output. It can only handle string (text) and numeric data .\u00a0String in a text box can be converted to a numeric data by using the function Val(text).<\/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<h4><b>Example 5.1<\/b><\/h4>\n<p>The following program will add the value in text box 1 and the value in text box 2 and output the sum in a message box.<\/p>\n<pre style=\"font-size: 110%;\">Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click\r\nMsgBox(\"The sum is \"&amp;Val(TextBox1.Text) + Val(TextBox2.Text))\r\nEnd Sub\r\n<\/pre>\n<p>The output window:<\/p>\n<p style=\"text-align: center;\"><a href=\"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2015\/03\/vb2015_fig5.01.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-5888\" src=\"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2015\/03\/vb2015_fig5.01.jpg\" alt=\"vb2015_fig5.01\" width=\"300\" height=\"300\" srcset=\"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2015\/03\/vb2015_fig5.01.jpg 300w, https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2015\/03\/vb2015_fig5.01-150x150.jpg 150w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><strong>Figure 5.1<\/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<p style=\"text-align: left;\">After clicking Add button, you can get the answer in a message box, as shown in Figure 5.2:<\/p>\n<p style=\"text-align: left;\"><a href=\"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2015\/03\/vb2015_fig5.02.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-5889\" src=\"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2015\/03\/vb2015_fig5.02.jpg\" alt=\"vb2015_fig5.02\" width=\"154\" height=\"155\" srcset=\"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2015\/03\/vb2015_fig5.02.jpg 154w, https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2015\/03\/vb2015_fig5.02-150x150.jpg 150w\" sizes=\"auto, (max-width: 154px) 100vw, 154px\" \/><\/a><\/p>\n<p style=\"text-align: center;\"><strong>Figure 5.2<\/strong><\/p>\n<hr style=\"border: 1px solid blue;\" \/>\n<div><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><\/div>\n<p>&nbsp;<\/p>\n<h3><strong>5.2 The Label<\/strong><\/h3>\n<p>The label in Visual Basic \u00a02015 can be used to provide instructions to the user as well as to display the outputs. It is different from text box because it can only display static text, which means the user cannot change the text.\u00a0 By using the syntax Label.Text, it can display text and numeric data.\u00a0 On the other hand, you can also change its text in the properties window and also at runtime.<\/p>\n<h4><strong>Example 5.2<\/strong><\/h4>\n<p>In this visual basic 2015 program, instead of showing the sum in a message box, we wish to display the sum on a label. This a simple calculator program that can calculate the sum of\u00a0two numbers entered by the user. To design the interface, \u00a0you add two text boxes, three\u00a0labels and a button on the form. Under the respective properties windows, change the name of the first text box to <strong>txtNum1<\/strong> and the name of the second textbox to<strong> txtNum2<\/strong>.<\/p>\n<p>Next, change the text of the first label to +,\u00a0the text of the second label to =. For the third label, change the autosize property to false and the name to <strong>LblAns<\/strong>. Drag the third label to appropriate size and set its background to yellow color. For the button, change its name to <strong>BtnCal<\/strong> and its text to Calculate. \u00a0Lastly, change the text of the form to Simple Calculator. The two text boxes are used to accept inputs from the user.\u00a0 We programmed the button to\u00a0calculate the sum of the two numbers using the plus operator.<\/p>\n<h4><strong>The Code<\/strong><\/h4>\n<pre style=\"font-size: 110%;\">Public Class Form1\r\nPrivate Sub BtnCal_Click(sender As Object, e As EventArgs) Handles BtnCal.Click\r\nDim num1 As Single = Val(TxtNum1.Text)\r\nDim num2 As Single = Val(TxtNum2.Text)\r\nDim Sum As Single = num1 + num2\r\nLblAns.Text = Sum.ToString\r\n\r\nEnd Sub\r\nEnd Class\r\n<\/pre>\n<p>The<strong> Dim<\/strong> keyword is to declare a number as a single precision number and the function Val is to convert a string to a number. In addition, the method<strong> ToString<\/strong> is to display an output as a string. We shall learn more about <strong>Dim<\/strong> in a later lesson.<\/p>\n<p>The output window:<\/p>\n<p style=\"text-align: center;\"><a href=\"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2015\/03\/vb2015_fig5.1.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-5856\" src=\"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2015\/03\/vb2015_fig5.1.jpg\" alt=\"vb2015_fig5.1\" width=\"386\" height=\"300\" srcset=\"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2015\/03\/vb2015_fig5.1.jpg 386w, https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2015\/03\/vb2015_fig5.1-300x233.jpg 300w\" sizes=\"auto, (max-width: 386px) 100vw, 386px\" \/><\/a><strong>Figure 5.3<\/strong><\/p>\n<div><script async src=\"\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js\"><\/script><br \/>\n<!-- vb2015 tutorial matched content --><br \/>\n<ins class=\"adsbygoogle\" style=\"display: block;\" data-ad-client=\"ca-pub-3033628290023372\" data-ad-slot=\"5090773108\" data-ad-format=\"autorelaxed\"><\/ins><br \/>\n<script>\n(adsbygoogle = window.adsbygoogle || []).push({});\n<\/script><\/div>\n<h4 style=\"text-align: center;\">\u00a0<strong><a title=\"visual basic 2015 Lesson 4\" href=\"http:\/\/www.vbtutor.net\/index.php\/visual-basic-2015-lesson-4-writing-code\/\">[Lesson 4]<\/a>&lt;&lt;<a title=\"Visual Basic 2015\" href=\"http:\/\/www.vbtutor.net\/index.php\/visual-basic-2015-tutorial\/\">[Contents]<\/a>&gt;&gt;<\/strong><strong><a title=\"visual basic 2015 lesson 6\" href=\"http:\/\/www.vbtutor.net\/index.php\/visual-basic-2015-lesson-6-list-box-combo-box\/\">[Lesson 6]<\/a><\/strong><\/h4>\n","protected":false},"excerpt":{"rendered":"<p>[Lesson 4]&lt;&lt;[Contents]&gt;&gt;[Lesson 6] 5.1 TextBox In this lesson, we shall learn how to work with some common controls in Visual Basic 2015. Among the commonly used controls are the label, text box, button, list box, combo box, picture box, timer and more. However, in this lesson, we shall only deal with the text box and &hellip; <a href=\"https:\/\/www.vbtutor.net\/index.php\/visual-basic-2015-lesson-5-working-controls\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Visual Basic 2015 Lesson 5: Working with Controls<\/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-5852","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 5: Working with Controls - Learn Visual Basic Programming \u2013 VB.NET, VBA &amp; Classic VB<\/title>\n<meta name=\"description\" content=\"This article discuss how to work with controls 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_lesson5.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 5: Working with Controls - Learn Visual Basic Programming \u2013 VB.NET, VBA &amp; Classic VB\" \/>\n<meta property=\"og:description\" content=\"This article discuss how to work with controls in visual basic 2015\" \/>\n<meta property=\"og:url\" content=\"http:\/\/www.vbtutor.net\/vb2015\/vb2015_lesson5.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-22T08:19:46+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2015\/03\/vb2015_fig5.01.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-5-working-controls\/\",\"url\":\"http:\/\/www.vbtutor.net\/vb2015\/vb2015_lesson5.html\",\"name\":\"Visual Basic 2015 Lesson 5: Working with Controls - 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_lesson5.html#primaryimage\"},\"image\":{\"@id\":\"http:\/\/www.vbtutor.net\/vb2015\/vb2015_lesson5.html#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2015\/03\/vb2015_fig5.01.jpg\",\"datePublished\":\"2015-03-18T09:17:00+00:00\",\"dateModified\":\"2018-06-22T08:19:46+00:00\",\"description\":\"This article discuss how to work with controls in visual basic 2015\",\"breadcrumb\":{\"@id\":\"http:\/\/www.vbtutor.net\/vb2015\/vb2015_lesson5.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"http:\/\/www.vbtutor.net\/vb2015\/vb2015_lesson5.html\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/www.vbtutor.net\/vb2015\/vb2015_lesson5.html#primaryimage\",\"url\":\"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2015\/03\/vb2015_fig5.01.jpg\",\"contentUrl\":\"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2015\/03\/vb2015_fig5.01.jpg\",\"width\":300,\"height\":300},{\"@type\":\"BreadcrumbList\",\"@id\":\"http:\/\/www.vbtutor.net\/vb2015\/vb2015_lesson5.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.vbtutor.net\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Visual Basic 2015 Lesson 5: Working with Controls\"}]},{\"@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 5: Working with Controls - Learn Visual Basic Programming \u2013 VB.NET, VBA &amp; Classic VB","description":"This article discuss how to work with controls 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_lesson5.html","og_locale":"en_US","og_type":"article","og_title":"Visual Basic 2015 Lesson 5: Working with Controls - Learn Visual Basic Programming \u2013 VB.NET, VBA &amp; Classic VB","og_description":"This article discuss how to work with controls in visual basic 2015","og_url":"http:\/\/www.vbtutor.net\/vb2015\/vb2015_lesson5.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-22T08:19:46+00:00","og_image":[{"url":"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2015\/03\/vb2015_fig5.01.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-5-working-controls\/","url":"http:\/\/www.vbtutor.net\/vb2015\/vb2015_lesson5.html","name":"Visual Basic 2015 Lesson 5: Working with Controls - 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_lesson5.html#primaryimage"},"image":{"@id":"http:\/\/www.vbtutor.net\/vb2015\/vb2015_lesson5.html#primaryimage"},"thumbnailUrl":"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2015\/03\/vb2015_fig5.01.jpg","datePublished":"2015-03-18T09:17:00+00:00","dateModified":"2018-06-22T08:19:46+00:00","description":"This article discuss how to work with controls in visual basic 2015","breadcrumb":{"@id":"http:\/\/www.vbtutor.net\/vb2015\/vb2015_lesson5.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["http:\/\/www.vbtutor.net\/vb2015\/vb2015_lesson5.html"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/www.vbtutor.net\/vb2015\/vb2015_lesson5.html#primaryimage","url":"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2015\/03\/vb2015_fig5.01.jpg","contentUrl":"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2015\/03\/vb2015_fig5.01.jpg","width":300,"height":300},{"@type":"BreadcrumbList","@id":"http:\/\/www.vbtutor.net\/vb2015\/vb2015_lesson5.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.vbtutor.net\/"},{"@type":"ListItem","position":2,"name":"Visual Basic 2015 Lesson 5: Working with Controls"}]},{"@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\/5852","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=5852"}],"version-history":[{"count":76,"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/pages\/5852\/revisions"}],"predecessor-version":[{"id":13021,"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/pages\/5852\/revisions\/13021"}],"wp:attachment":[{"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/media?parent=5852"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/categories?post=5852"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/tags?post=5852"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}