Visual Basic: Textboxes and Comments
Textboxes are very useful tools in applications.
To add a textbox to your form, simply find "Textbox" in your toolbox, and drag it onto your form (window).
Once this is done you can use the input from the textbox later in the program - for example let's say that when a button is pressed we want the Textbox text to go into a string variable.
First of all make sure that you have a Textbox and Button on your form.
Just double click on the button to bring up the "button_click" code.
Type something like the following:
Dim TextBoxText As String TextBoxText = TextBox1.Text
The above simply creates a variable called TextBoxText which can contain string values, and then gets the string from the textbox and puts it into the variable (using ".Text" simply gets the object "TextBox1"(the object name is set in the properties panel)'s text).
If we really wanted we could then set our textbox text to something to show that we have saved what they typed:
TextBox1.Text = "Input registered"
In VB, like many other languages we often want to comment our code.
To create comments in visual Basic you use apostrophes (This-> ') at the start of the comment. For example:
' This is a comment
Comments are really useful when creating programs, as they allow someone else to look at your code (or y ou to come back to your code after a break) and understand how and why everything works.
Unfortunately you cant do multi-line comments in Visual Basic, so you have to do apostrophes at the start of each line (it's worth the hassle).
Here is an example of the code we used previously, commented:
Dim TextBoxText As String 'Create a string variable TextBoxText = TextBox1.Text 'Set our string variable to Textbox1's text TextBox1.Text = "Input registered" 'Set the textbox text to tell the user that their input was stored
Back to Visual Basic

