PDA

View Full Version : [vb6]Tutorial 3


Darkchild
08-19-2007, 09:43 PM
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:

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:

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!

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:
2687

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 :


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!

Acerthief
08-20-2007, 12:14 AM
man you should publish a book yourself, DC.
you'll be rich XD.
nice tut, once again.

Darkchild
08-20-2007, 07:58 AM
I did (in portuguese) but no one was interested so.. XD I only made one chapter

roe-ur-boat
08-20-2007, 05:56 PM
Seriously man an ebook would be cool

Darkchild
08-21-2007, 07:34 AM
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

Acerthief
08-21-2007, 02:30 PM
teach me how to do it and i'll make the ebook XD. sell it through the web and give you 90% what we've earned XD

Darkchild
08-21-2007, 08:54 PM
use openoffice and export as pdf xD

Acerthief
08-21-2007, 09:15 PM
hm... sounds easy. well i guess i'll hafta wait for more tutorials :D

Darkchild
08-22-2007, 12:46 AM
well..if you want another one..you know the rules! :D

Acerthief
08-22-2007, 09:35 AM
number one!!!!
and my c++ tutorial is almost there!

Darkchild
09-07-2007, 06:36 PM
Anybody else wants a tuto?

Cheezeball99
09-07-2007, 09:21 PM
My name... Is... TWO!

Acerthief
09-08-2007, 02:31 AM
here here here!

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

Darkchild
09-08-2007, 08:08 PM
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 :)

Junit
10-10-2007, 06:14 PM
I'm down,I'm sure I'll need them in the near future. Count me as 3.Junit wants to make JUNamp xD

Darkchild
10-10-2007, 07:00 PM
XD

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

Acerthief
10-11-2007, 08:49 AM
yeah!
(just as i though this section is dead...)

MenaceInc
10-11-2007, 09:17 AM
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

Darkchild
10-11-2007, 06:06 PM
OK Events and changing labels

anything else?

Clint
02-13-2008, 02:29 AM
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 :]

Darkchild
02-14-2008, 01:14 AM
hehe, I thought you guys didn't want any more of these xD

I'll make more, but I want evil seph to edit them to make sure they are correct XD