Our Pages
Download Free HTML Guide E-Book!
Friday, June 3, 2011
Visual Basic 2008 Tutorial 1 - Basics
Posted on 10:36 AM by Ram Sidh
This tutorial can be found as a video tutorial at our video channel, and some more details and examples can be found in the video itself. With this Visual Basic tutorial, we start the basic foundations required to start creating your own Windows applications, programs and software.
In this article we'll discuss two specific topics, creating strings and variables in VB 2008. So, naturally, we first open up the program itself and then we create a new project and choose it as a Windows Application. We name it whatever we want, and then click OK, which automatically opens up the 'Form1' tab.
You can now edit this 'Form1' by changing options within the Properties tab towards the bottom-left of your screen. You can change the title of the Form by inserting your custom text inside the 'Text' property. You can also change the Form's icon by choosing your .ico file from the 'Icon' property.
We won't go into too many details here, since the properties tab is very easy to understand. We'll quickly move into the code of the program. So basically, we're going to present the concept of strings & variables in the example of a Message Box application.
What is a Message Box?
A message box is basically a program with a button, when clicked opens up a separate dialog box presenting the specific message to the viewer. Now, where does a string come into all of this?
Strings, as you might be knowing, are always written within double-quotations, and are the text that shows up as the message we want. But how do we command the application to open up a specific message box containing the specific text as the string? We do that using code naturally.
So first, we add a button to the form by going into the Tools and dragging and dropping the 'Button' to the space inside the form. There we adjust the size and position using the various handles present, and then we can change its style by going into the properties tab. Then we double-click the button which will open up a new tab which contains the basic code of that 'button' element. Most of the code will already be automatically entered as we transition into the 'code' tab, we only need to write in the code that gives the specific commands to the program.
So here is the code we write in after we double-click the button, an explanation will be there below it:
MessageBox.Show("My name is Ram!")
So, we created the command that, whenever the button is clicked, it is commanded to 'show' the 'message box' with the text 'My name is Ram!' which is a STRING, which is the reason why it is written between double-quotations. The dot and the parenthesis' are part of the syntax of Visual Basic code. You'll be able to understand it as you progress through the tutorials. Visual Basic syntax is somewhat similar to JavaScript.
We can also alter this basic statement by creating a variable for the STRING and just insert it into the code. So here's the code and below it is the explanation:
Dim messagecontent As String = "My name is Ram!"
MessageBox.Show(messagecontent)
So we used the 'Dim' command to specify a name for our STRING, which can be anything, anything at all. If you have some basic knowledge of CSS & HTML, you'll recognize that this situation is similar to creating 'id''s within HTML and their respective identifications in the CSS document. Then we declare that the name we've created for our STRING is used for a STRING, and not an INTEGER, which is represented as being a negative, zero or positive number. Following that, we write in the text we want displayed.
And then we say we want to have a message box displayed upon the clicking of the button and instead of a string, we add in the name we've created for our content. This 'name' is called a VARIABLE in Visual Basic 2008.
That is it for this tutorial, more tutorials coming up soon later on!
Thanks!
In this article we'll discuss two specific topics, creating strings and variables in VB 2008. So, naturally, we first open up the program itself and then we create a new project and choose it as a Windows Application. We name it whatever we want, and then click OK, which automatically opens up the 'Form1' tab.
You can now edit this 'Form1' by changing options within the Properties tab towards the bottom-left of your screen. You can change the title of the Form by inserting your custom text inside the 'Text' property. You can also change the Form's icon by choosing your .ico file from the 'Icon' property.
We won't go into too many details here, since the properties tab is very easy to understand. We'll quickly move into the code of the program. So basically, we're going to present the concept of strings & variables in the example of a Message Box application.
What is a Message Box?
A message box is basically a program with a button, when clicked opens up a separate dialog box presenting the specific message to the viewer. Now, where does a string come into all of this?
Strings, as you might be knowing, are always written within double-quotations, and are the text that shows up as the message we want. But how do we command the application to open up a specific message box containing the specific text as the string? We do that using code naturally.
So first, we add a button to the form by going into the Tools and dragging and dropping the 'Button' to the space inside the form. There we adjust the size and position using the various handles present, and then we can change its style by going into the properties tab. Then we double-click the button which will open up a new tab which contains the basic code of that 'button' element. Most of the code will already be automatically entered as we transition into the 'code' tab, we only need to write in the code that gives the specific commands to the program.
So here is the code we write in after we double-click the button, an explanation will be there below it:
MessageBox.Show("My name is Ram!")
So, we created the command that, whenever the button is clicked, it is commanded to 'show' the 'message box' with the text 'My name is Ram!' which is a STRING, which is the reason why it is written between double-quotations. The dot and the parenthesis' are part of the syntax of Visual Basic code. You'll be able to understand it as you progress through the tutorials. Visual Basic syntax is somewhat similar to JavaScript.
We can also alter this basic statement by creating a variable for the STRING and just insert it into the code. So here's the code and below it is the explanation:
Dim messagecontent As String = "My name is Ram!"
MessageBox.Show(messagecontent)
So we used the 'Dim' command to specify a name for our STRING, which can be anything, anything at all. If you have some basic knowledge of CSS & HTML, you'll recognize that this situation is similar to creating 'id''s within HTML and their respective identifications in the CSS document. Then we declare that the name we've created for our STRING is used for a STRING, and not an INTEGER, which is represented as being a negative, zero or positive number. Following that, we write in the text we want displayed.
And then we say we want to have a message box displayed upon the clicking of the button and instead of a string, we add in the name we've created for our content. This 'name' is called a VARIABLE in Visual Basic 2008.
That is it for this tutorial, more tutorials coming up soon later on!
Thanks!
Subscribe to:
Post Comments (Atom)
No Response to "Visual Basic 2008 Tutorial 1 - Basics"
Leave A Reply