DoxCoding.com
Well hello.
I havn't done a Article in ages. And didn't really plan on doing anymore.
So i'm only doing this because am too darn bored, 
Anyway, it will only be nice, simple and quick.
It's about Visual Basic 6, Hence the VB in the title.
First we will make a Hello World Message box.
We will make it a critical message box. 
So first of all.
Go to Visual Basic 6, You will be congronted with a small dialog box.
There will be many methods of creating a new project, but for this sake, click Standard Exe.
Ok, Now. To the sort of fun part.
Place a Button onto your form,
Double click that button. And you should enter into the code view.
Now for some more fun, and get coding.
Unfortunately, because this is the first program you will do, it wont be very long, and will in a sense, be pointless.
But without further ado, i will get you going.
Within the,
Private Sub Command1_Click()
End Sub
Enter,
MsgBox "Hello, World", vbCritical, "hello"
Now to the explaining part, boooooooooooooring. But you must read this,
The code is a little basic, and self explanitory.
But will clear things out.
MsgBox, This command will start the Message Box, anything following it, in the correct format of course, will be shown somewhere withing that message box.
"Hello, World", this part will be the main part, This will print out Hello World onto the message box.
,vbCritical, This, Yes, When shown will make a little noise . But this will also place a small image, to the left of the Hello World text, showing it is a critical message, If we changed this to ' vbQuestion ' it will place a question mark simble to the left hand side.
Then finally...
"hello", this will be the title bar of the message bar. As you can see, the message bar will say hello.
There are other commands you can add into the message box.
For example you can add in what type of buttons to add.
For the second part of this tutorial.
Create a new project, Standard Exe again.
This time add the following.
1 x Label
1 x Button.
Place them wherever you like.
I will shoot through this, as i have explained above etc. I will still explain though ;)
So, double click the button.
Enter,
Label1.Caption = "Hello, World"
So within that button, your code should now look like this...
Private Sub Command1_Click()
Label1.Caption = "Hello, World"
End Sub
It is wise to tab out you work, in any language. PHP and VB, and C++, whatever.
Just to keep a track of what you are doing.
It also a good idea to comment your work, tell yourself what that part is doing.
Lets add a comment into that code above.
Private Sub Command1_Click()
Label1.Caption = "Hello, World" 'This will change label1 text to Hello, World
End Sub
Now to explain this, very quick, as again, it is self explanitory.
Label1.Caption is the name of the Label. Caption is what is inside.
For example. A Textbox would be.
Text1.Text, as it is text inside. But i will not go into that, you can try it with a textbox too, after you have done it with a label.
So...
Label1 -> Name
.Caption -> Whats inside.
Next
= -> Sets the caption to...
Finally
"Hello World" -> Set text into the caption (label1)
Well. I said it would be simple.
Nice and easy to follow. (I hope).
Well. Laters guys.
Peace
And
Kind regards,
Ant
Please login to rate coding articles.
Click here to register a free account with us.
|