In today's tutorial I am going to be showing you how to declare and use string variables in visual basic 2010. The very basics of what you need to know about string variables are it will store a string of characters with a label name which you can then call upon later on in your programme. This can save you time as it reduces the amount of code you will have to write.
First of I want you to open up visual basic, you should have this already download and know the basic layout out of the program. You then need to set up a new project and call it "learning to use string variables". Once the form designer has opened up you will need to add one text box and one button. Change the text of button one to "clear text". Your form should look like this:
Once you have the form to look like this you will now open the coding screen to control what each component will do in your form. You should have learnt how to open the coding screen in my previous tutorials. Here the code you will need to write once you have written it we will do a run through of what it actually means.
Now that we have the code in I want you to debug the program and check that it works if not please recheck you have written the code in correctly. Now for the rundown, "Dim text as string" is basically saying to declare the word "text" as a string which is only characters. "text = textbox1.text" is assigning a value to the newly declared variable called "text" in this case the value is the text in textbox1.text. Next the code erases what was in textbox1.text this is to prove to you that our variable is truly stored. "messagebox.show(text)" is the clever bit. This is where we create a messagebox to display the value of our string variable.
And there you have it you have now learnt how to declare and use string variables in visual basic. Stay tuned for more tutorials. Also check out my own website here.
0 comments:
Post a Comment