{"id":1336,"date":"2008-02-06T20:00:57","date_gmt":"2008-02-07T01:00:57","guid":{"rendered":"http:\/\/teamtutorials.com\/programming-tutorials\/simple-vb-code-command-buttons"},"modified":"2008-02-03T05:17:36","modified_gmt":"2008-02-03T10:17:36","slug":"simple-vb-code-command-buttons","status":"publish","type":"post","link":"https:\/\/teamtutorials.com\/programming-tutorials\/simple-vb-code-command-buttons","title":{"rendered":"Simple VB Code with Command Buttons"},"content":{"rendered":"

In this tutorial we will look into changing other controls in the command of varying buttons. I am trying to keep these VB tutorials quick and simple so that they are easy to understand and you are able to do this stuff enough to be able to remember it. First we need to create the form. I will post two pictures, one of the form showing what I called all the controls on the form, and one that shows the text that I applied to each one. In this tutorial I will be using panels to show the changes made. Since panels contain no text I can\u2019t put their names on them. I simply named them pnlXXXX (where XXXX is the same as the button below it Ex. The one on the left is pnlSize). <\/p>\n

Basic_VB_Programming_2_01<\/p>\n

Note: Make sure you make all 4 of the panels have a border style of FixedSingle under the properties menu. Now we can start adding the code to make these buttons do the changes we want to make. First lets program the exit button as it is the most simple to do. Remember, to start programming for a button, all we need to do is double-click on it in the GUI section. So, let\u2019s double click on our Exit button and add the word \u201cEnd\u201d to it as below:<\/p>\n

\r\n    Private Sub cmdExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdExit.Click\r\n        End\r\n    End Sub\r\n<\/pre>\n

Next we need to program the first panel to first change to a smaller size when we first click the button and then change back to normal when we click it again. To differentiate between which mode it is in we will use and if statement to check its current size. Double click on the Change Size button to start adding the code. All of my panels are a size of : \u201c66, 32\u201d \u2013 Shown as Width, Height. Add the code as shown below:<\/p>\n

\r\n    Private Sub cmdSize_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSize.Click\r\n        If pnlSize.Width = 66 Then\r\n            pnlSize.Width = 33\r\n        Else\r\n            pnlSize.Width = 66\r\n        End If\r\n    End Sub\r\n<\/pre>\n

The code simply checks to see if the panel is at its current width of 66 pixels and if it is, it changes it to 33 pixels. If it\u2019s not at 66 it must be 33 pixels and sets it back to 66. Next we need to code our color changing button. Note: Please set this panel\u2019s backcolor property to Red (once you clikc backcolor an option menu will come up, select the web optioni and go to red)before putting in the code. We are going to make this a little trickier by throwing in and ElseIf statement. I will explain after I show you the code:<\/p>\n

\r\n    Private Sub cmdColor_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdColor.Click\r\n        If pnlColor.BackColor = Color.Red Then\r\n            pnlColor.BackColor = Color.Blue\r\n        ElseIf pnlColor.BackColor = Color.Blue Then\r\n            pnlColor.BackColor = Color.Orange\r\n        Else\r\n            pnlColor.BackColor = Color.Red\r\n        End If\r\n    End Sub\r\n<\/pre>\n

This code is the same as the If statement that we had before in our previous tutorial but we added one more condition. This time the application checks to see if the box has the backcolor of red(If) and if it does it changes it to blue. If it is not Red then it checks to see if it is blue (Else If) and if it is it changes it to orange. If it is not red or blue it changes it to red (Else). This way it will make a continuous loop from Red to Blue to Orange. Our next button is going to change the border type of our panel. This is the code that should be place within the sub after double-clicking on the button:<\/p>\n

\r\n    Private Sub cmdBorder_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdBorder.Click\r\n        If pnlBorder.BorderStyle = BorderStyle.FixedSingle Then\r\n            pnlBorder.BorderStyle = BorderStyle.Fixed3D\r\n        ElseIf pnlBorder.BorderStyle = BorderStyle.Fixed3D Then\r\n            pnlBorder.BorderStyle = BorderStyle.None\r\n        Else\r\n            pnlBorder.BorderStyle = BorderStyle.FixedSingle\r\n        End If\r\n    End Sub\r\n<\/pre>\n

This code is similar to our previous button except we are doing it with borders. There are three types of border (well, two really and then no border). This section of code is checking to see if our panel has a borderstyle of FixedSingle (which is how it is starting) and if it is, sets it to have a style of Fixed3D (If). If it is not Fixedsingle it checks to see if it is Fixed3D, and changes it to none if it is (Else IF). If it is not FixedSingle or Fixed3D it changes it to FixedSingle (Else) Our next and last button is going to change the visibility of the form (Make is visible or not). Here is the code:<\/p>\n

\r\n    Private Sub cmdVisible_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdVisible.Click\r\n        If pnlVisible.Visible = True Then\r\n            pnlVisible.Visible = False\r\n        Else\r\n            pnlVisible.Visible = True\r\n        End If\r\n    End Sub\r\n<\/pre>\n

This code is not different from our others really. Visibility is known as a Boolean Type. It is either true or false. It is checking to see if the panel\u2019s visibility is currently set to true and if it is it sets it to false, otherwise it sets it to true. This should conclude the code of the tutorial. You should no be able to run the application and the button will make the panels do their respective tasks. If you have any questions please comment. Thanks for viewing. <\/p>\n","protected":false},"excerpt":{"rendered":"

This is the second tutorial in the beginners tutorials that will give you a basic insight into VB programming and lay the groundwork for you to be able to understand more advanced concepts. We will be working with modifying forms using command buttons.<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[25,26],"tags":[],"yoast_head":"\nSimple VB Code with Command Buttons<\/title>\n<meta name=\"description\" content=\"This is the second tutorial in the beginners tutorials that will give you a basic insight into VB programming and lay the groundwork for you to be able to understand more advanced concepts. We will be working with modifying forms using command buttons.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/teamtutorials.com\/programming-tutorials\/simple-vb-code-command-buttons\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Mike Maguire\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebSite\",\"@id\":\"https:\/\/teamtutorials.com\/#website\",\"url\":\"https:\/\/teamtutorials.com\/\",\"name\":\"Team Tutorials\",\"description\":\"Learn something new today\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/teamtutorials.com\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/teamtutorials.com\/programming-tutorials\/simple-vb-code-command-buttons#primaryimage\",\"inLanguage\":\"en-US\",\"url\":\"http:\/\/teamtutorials.com\/wp-content\/uploads\/2008\/02\/basic_vb_programming_2_01.jpg\",\"contentUrl\":\"http:\/\/teamtutorials.com\/wp-content\/uploads\/2008\/02\/basic_vb_programming_2_01.jpg\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/teamtutorials.com\/programming-tutorials\/simple-vb-code-command-buttons#webpage\",\"url\":\"https:\/\/teamtutorials.com\/programming-tutorials\/simple-vb-code-command-buttons\",\"name\":\"Simple VB Code with Command Buttons\",\"isPartOf\":{\"@id\":\"https:\/\/teamtutorials.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/teamtutorials.com\/programming-tutorials\/simple-vb-code-command-buttons#primaryimage\"},\"datePublished\":\"2008-02-07T01:00:57+00:00\",\"dateModified\":\"2008-02-03T10:17:36+00:00\",\"author\":{\"@id\":\"https:\/\/teamtutorials.com\/#\/schema\/person\/eb38d967529dbe49f7cbe082fd39105b\"},\"description\":\"This is the second tutorial in the beginners tutorials that will give you a basic insight into VB programming and lay the groundwork for you to be able to understand more advanced concepts. We will be working with modifying forms using command buttons.\",\"breadcrumb\":{\"@id\":\"https:\/\/teamtutorials.com\/programming-tutorials\/simple-vb-code-command-buttons#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/teamtutorials.com\/programming-tutorials\/simple-vb-code-command-buttons\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/teamtutorials.com\/programming-tutorials\/simple-vb-code-command-buttons#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/teamtutorials.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Simple VB Code with Command Buttons\"}]},{\"@type\":\"Person\",\"@id\":\"https:\/\/teamtutorials.com\/#\/schema\/person\/eb38d967529dbe49f7cbe082fd39105b\",\"name\":\"Mike Maguire\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/teamtutorials.com\/#personlogo\",\"inLanguage\":\"en-US\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/36f2aa9a11241ca79ed05e758e36f3cb?s=96&d=mm&r=r\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/36f2aa9a11241ca79ed05e758e36f3cb?s=96&d=mm&r=r\",\"caption\":\"Mike Maguire\"},\"sameAs\":[\"http:\/\/mikemaguire.me\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Simple VB Code with Command Buttons","description":"This is the second tutorial in the beginners tutorials that will give you a basic insight into VB programming and lay the groundwork for you to be able to understand more advanced concepts. We will be working with modifying forms using command buttons.","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":"https:\/\/teamtutorials.com\/programming-tutorials\/simple-vb-code-command-buttons","twitter_misc":{"Written by":"Mike Maguire","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebSite","@id":"https:\/\/teamtutorials.com\/#website","url":"https:\/\/teamtutorials.com\/","name":"Team Tutorials","description":"Learn something new today","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/teamtutorials.com\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"ImageObject","@id":"https:\/\/teamtutorials.com\/programming-tutorials\/simple-vb-code-command-buttons#primaryimage","inLanguage":"en-US","url":"http:\/\/teamtutorials.com\/wp-content\/uploads\/2008\/02\/basic_vb_programming_2_01.jpg","contentUrl":"http:\/\/teamtutorials.com\/wp-content\/uploads\/2008\/02\/basic_vb_programming_2_01.jpg"},{"@type":"WebPage","@id":"https:\/\/teamtutorials.com\/programming-tutorials\/simple-vb-code-command-buttons#webpage","url":"https:\/\/teamtutorials.com\/programming-tutorials\/simple-vb-code-command-buttons","name":"Simple VB Code with Command Buttons","isPartOf":{"@id":"https:\/\/teamtutorials.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/teamtutorials.com\/programming-tutorials\/simple-vb-code-command-buttons#primaryimage"},"datePublished":"2008-02-07T01:00:57+00:00","dateModified":"2008-02-03T10:17:36+00:00","author":{"@id":"https:\/\/teamtutorials.com\/#\/schema\/person\/eb38d967529dbe49f7cbe082fd39105b"},"description":"This is the second tutorial in the beginners tutorials that will give you a basic insight into VB programming and lay the groundwork for you to be able to understand more advanced concepts. We will be working with modifying forms using command buttons.","breadcrumb":{"@id":"https:\/\/teamtutorials.com\/programming-tutorials\/simple-vb-code-command-buttons#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/teamtutorials.com\/programming-tutorials\/simple-vb-code-command-buttons"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/teamtutorials.com\/programming-tutorials\/simple-vb-code-command-buttons#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/teamtutorials.com\/"},{"@type":"ListItem","position":2,"name":"Simple VB Code with Command Buttons"}]},{"@type":"Person","@id":"https:\/\/teamtutorials.com\/#\/schema\/person\/eb38d967529dbe49f7cbe082fd39105b","name":"Mike Maguire","image":{"@type":"ImageObject","@id":"https:\/\/teamtutorials.com\/#personlogo","inLanguage":"en-US","url":"https:\/\/secure.gravatar.com\/avatar\/36f2aa9a11241ca79ed05e758e36f3cb?s=96&d=mm&r=r","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/36f2aa9a11241ca79ed05e758e36f3cb?s=96&d=mm&r=r","caption":"Mike Maguire"},"sameAs":["http:\/\/mikemaguire.me"]}]}},"_links":{"self":[{"href":"https:\/\/teamtutorials.com\/wp-json\/wp\/v2\/posts\/1336"}],"collection":[{"href":"https:\/\/teamtutorials.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/teamtutorials.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/teamtutorials.com\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/teamtutorials.com\/wp-json\/wp\/v2\/comments?post=1336"}],"version-history":[{"count":0,"href":"https:\/\/teamtutorials.com\/wp-json\/wp\/v2\/posts\/1336\/revisions"}],"wp:attachment":[{"href":"https:\/\/teamtutorials.com\/wp-json\/wp\/v2\/media?parent=1336"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/teamtutorials.com\/wp-json\/wp\/v2\/categories?post=1336"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/teamtutorials.com\/wp-json\/wp\/v2\/tags?post=1336"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}