Starting vb6

From VbGORE Visual Basic Online RPG Engine

In this guide you will learn the basics of vb6 so you don't just make a ton of clone games, with the only edits from a guide. With your new found knowledge you will be able to edit the game and understand the wiki guides and vbgore itself.

The Program: First thing first, you must have Visual Basic to use it. Microsoft does NOT make copies of Visual Basic 6.0 anymore so if you don't have it, you might be a while finding it.But please don't download vb 2005/.NET all it will do is waste your time as it wont work with vbgore as there are completely different programs.

Remember VB 2005 and VB.NET are NOT the same as VB6.0 - they will NOT work with vbGORE!

The Interface : I will quickly talk about the interface as the program is user friendly so you will get the hang of it quickly! vb6guideqy2.jpg


Your first application "Hello world" in style! First of all drag your mouse to the toolbox of controls and click on the command button icon, Place it down on the form. Next go to the textbox icon and drag one onto screen it should look like this

showcz0.jpg

Next double command click the command button so your in the code editor and you should see

Important note! make sure you click the command button and not the textbox or it will not work!


 Private Sub Command1_Click()
 
End Sub


Now replace all of that code with

Private Sub Command1_Click()
Dim HelloMessage As String
  HelloMessage = "Hello, world!"
  Text1.Text = HelloMessage
 
End Sub


save it then go to file, and click make project1.exe show2hk7.jpg

Now run the application and press button1 on the text box the worlds Hello, world! should come up. Now close the application its time to explain just what went on there. I shall explain it to you line by line



Private Sub Command1_click()

"Private sub" all this is doing is just identifying this code as a subroutine

"Command1" all this means is that the code is in the section called Command1 (basically your command box is named command1) but remember if you renamed your command box something else like adam then you will have to change "Command1! to adam or the computer will not I.D. the command box so you will just get a error.

"-click()" this is just telling the computer its a click event, I.E. when you click the button the code runs



Dim HelloMessage As String

"Dim HelloMessage" This is one of the most important features in vb6, the computer is making a Variable called HelloMessage. A Variable stores a piece of information, it can be a letter, a number a sentence a age etc This is handy when you call on Variables, as you can store something like someones name then later in the program You can call the Variable to find out what his name in.

"As String" This part is a bit more complicated this defines the Variable as a string, a string stores letters


== A important note, if the Variable is a string it only stores whats inside the "" I.E. if you say HelloMessage = "Josh" then the Variabile will store the name josh but if you say HelloMessage = josh then you will get a error as it isn't storing anything. ==

Helloworld is the name of the variable but the variable can be any word that is declared


HelloMessage = "Hello, world!"

HelloMessage = "Hello, world!" this may look strange but it isn't all whats happening is the Variable is storing the words Hello, world! in its memory


A important note, A variable can only store one bit of information at a time


Text1.Text = HelloMessage

Text1.Text = HelloMessage This is the most complicated part of the code you have come across so far All what is happening is the computer is calling on the Variable HelloMessage and is displaying its information on Text1, our text box. If you have followed the code so far you would have got the fact that the text box is displaying the words Hello, world!.

Text1 is the name of the textbox that was setup earlier, text1 can be whatever you choose to name it in the form



End Sub

End Sub this is telling the computer the subroutine that we created at the beginning is finished.

Thats it, your very first Program!



Variable as string = “Lesson two”

You have now learned the basics of a Program so its now time to go into Variables in more detail. Here is a list of some types Of Variables and what they do.


Byte The Byte data type is an 8-bit variable which can store value from 0 to 255. This data type is very useful for storing binary data. It can also be very useful when sending/receiving byte values to/from a Basic Stamp or PIC.

e.g.

 Dim example as byte
Byte = 13 + 240

Double the Double data type takes up 64 bytes to use. If you want to get accurate results this is needed. The Variable its self can only store numbers from 1 -4 but can get up at over 20 Decimal places!, it can also do Negative values from -1 to -4.

Dim example as double
Example = 1.758799435546646

Integer The Integer data takes up 16-bytes to use. Its numbers can range from -32768 to 32767. Integers are used when you are using numbers with whole numbers only

Dim example as Integer
exAMPLE = 32465

Long The Long data type takes up 32 bytes to use But can range from -2,147,483,648 to 2,147,483,647. Long variables can only hold whole numbers. Its better to use Integer for small numbers as longs take up twice the amount of space.

Dim example as long
Example = 284874648

Single The Single data type takes up 32 bytes to use when you want to use fractions/ decimals use a single type data.

Dim example as single
Single = 0.46483

String A string can store huge amounts of text, this is the only variable that can store writing. It can also store data.

Dim example as string
Example = “hello, world 123@()!”


[edit] Defining Variables

When you make a Variable you have learnt to use the term “Dim”. This will work small scale but for big variables like player stats you will need to make the Variable global.

The difference between global and dim

When you Dim A variable, that variable is only stored in that procedure (A procedure is a like a section a example of this is FRMconnect or FRMmain. Dimming a Variable has some uses over a global Variable.

• Its easy to isolate a specific concern/error in that variable • It uses less memory • Its faster

You may be thinking why you want to use a global variable, there biggest advantage is the fact that they work in all procedures. To make a global Variable you must change the way you define it.

To make a global Variable instead of saying

Dim variablename
you would type
Global Variablename

there you go you now have global Variables.

Another way to have a global variable is adding the normal Definition (Dim) into a module file (we'll see it ahead).

[edit] "IF" statements

The "IF"'s statements are likes forks: IF something happen, do this, else, do that.

It's very simple.

Start making a simple form, add a blank box (with the name of "testbox") and a button (with the name - not caption - as "cmdbutton").

Okay, now, click two times into the button and you'll go to code page. It should be like it:

Private sub cmdbutton_Click
 
 
End sub

So, we'll make a program that if we put "Raijenki", it will say "Raijenki is very beautiful".

If you put anything in the textbox that isn't "Raijenki", it will say another thing. Then, try this:

Private sub cmdbutton_Click
 
'Specifing the condition (if at the testbox.text is typed Raijenki when clicked at the button, then we will display a message).
if testbox.text = Raijenki Then
    msgbox "Raijenki is very beautiful"
 
'If not typed... Display another!
Else
    msgbox "You have not entered the name of Raijenki here!"
 
End if
 
End sub

We can do anothers things too, let's say that we will only create conditions to "Raijenki", "Spodi", "nex666" and "else".

Private sub cmdbutton_Click
 
'Specifing the condition (if at the testbox.text is typed Raijenki when clicked at the button, then we will display a message).
if testbox.text = Raijenki Then
    msgbox "Raijenki is very beautiful"
 
'If not typed... Let's make another condition!
Elseif testbox.text = Spodi
    msgbox "Spodi is the vbGore main programmer!"
 
'OMG! Let's make the last condition... for nex666
Elseif testbox.text = nex666
    msgbox "nex666 is the vbGore's sponsor!"
 
'But... what if we don't put Raijenki, Spodi or nex666 at the text box?
Elseif testbox.text <> Raijenki And testbox.text <> Spodi And testbox.text <> nex666
'The code above means that if the typed on testbox is not equal to Raijenki, Spodi and nex666, do the following
msgbox "HaHaHa! You didn't typed the gods on the text box!
End if
 
End sub

That's all by now!

Personal tools