{"id":4182,"date":"2014-01-07T11:54:30","date_gmt":"2014-01-07T03:54:30","guid":{"rendered":"http:\/\/www.vbtutor.net\/?page_id=4182"},"modified":"2018-06-23T11:43:39","modified_gmt":"2018-06-23T03:43:39","slug":"working-with-controls","status":"publish","type":"page","link":"https:\/\/www.vbtutor.net\/index.php\/working-with-controls\/","title":{"rendered":"Visual Basic 2013 Lesson 5: Working with Controls"},"content":{"rendered":"<h4 style=\"text-align: center;\"><a href=\"http:\/\/www.vbtutor.net\/index.php\/writing-the-vb-code\/\">[Lesson 4] <\/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-6-working-with-list-box-and-combo-box\/\">[Lesson 6]<\/a><\/h4>\n<p>In the previous lesson, you\u00a0have learned how to write simple Visual Basic 2013 code. In this lesson, you\u00a0will learn how to work with some common controls and write codes for them. Some of the common controls are the label, text box, button, list box and the combo box. However, in this lesson, you will\u00a0only deal with the text box and the label, you\u00a0shall learn how to work other\u00a0controls in later lessons.<\/p>\n<h3>5.1 The TextBox<\/h3>\n<p>The textbox is the standard control for receiving input from the user. It can also be used to display the output. It can only handle string (text) and numeric data but not images or pictures. By the way, a string in a text box can be converted to a numeric data by using the <strong>function Val(text)<\/strong>. The following example illustrates a simple program that processes the input from the user.<\/p>\n<h4>Example 5.1<\/h4>\n<p>In this program, you add two text boxes and a button on the form. The two text boxes are used to accept inputs from the user. Besides, a button is also programmed to calculate the sum of the two numbers using the plus operator. The value enters into a text box is stored using the syntax Textbox1.Text, where Text is one of the properties of the textbox.<\/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=\"3914691604\"><\/ins><br \/>\n<script>\n     (adsbygoogle = window.adsbygoogle || []).push({});\n<\/script><\/p>\n<p>The following program will add the value in text box 1 and 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\n MsgBox(The sum is &amp; Val(TextBox1.Text) + Val(TextBox2.Text))\r\nEnd Sub\r\n<\/pre>\n<p>The output window:<\/p>\n<p><a href=\"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2014\/01\/vb2013_figure5.1.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4190\" src=\"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2014\/01\/vb2013_figure5.1.jpg\" alt=\"vb2013_figure5.1\" width=\"300\" height=\"300\" \/><\/a><br \/>\n<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=\"3914691604\"><\/ins><br \/>\n<script>\n     (adsbygoogle = window.adsbygoogle || []).push({});\n<\/script><\/p>\n<p><strong>Figure 5.1<\/strong><\/p>\n<p>After clicking Add button, you can get the answer in a message box, as shown in Figure 5.2:<\/p>\n<p><a href=\"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2014\/01\/vb2013_figure5.2.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4194\" src=\"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2014\/01\/vb2013_figure5.2.jpg\" alt=\"vb2013_figure5.2\" width=\"154\" height=\"155\" \/><\/a><\/p>\n<p><strong>\u00a0Figure 5.2\u00a0<\/strong><\/p>\n<h3>5.2 The Label<\/h3>\n<p>The label is not only used to provide instructions and guides to the users, it can also be used to display outputs. It is different from text box because it can only display static text, which means the user cannot change the text. Using the syntax Label.Text, it can display text and numeric data. You can change its text in the properties window and also at runtime.<\/p>\n<p><strong>Example 5.2<\/strong><\/p>\n<p>Based on Example 5.1, you now add two labels, one is to display the text Sum= and the other label is to display the answer of the Sum. For the first label, change the text property of the label by typing Sum= over the default text Label1. Further, change its font to bold and font size to 10. For the second label, delete the default text Label2 and change its font to bold and font size to 10. Besides that, change its background color to white.<\/p>\n<p>In this program, instead of showing the sum in a message box, we wish to display the sum on the label.<\/p>\n<p><strong>The Code<\/strong><\/p>\n<pre style=\"font-size: 110%;\">Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click\r\n Label2.Text = Val(TextBox1.Text) + Val(TextBox2.Text)\r\nEnd Sub\r\n<\/pre>\n<p>*The function Val is to convert text to a\u00a0numeric value. Without using Val, you will see that two numbers are joined together without adding them.<\/p>\n<p>The output is as shown in Figure 5.3<\/p>\n<p align=\"center\"><a href=\"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2014\/01\/vb2013_figure-5.3.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4207\" src=\"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2014\/01\/vb2013_figure-5.3.jpg\" alt=\"vb2013_figure 5.3\" width=\"300\" height=\"300\" \/><\/a><\/p>\n<h4 align=\"center\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 Figure 5.3<\/h4>\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=\"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\/writing-the-vb-code\/\">[Lesson 4]\u00a0<\/a>&lt;&lt;\u00a0<a href=\"http:\/\/www.vbtutor.net\/index.php\/visual-basic-2013-tutorial\/\">[Contents]\u00a0<\/a>&gt;&gt; <a href=\"http:\/\/www.vbtutor.net\/index.php\/visual-basic-2013-lesson-6-working-with-list-box-and-combo-box\/\">[Lesson 6]<\/a><\/h4>\n","protected":false},"excerpt":{"rendered":"<p>[Lesson 4] &lt;&lt; [Contents] &gt;&gt; [Lesson 6] In the previous lesson, you\u00a0have learned how to write simple Visual Basic 2013 code. In this lesson, you\u00a0will learn how to work with some common controls and write codes for them. Some of the common controls are the label, text box, button, list box and the combo box. &hellip; <a href=\"https:\/\/www.vbtutor.net\/index.php\/working-with-controls\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Visual Basic 2013 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-4182","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 5: Working with Controls - Learn Visual Basic Programming \u2013 VB.NET, VBA &amp; Classic VB<\/title>\n<meta name=\"description\" content=\"The lesson discusses the usage of two controls, namely text box and label in 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_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 2013 Lesson 5: Working with Controls - Learn Visual Basic Programming \u2013 VB.NET, VBA &amp; Classic VB\" \/>\n<meta property=\"og:description\" content=\"The lesson discusses the usage of two controls, namely text box and label in Visual Basic 2013\" \/>\n<meta property=\"og:url\" content=\"http:\/\/www.vbtutor.net\/vb2013\/vb2013_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-23T03:43:39+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2014\/01\/vb2013_figure5.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=\"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\/working-with-controls\/\",\"url\":\"http:\/\/www.vbtutor.net\/vb2013\/vb2013_lesson5.html\",\"name\":\"Visual Basic 2013 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\/vb2013\/vb2013_lesson5.html#primaryimage\"},\"image\":{\"@id\":\"http:\/\/www.vbtutor.net\/vb2013\/vb2013_lesson5.html#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2014\/01\/vb2013_figure5.1.jpg\",\"datePublished\":\"2014-01-07T03:54:30+00:00\",\"dateModified\":\"2018-06-23T03:43:39+00:00\",\"description\":\"The lesson discusses the usage of two controls, namely text box and label in Visual Basic 2013\",\"breadcrumb\":{\"@id\":\"http:\/\/www.vbtutor.net\/vb2013\/vb2013_lesson5.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"http:\/\/www.vbtutor.net\/vb2013\/vb2013_lesson5.html\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/www.vbtutor.net\/vb2013\/vb2013_lesson5.html#primaryimage\",\"url\":\"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2014\/01\/vb2013_figure5.1.jpg\",\"contentUrl\":\"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2014\/01\/vb2013_figure5.1.jpg\",\"width\":300,\"height\":300},{\"@type\":\"BreadcrumbList\",\"@id\":\"http:\/\/www.vbtutor.net\/vb2013\/vb2013_lesson5.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.vbtutor.net\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Visual Basic 2013 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 2013 Lesson 5: Working with Controls - Learn Visual Basic Programming \u2013 VB.NET, VBA &amp; Classic VB","description":"The lesson discusses the usage of two controls, namely text box and label in 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_lesson5.html","og_locale":"en_US","og_type":"article","og_title":"Visual Basic 2013 Lesson 5: Working with Controls - Learn Visual Basic Programming \u2013 VB.NET, VBA &amp; Classic VB","og_description":"The lesson discusses the usage of two controls, namely text box and label in Visual Basic 2013","og_url":"http:\/\/www.vbtutor.net\/vb2013\/vb2013_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-23T03:43:39+00:00","og_image":[{"url":"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2014\/01\/vb2013_figure5.1.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\/working-with-controls\/","url":"http:\/\/www.vbtutor.net\/vb2013\/vb2013_lesson5.html","name":"Visual Basic 2013 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\/vb2013\/vb2013_lesson5.html#primaryimage"},"image":{"@id":"http:\/\/www.vbtutor.net\/vb2013\/vb2013_lesson5.html#primaryimage"},"thumbnailUrl":"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2014\/01\/vb2013_figure5.1.jpg","datePublished":"2014-01-07T03:54:30+00:00","dateModified":"2018-06-23T03:43:39+00:00","description":"The lesson discusses the usage of two controls, namely text box and label in Visual Basic 2013","breadcrumb":{"@id":"http:\/\/www.vbtutor.net\/vb2013\/vb2013_lesson5.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["http:\/\/www.vbtutor.net\/vb2013\/vb2013_lesson5.html"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/www.vbtutor.net\/vb2013\/vb2013_lesson5.html#primaryimage","url":"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2014\/01\/vb2013_figure5.1.jpg","contentUrl":"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2014\/01\/vb2013_figure5.1.jpg","width":300,"height":300},{"@type":"BreadcrumbList","@id":"http:\/\/www.vbtutor.net\/vb2013\/vb2013_lesson5.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.vbtutor.net\/"},{"@type":"ListItem","position":2,"name":"Visual Basic 2013 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\/4182","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=4182"}],"version-history":[{"count":63,"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/pages\/4182\/revisions"}],"predecessor-version":[{"id":13060,"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/pages\/4182\/revisions\/13060"}],"wp:attachment":[{"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/media?parent=4182"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/categories?post=4182"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/tags?post=4182"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}