Post by Mechanical Jerk on Jan 29, 2004 4:37:07 GMT -5
This tutorial will work with both VB 5 and 6 and it’s only using the most basic of controls.
OK lets start VB, and well be creating a new exe. There are other options at this stage but these are a little to complicated to go into at the moment.
So now we have are blank form. This form is the blank “canvas” on which we are going to build are application. We build are application using the controls. These controls are accessed from the control library on the right hand side of the screen.
For now well just use the basic controls of:
Text Box
the text box allows us to enter information into it. With this information we can perfom various tasks.
Label
the label allows us to print text out to it.
Command Button
the command button allows us to attach click events to actions. A click event is an action that will occur when the button is pressed.
Okay so know we know what controls we will be using all we have to do is, add those controls to the form. To do this simply double click on the control and it will appear on the form. Then simply click (single not double, if you should happen to double click the control you will open the code window. Simply close this and return to the object window by press Shift & F7) the object and drag it around the form. It is also possible to click on the object and hold Ctrl and use the courser keys to navigate the object around the form.
Once we have the controls looking like this:
we can move on to the actual coding of the program.
Double click the command button. This will tell VB that we wish to use the click event of the button. The click event is the action that will be performed when the user clicks on the button during run time.
So double click on the button and we have the code window open up below:
As you can see we have “Command1_click” which tells us that this is the click event for the command 1 button. We also have “Private Sub”. Private Sub referes to the term sub rountine which is a action or set of actions performed within a main program. The private dosen’t really matter at the moment.
So anything we write between the “private sub” and “end sub” will be performed when the button is clicked (are click event).
So what do we want are program to do? Well lets start with something simple. We want our program to allow us to enter a word in the text box and when we click the button, we want it to print the contents of the text box to the label.
Having double clicked the command button we have said that we want to action to happen on the button click (we want the txt to be written on the button click remeber).
So we want:
The label to print the contents of the text box.
How do we write this a way the system will understand.
First we need to name the object in this case Label1, then call a parameter of that object (parameters are basicly looks styles of the objects, well come to them in another tutorial) in this case the parameter is the caption.
So we write “label1.caption”.
Next we need to say what we want of caption of label1. what do we want? We want it to be equal (the same) as the contents of the text box.
So “label1.caption = text1.text”
We call the object “text1” and call the parameter “text”. The equal works in the same way as the mathematical symbol.
So we should have the full code looking like this:
next all we need to do is run and the program. This is easy enough simple click the play button.
then enter simply enter the text you want in the text box and click the button to see what happens.
OK lets start VB, and well be creating a new exe. There are other options at this stage but these are a little to complicated to go into at the moment.
So now we have are blank form. This form is the blank “canvas” on which we are going to build are application. We build are application using the controls. These controls are accessed from the control library on the right hand side of the screen.
For now well just use the basic controls of:
Text Box
the text box allows us to enter information into it. With this information we can perfom various tasks.
Label
the label allows us to print text out to it.
Command Button
the command button allows us to attach click events to actions. A click event is an action that will occur when the button is pressed.
Okay so know we know what controls we will be using all we have to do is, add those controls to the form. To do this simply double click on the control and it will appear on the form. Then simply click (single not double, if you should happen to double click the control you will open the code window. Simply close this and return to the object window by press Shift & F7) the object and drag it around the form. It is also possible to click on the object and hold Ctrl and use the courser keys to navigate the object around the form.
Once we have the controls looking like this:
we can move on to the actual coding of the program.
Double click the command button. This will tell VB that we wish to use the click event of the button. The click event is the action that will be performed when the user clicks on the button during run time.
So double click on the button and we have the code window open up below:
As you can see we have “Command1_click” which tells us that this is the click event for the command 1 button. We also have “Private Sub”. Private Sub referes to the term sub rountine which is a action or set of actions performed within a main program. The private dosen’t really matter at the moment.
So anything we write between the “private sub” and “end sub” will be performed when the button is clicked (are click event).
So what do we want are program to do? Well lets start with something simple. We want our program to allow us to enter a word in the text box and when we click the button, we want it to print the contents of the text box to the label.
Having double clicked the command button we have said that we want to action to happen on the button click (we want the txt to be written on the button click remeber).
So we want:
The label to print the contents of the text box.
How do we write this a way the system will understand.
First we need to name the object in this case Label1, then call a parameter of that object (parameters are basicly looks styles of the objects, well come to them in another tutorial) in this case the parameter is the caption.
So we write “label1.caption”.
Next we need to say what we want of caption of label1. what do we want? We want it to be equal (the same) as the contents of the text box.
So “label1.caption = text1.text”
We call the object “text1” and call the parameter “text”. The equal works in the same way as the mathematical symbol.
So we should have the full code looking like this:
next all we need to do is run and the program. This is easy enough simple click the play button.
then enter simply enter the text you want in the text box and click the button to see what happens.