 |
Cheat Engine The Official Site of Cheat Engine
|
| View previous topic :: View next topic |
| Author |
Message |
merlin22 Master Cheater
Reputation: 0
Joined: 29 Mar 2008 Posts: 267
|
Posted: Sat Aug 02, 2008 9:06 am Post subject: [TuT] Basic VB6 |
|
|
Before you go further, bear in mind that this tutorial was written for VB6 and may not compile with other VB languages.
Ok, now create a Standard EXE project with VB6(if you want) and lets begin!
Index
1)Functions
2)Functions with parameters
3)Declaring Variables
4)Data Types
5)Errorhandling
6)Procedures
7)Comparison Operators
8)Logical Operators
<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
'Functions:
Functions are very useful in any programming language, and
once you understand the fundamentals of them and how they
work, you could open new possibilies with your code.
Here is an example of how to not only declare a function but
also call it:
| Code: |
Private Function SetVars()
Call swf.SetVariable("_level0.1", 9999)
Call swf.SetVariable("_level0.2", 9999)
Call swf.SetVariable("_level0.3", 9999)
Call swf.SetVariable("_level0.3", 9999)
Call swf.SetVariable("_level0.4", 9999)
Call swf.SetVariable("_level0.5", 9999)
Call swf.SetVariable("_level0.6", 9999)
Call swf.SetVariable("_level0.7", 9999)
Call swf.SetVariable("_level0.8", 9999)
End Function
Private Function ResetVars() As Boolean
Call swf.SetVariable("_level0.1", 9)
Call swf.SetVariable("_level0.2", 2)
Call swf.SetVariable("_level0.3", 4)
Call swf.SetVariable("_level0.3", 6)
Call swf.SetVariable("_level0.4", 22)
Call swf.SetVariable("_level0.5", 6)
Call swf.SetVariable("_level0.6", 2)
Call swf.SetVariable("_level0.7", 0)
Call swf.SetVariable("_level0.8", NaN)
End Function
Private Sub Command1_Click()
Call SetVars
End Sub
Private Sub Command2_Click()
Call ResetVars
End Sub
|
Noticed how I declared the function as a boolean. Just like everything
else in the code, it can changed because it is simply a return type.
'Functions with parameters:
Parameters are extremely useful in the fact that it can not only save a
whole lot of time, but can also call the same function many times, but
in a way make it completely different each time.
As the first example, I will use a funciton like the 'SetVars' one above:
| Code: |
Private Function SetVars(value, value2, value3, value4) 'the parameters
Call swf.SetVariable("_level0.1", value
Call swf.SetVariable("_level0.2", value)
Call swf.SetVariable("_level0.3", value)
Call swf.SetVariable("_level0.3", value)
Call swf.SetVariable("_level0.4", value2)
Call swf.SetVariable("_level0.5", value2)
Call swf.SetVariable("_level0.6", value3)
Call swf.SetVariable("_level0.7", value)
Call swf.SetVariable("_level0.8", value4)
End Function
Private Sub Command1_Click()
Call SetVars(9999, 100, 359, 1000)
End Sub
|
As you can see, paramters are awesome and can be used to further manipulate
your functions.
| Code: |
Private Sub Command2_Click()
Call SetVars(999, 1540, 332, 0)
End Sub
Private Sub Command3_Click()
Call SetVars(234432, 1, 345, 1866)
End Sub
Private Sub Command4_Click()
Call SetVars(0, 0, 0, 0)
End Sub
|
Each time I call the same exact function, I can have completely different results
by changing the values of the paramaters.
'Declaring variables
To declare variables in VB6, the basic syntax is:
| Code: |
Dim 'Variable Name' As 'Type'
|
As you can see theres obviously not much to it, but here
would be an example:
| Code: |
Dim Num1 As Integer
Dim Num2 As Integer
|
Not much, eh? Ill show you how it can be used:
| Code: |
Private Sub Command1_Click()
Dim Num1 As Integer
Dim Num2 As Integer
Num1 = Text1.Text
Num2 = Text2.Text
Command1.Caption = Num1 + Num2
|
If you didnt know, that code will add the values of Text1 and Text2
only if they are numbers, and the resulting value will be displayed as
the caption of Command1 button.
'Data Types
Next I will cover the different data types that can be used in VB6 when
declaring a variable and much more. They go as following:
| Code: |
Integer
Long
Object
Single
String
Variant
Boolean
Byte
Currency
Date
Double
|
Now I shall go over the most commonly used data types. They are 'Integer',
'Boolean', and 'String':
| Code: |
Integer: An integer is either a positive or negative whole number.
(1,2,3,4,5).. (-1,-2,-3,-4,-5).. (0)
Boolean: A boolean is simply true or false.
(true).. (false)
String: A string is a group of multiple characters enclosed by quotation marks.
("Hi, how are you")... ("GAME OVER")
|
Now I will use all of them in a single example:
| Code: |
Private Sub Command1_Click()
'declare the variables
Dim Num As Integer
Dim Str As String
Dim tf As Boolean
'give them a value
Num = Command2.Caption
Str = "The magical number is:"
'true or false argument
If Command1.Caption = "Command1" Then
tf = True
Else
tf = False
End If
'do something if argument is true
'else the caption will not change
If tf = True Then
Command1.Caption = Str & Num
End If
End Sub
|
What this did was if command1's caption was "command1" then it added
together the string 'Str' and Command2's Caption. The resulting value was
then returned as command1's new caption.
'Errorhandling:
This may be simple but it can be one of the most important line(s) of your
code. It is used in multiple situations in which the result may not always
be able to happen. Most of you have experience this where you get the annoying
error message. The simple solution is to use errorhandlers.
There are two most commonly used types of errorhandling:
| Code: |
On Error Resume Next - one of the most commonly used types of errorhandling
on Error GotO 'a label' - i like dis one xD
|
Those are the two most commonly used types of errorhandling. Now I will give examples of how
to use each one:
'On Error Resume Next':
| Code: |
Private Sub Command1_Click()
On Error Resume Next
Open "C:\Documents and Settings\Owner\Desktop\lol.txt" For Input As #1
Close #1
End Sub
|
'On Error Goto 'a label'':
| Code: |
On Error Goto errorhandler
Open "C:\Documents and Settings\Owner\Desktop\lol.txt" For Input As #1
Exit Sub
errorhandler:
Close #1
End Sub
|
Both of those examples would return errors if you didnt have a text file called
"lol" in the desired location and if you never used an errorhandler.
'Procedures:
Procedures in VB6 are used similar to functions, so Im just going to give you a quick little example.
| Code: |
Private Sub lol(x)
Command2.Caption = x
End Sub
Private Sub Command1_Click()
lol ("rfjsjdfiejf")
End Sub
|
orz:
| Code: |
Private Sub lol()
Command2.Caption = "x"
End Sub
Private Sub Command1_Click()
lol
End Sub
|
'Comparison Operators:
These are quite useful and is a must know for every programmer:
| Code: |
= (equals to)
< (less than)
> (greater than)
<> (not equal to)
<= (less than or equal to)
>= (greater than or equal to)
|
These are simple operators and can be used just like everything else:
| Code: |
Private Sub Command1_Click()
Dim x As Integer
Dim y As Integer
x = 5
y = 6
'equals to
If x = y Then
'code
End If
'less than
If x < y Then
'code
End If
'greater than
If x > y Then
'code
End If
'not equal to
If x <> y Then
'code
End If
'less than or equal to
If x <= y Then
'code
End If
'greater than or equal to
If x >= y Then
'code
End If
End Sub
|
'Logical Operators:
Logical Operators can be used the same as the Comparison Operators.
These are also a must know for every programmer.
In VB6, there are 8 logical operators.
I will only go over the 3 most commonly used.
They are as follows:
They can be used like this:
| Code: |
Private Sub Command1_Click()
If Command1.Caption = "Command1" And Command2.Caption = "Command2" Then
Command1.Caption = "It is"
Command2.Caption = "true"
End If
End Sub
Private Sub Command2_Click()
If Command1.Caption = "Command1" Or Command2.Caption = "Command2" Then
Command1.Caption = "It is"
Command2.Caption = "true"
End If
End Sub
Private Sub Command3_Click()
If Not Command3.Caption = "Command3" Then
Command3.Caption = "true"
End If
End Sub
|
As you can see, the Comparison and Logical Operators check for a certain
condition, and when that condition is met, it initiates the code.
<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
This is the end of my tutorial, I hope I could have helped someone out, and help
them learn with this tutorial.
All credits for this tutorial go to me.
Last edited by merlin22 on Sun Aug 03, 2008 11:07 am; edited 2 times in total |
|
| Back to top |
|
 |
hcavolsdsadgadsg I'm a spammer
Reputation: 26
Joined: 11 Jun 2007 Posts: 5801
|
Posted: Sat Aug 02, 2008 11:11 pm Post subject: |
|
|
| Why are you making boolean functions if you're not returning anything?
|
|
| Back to top |
|
 |
merlin22 Master Cheater
Reputation: 0
Joined: 29 Mar 2008 Posts: 267
|
Posted: Sun Aug 03, 2008 7:01 am Post subject: |
|
|
| slovach wrote: | | Why are you making boolean functions if you're not returning anything? |
First of all, it was only one function, secondly, it was a mistake.
|
|
| Back to top |
|
 |
Typhoon808 Expert Cheater
Reputation: 0
Joined: 27 Mar 2008 Posts: 175 Location: Wales
|
Posted: Sun Aug 03, 2008 9:13 am Post subject: |
|
|
| You may want to go into a bit more detail on certain things such as the differences between functions and procedures. Other than that, it's not a bad tutorial for beginners.
|
|
| Back to top |
|
 |
oib111 I post too much
Reputation: 0
Joined: 02 Apr 2007 Posts: 2947 Location: you wanna know why?
|
Posted: Sun Aug 03, 2008 9:50 am Post subject: |
|
|
| Typhoon808 wrote: | | You may want to go into a bit more detail on certain things such as the differences between functions and procedures. Other than that, it's not a bad tutorial for beginners. |
What is the difference o.O
_________________
| 8D wrote: |
cigs dont make people high, which weed does, which causes them to do bad stuff. like killing |
|
|
| Back to top |
|
 |
Typhoon808 Expert Cheater
Reputation: 0
Joined: 27 Mar 2008 Posts: 175 Location: Wales
|
Posted: Sun Aug 03, 2008 12:07 pm Post subject: |
|
|
| Functions return a value whereas subs are basically the same as a void function (or so I thought).
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
|
|