• Steam recently changed the default privacy settings for all users. This may impact tracking. Ensure your profile has the correct settings by following the guide on our forums.

[vb6]Tutorial 3

Darkchild

The Doctor
Ladies and gentleman, young ones and old ones!!
Here it is! the 3rd VB6 TUTORIAL!!!

Today we learn : CODE!

First of all!! the mother of all codes! The "hello world!"

Well, to begin start a "Standard EXE" project, after that he shows you a form, this is the form in which we are going to work!

double click the form!

(a new window should appear, and if you read my previous tutorial you will know that it is the code window)

In there you should see something like:

Code:
Public sub Form_load ()

end sub

Now to explain what these lines mean! :D

"public sub form_load()" is the "header" for the set of code that will occur WHEN the form loads (Form_load, got it? no? well this part of the header is in this syntax : "component_event(parameters)" simple, no? )

now, you can put it in private instead of public (by replacing "public" for "private" although I don't recommend it >.< do this on modules and stuff not on forms! (again just a suggestion))

and now the "end sub" this is the finish of the set of code that will be executed when the event on the header starts

now! for the "hello world" program!

As you may know the code above, the header and the finish must NOT be deleted if you are working to put code into that event, they both must stay intact!

ok! this is the first command you will learn!

MSGBOX

syntax:
msgbox text as string, messagestyle as vbstyle, title as string

Here's an example:
Code:
Msgbox "Hello World!", vbinformation, "HELLO WORLD PROGRAM!"

(remember this has to be between the "public sub" and the "end sub" of the event you want it to occur in!

and as you can see he displayed an error! saying "Hello world!" and has a title named "HELLO WORLD PROGRAM!" and has that little "i" on the left (information warning!)

here's a trick for this msgbox!

Code:
msgbox "Line1" + vbcrlf + "line2" + vbcrlf + "line3"

Crowd : YOU FORGOT SOME PARAMETERS!!!!

err... no I didn't! Msgbox only needs one (the text), the other ones are optional, if you don't tell him the error style he won't put any icon on the left of the warning!

Crowd : AND ABOUT THAT PLUS!! DON'T YOU MEAN "&"??

No, VBCRLF is like "/n" in C++ so between the lines you have to put it as a plus, "&" is for joining strings!

Now that these questions have been cleared...
to explain the line code!

Notice the " + VBCRLF + " between every set of strings? like I said above it's like pressing Enter on word or... "/n" in c++ or "<br>" in html :)

Note : USE VBCRLF ON MSGBOX ONLY!

[/MSGBOX]:laugh: (I made a funny!!)

Crowd : Is form_load all we can have as events?

Hell no! You have loads of them, PER COMPONENT!
look at the image below:
vb6_1.JPG

that list on the right is all the events you can have, and on the right the components, this will be very helpful to the new ones in the programming language!

By choosing a component and then an event, VB will automatically create the header and the end of the header for the component and event chosen, then all you have to do is dump the code in it :)

Very simple am I correct? :D

now...create a label on the form!

and in the code put :

Code:
label1.caption = "TEXT IN LABEL!"

where label1 is the name of the label you've put (by default, it's label1)
.caption is a propriety, in which is the text to display in the label :)
"TEXT IN LABEL" Well...this is self explanatory

Well...This is all for today, toy around with other objects and start learning!
By the way, I'm accepting suggestions on about what to write for the next tuto so... post sum suggestions and comments :)

Darkchild..OUT!
 

Darkchild

The Doctor
nah, ebooks are too much work for me, what I could do, is continuing to make these tutorials and then someone could compile them and make the ebook =D
 

Cheezeball99

But I was committed after that birthday party...
My name... Is... TWO!
 

Darkchild

The Doctor
here here here!

(no one replies my tuto....) lol.

I feel your pain xD I had to revive this one to know if anyone wanted another one xD

Well...Another one is what you want, then another one you shall have!
I won't promise any date, but when I make it, you'll know :)
 
J

Junit

Guest
I'm down,I'm sure I'll need them in the near future. Count me as 3.Junit wants to make JUNamp xD
 

MenaceInc

Staff Member
XD

Anyways, what do you guys want to learn in the next tuto?


umm...would be cool to learn how to check for a keypress and change a label property according to the key press....you know,something in the direction of a game? :p
 

Clint

Clintoris
I think what would be most appropriate, considering you've done variable and gone over the basic form properties, would be to go over loops. This is something everyone needs to know, especially if they're going to make a game, as MenaceInc said. Perhaps this could go along with MenaceInc's idea, using that as an example! :)

By the way, the first 3 tutorials were great! I thought the first one was a great introduction without dwelling too long on the small things, like many tutorials written for beginners do.


Clint [Sorry for the bump :]
 
Top