RuneScape Stats Lookup Tutorial
By Webmaster
I. Table Of Contents
II. Introduction
III. A Little About VB
IV. Adding The Objects
V. Coding/Explanation
VI. Testing
VII. Compiling
VIII. Final Remarks
IX. Frequently Asked Questions
X. Credits
II. Introduction:
A. Version History
05/25/05 - Started Guide.
06/03/05 - Completed Form_Load, Command1_Click, and Command2_Click.
06/18/05 - Completed Guide.
B. A Few Quick Words
Well, in this guide i'm going to show and explain to you how to make your very own RuneScape Stats Lookup Tool! This will take a while, proborbly about one to two hours! I'll teach you everythign from the learning the VB basics, to adding the objects to the form, to adding the code, all the way to distribution! Your Screenshots will nto look exactly like mine, because i'm using windowblinds theme! Lets get started with some quick requirements!
C. Requirements
Visual Basic 6.0 Or Visual Basic .NET
Also, About An Hour Of Time
III. A Little About VB
A. What Is It?
VB is short for Visual Basic. It one of the best compilers out there! SwiftSwitch, RSTK, RSP, are all made with VB! Microsoft makes it... Visual basic is what you would call an "Object Oriented" Language...
B. Object oriented? Whats that?
An Object Oriented language is one that is based on buttons, text boxes, option butons, check boxes, etc. Most higher level programming languages are object oriented, a few non-object oriented languages are PHP, MySQL, etc. Its also an "Real-Life Language"...
B. A Real Life Language?
Its where the language is a lot like english, you can liek read it outloud and know what it means... For instance The Vb if statements:
 |
CODE 1 |
 |
If X = 1 Then
 X = 2
End If |
IV. Adding The Objects
A. Text Boxes, Text Boxes, Text Boxes...
First of all, we need to add the Winsock Control to the form... Press Ctrl+T, scroll down to "Microsoft Winsock Control 6.0" Check The Box Next To It, Click OK! Your Should look Something Like This: Click Here
Ok, Now Click The Winsock Icon () And Put It Somewhere In The Form (It Dosn't Really Matter Where Since Its Not Seen When The Program Is Running). Next Place Your Basic Layout... with 2 command buttons (command1 and command2) and a bunch of text boxes... because you need to set all the names ot a certain thing, you can save yourself about 20 min and downlaod my form... Click Here
Once you've downlaoded my form, we can continue to adding the code...
- V. Coding/Explanation
A. A Few Remarks
Ok, Before we Start The Coding... In Most Of The Lines Of VB Code In This Tutorial you'll see a ' and then some works, the ' and everything after it is called a remark, it will turn green in vb. All Remarks Will Be Ignored By Visual Basic and striped from the exe when compiling to Minimize Space. For Instance: Click Here
Notice How The ' And Everything After It In That Line Is Green... Also, If You Look Closely Enough At The Picture You Will Notice That The Words "If" and "Then" Are A Dark blue, Instead Of Black... There Are Blue Because They Are Needed Parts Of VB. You Cannot use the Words In Blue For: Variable Names, Function Names, Or RaiseEvents... Last But Certainly Not Least, look at this Picture: Click Here
As You Write This Program You Will Probrobly Notice That Vb Automatically Makes Levels Of Statements for easier reading, this dosn;t actually mean anything, its just there to help you if you get confused to what level you are in...
THIS GUIDE IS NOT MEANT FOR THE BEGINING VISUAL BASIC USER! Its Geared more towards the "Intermediate to Slightly Advanced"... Ok, Now That That Stuff Is All Out Of The Way, I'd Like To Say One Thing... I Realize That This Code Could Be A LOT More Compact, I'm Sure I Could Have Made Several Stuff Quicker... But It Gets The Job Done... From Time To Time, I'll be Updating This Guide With Less Time Consuming Code... But In The Mean Time Bear With Me =) Now For The Fun Part...
B. Declarations
This is mainly for Variable declatations and Functions, all you really need to worry abotu at this point is one variable that needs to be set:
 |
CODE 2 |
 |
| Private m_strHttpResponse As String ' Line 0 |
C. Form_Load
I hope that everyone knows when the Form Load is Triggered... But For Those of you who dont... Its when the form first is launched. Please, if you havn't done so, download my form above! you need all the correct names of objects... I could have given you a list, but it'd be a waste of time... Well, go to the coding window, and insert this...
 |
CODE 3 |
 |
Private Sub Form_Load() ' Line 1
 Form1.Caption = "Stats Lookup (Ver " & App.Major & "." & App.Minor & "." & App.Revision & ")" ' Line 2
End Sub ' Line 3
|
Line 2: Now, all that that really does is set the Title bar to "Stats Lookup (Ver 9.9.9)" except that 9.9.9 will be replaced with the version number (we'll learn more about this when we are compiling)... Well th next part... Notice How The Comments Show the line numbers, I manually added that in for easier explanation of the code...
D. Command1_Click
This is triggered when you click the "Get Stats" Button When The Program is running... The Code...
 |
CODE 4 |
 |
Line 5: This Line Takes What ever is in the username text box, changes it to lowercase and replaces all spaces (ascii 32) to underscores (ascii 95)
Line 6: Here we initialize the connection the the RuneScape hiscore server (hiscore.web.runescape.com on port 80).
E. Command2_Click
I just put this in there because it is an easy (not nessicarily efficient) way of setting all of the stats fields to "N/A" when you lookup a user. The Code...
 |
CODE 5 |
 |
Private Sub Command2_Click() 'Line 8
 overlvl.Text = "N/A" 'Line 9
 overrank.Text = "N/A" 'Line 10
 overexp.Text = "N/A" 'Line 11
 attlvl.Text = "N/A" 'Line 12
 attrank.Text = "N/A" 'Line 13
 attexp.Text = "N/A" 'Line 14
 deflvl.Text = "N/A" 'Line 15
 defrank.Text = "N/A" 'Line 16
 defexp.Text = "N/A" 'Line 17
 Strlvl.Text = "N/A" 'Line 18
 strrank.Text = "N/A" 'Line 19
 strexp.Text = "N/A" 'Line 20
 hplvl.Text = "N/A" 'Line 21
 hprank.Text = "N/A" 'Line 22
 hpexp.Text = "N/A" 'Line 23
 ranlvl.Text = "N/A" 'Line 24
 ranrank.Text = "N/A" 'Line 25
 ranexp.Text = "N/A" 'Line 26
 praylvl.Text = "N/A" 'Line 27
 prayrank.Text = "N/A" 'Line 28
 prayexp.Text = "N/A" 'Line 29
 maglvl.Text = "N/A" 'Line 30
 magrank.Text = "N/A" 'Line 31
 magexp.Text = "N/A" 'Line 32
 cooklvl.Text = "N/A" 'Line 33
 cookrank.Text = "N/A" 'Line 34
 cookexp.Text = "N/A" 'Line 35
 wclvl.Text = "N/A" 'Line 36
 wcrank.Text = "N/A" 'Line 37
 wcexp.Text = "N/A" 'Line 38
 fletlvl.Text = "N/A" 'Line 39
 fletrank.Text = "N/A" 'Line 40
 fletexp.Text = "N/A" 'Line 41
 fishlvl.Text = "N/A" 'Line 42
 fishrank.Text = "N/A" 'Line 43
 fishexp.Text = "N/A" 'Line 44
 firelvl.Text = "N/A" 'Line 45
 firerank.Text = "N/A" 'Line 46
 fireexp.Text = "N/A" 'Line 47
 craftlvl.Text = "N/A" 'Line 48
 craftrank.Text = "N/A" 'Line 49
 craftexp.Text = "N/A" 'Line 50
 smithlvl.Text = "N/A" 'Line 51
 smithrank.Text = "N/A" 'Line 52
 smithexp.Text = "N/A" 'Line 53
 minelvl.Text = "N/A" 'Line 54
 minerank.Text = "N/A" 'Line 55
 mineexp.Text = "N/A" 'Line 56
 herblvl.Text = "N/A" 'Line 57
 herbrank.Text = "N/A" 'Line 58
 herbexp.Text = "N/A" 'Line 59
 agillvl.Text = "N/A" 'Line 60
 agilrank.Text = "N/A" 'Line 61
 agilexp.Text = "N/A" 'Line 62
 Thievlvl.Text = "N/A" 'Line 63
 Thievrank.Text = "N/A" 'Line 64
 thievexp.Text = "N/A" 'Line 65
 slaylvl.Text = "N/A" 'Line 66
 slayrank.Text = "N/A" 'Line 67
 slayexp.Text = "N/A" 'Line 68
 rclvl.Text = "N/A" 'Line 69
 rcrank.Text = "N/A" 'Line 70
 rcexp.Text = "N/A" 'Line 71
 comlvl.Text = "N/A" 'Line 72
End Sub 'Line 73 |
Lines 8-73: Sets All The Skill Text Boxes To N/A...
F. wscHTTP_Connect
Well, this was triggered in the command1_click statement... This is the data we'll be sending to the server...
 |
CODE 6 |
 |
Private Sub wscHttp_Connect() 'Line 74
 Dim strHttpRequest As String 'Line 75
 strHttpRequest = "GET /aff/runescape/hiscorepersonal.cgi?username=" & username.Text & "&category=0 HTTP/1.1" & vbCrLf 'Line 76
 strHttpRequest = strHttpRequest & "Host: hiscore.web.runescape.com" & vbCrLf 'Line 77
 strHttpRequest = strHttpRequest & "Accept: */*" & vbCrLf 'Line 78
 strHttpRequest = strHttpRequest & "Connection: close" & vbCrLf 'Line 79
 strHttpRequest = strHttpRequest & vbCrLf 'Line 80
 wscHTTP.SendData strHttpRequest 'Line 81
End Sub 'Line 82 |
OK, well this is what we're sending to the server...
Lines 75: Here we set the variable that all the data will be stored in that we're going to send to the hiscore server...
Lines 76: This is where we tell the server what page we want to get from the site, "GET" is the command that tells then what we want... the next is the URL of the page (in this case, the users stats). The "HTTP/1.1" tells the server the server the Language to send.
Lines 77: This is the host that we're connecting to...
Lines 78: This line tells the server what file type we want.. in this cas,e we want all the file types...
Lines 79: We are closing the connection to the server...
Lines 80: A Second crlf tells the server that we're done sending it stuff...
Lines 81: And this finnaly sends evrything above to the server...
F. wscHTTP_DataArrival
Now that we've told the server what we want, it not sends us the data... the code here is executed when the data is recieved... All of the HTML in the page is sent as one LONG line of text and line feeds... Lets look at the code:
 |
CODE 7 |
 |
Lines 84: This Makes The variable that we'll be putting the data into, it a String datatype...
Lines 85: This gets the WHOLE page's HTML and stuffs it into the var "strData"...
Lines 86: RS puts its HTML in a way where lines are not seperated with crlf's, but just line feeds... so, here i substituted all the linefeed with crlf's =P fixes the problem...
G. Some Functions
Here we are going to need some functions for misc things such as stripping HTML and reading specific lines from files...
 |
CODE 8 |
 |
Public Function RFF(FileName As String, LineOfFile As Integer) 'Line 88
 Dim tehrffvar As String 'Line 89
 Dim p As Integer 'Line 90
 Dim Filenum As Integer 'Line 91
 p = 1 'Line 92
 Filenum = FreeFile 'Line 93
 Open FileName For Input As Filenum 'Line 94
   For p = 1 To LineOfFile 'Line 95
     If p <> LineOfFile Then 'Line 96
       Line Input #Filenum, tehrffvar 'Line 97
     End If 'Line 98
     If p = LineOfFile Then 'Line 99
       Line Input #Filenum, tehrffvar 'Line 100
       RFF = Replace(tehrffvar, Chr(34), "") 'Line 101
       Exit For 'Line 102
     End If 'Line 103
   Next p 'Line 104
 Close Filenum 'Line 105
End Function 'Line 106
Public Function Lines(FileName As String) 'Line 107
 Dim numoflines As Long 'Line 108
 Dim Filenum As Integer 'Line 109
 Dim Unneededver As String 'Line 110
 Filenum = FreeFile 'Line 111
 Open FileName For Input As Filenum 'Line 112
   Do While Not EOF(Filenum) 'Line 113
     Line Input #Filenum, Unneededver 'Line 114
     numoflines = numoflines + 1 'Line 115
   Loop 'Line 116
 Close Filenum 'Line 117
 Lines = numoflines 'Line 118
End Function 'Line 119
Public Function htmlfree1(ltsf As String) 'Line 120
 htmlfree1 = Replace(Replace(Replace(Replace(ltsf, "<td><a href=", ""), "hiscoreuser.cgi?username=", ""), " class=c>", ""), "</a></td>", "") 'Line 121
 htmlfree1 = Replace(Replace(Replace(Replace(Replace(Replace(Replace( _
   Replace(Replace(Replace(Replace(Replace(Replace( _
   Replace(Replace(Replace(Replace(Replace(Replace( _
   Replace(Replace(Replace(Replace(Replace(Replace( _
   Replace(htmlfree1, "&category=25", ""), "&category=24", ""), "&category=23", ""), "&category=22", ""), "&category=21", ""), "&category=20", ""), _
   "&category=19", ""), "&category=18", ""), "&category=17", ""), "&category=16", ""), "&category=15", ""), "&category=14", ""), "&category=13", ""), _
   "&category=12", ""), "&category=11", ""), "&category=10", ""), "&category=9", ""), "&category=8", ""), "&category=7", ""), "&category=6", ""), _
   "&category=5", ""), "&category=4", ""), "&category=3", ""), "&category=2", ""), "&category=1", ""), "&category=0", "") 'Line 122
 htmlfree1 = Replace(htmlfree1, username.Text, "") 'Line 123
End Function 'Line 124
Public Function htmlfree2(ltsf As String) 'Line 125
 htmlfree2 = Replace(Replace(Replace(ltsf, "<td align=right>", ""), "</td><td align=right>", ""), "</td>", "") 'Line 126
End Function 'Line 127 |
Lines 88-106: This Will Get A Certain line of text from a file in this format: RFF(<Filename>, <Line>).
Line 107-119: Returns the number of lines in a file... format: Lines(<Filename>)
Line 120-124: This trims some misc HTML from a lines... It leaves only the skill name... format: htmlfree1(<Line Of HTML>)
Line 125-127: This also trims some misc HTML from a lines... It leaves only the level, exp, and rank depending on what line you push though it... format: htmlfree2(<Line Of HTML>)
H. wscHTTP_Close
This is essensually where all of the good stuff happens!
 |
CODE 9 |
 |
Line 129: Executes whatever is in Command2_Click (in this case it makes all of the text boxes go to "N/A"
Line 130: This part here looks for a double crlf (this means that the header is over), and removes everything before it...
Line 131-133: This write the stats page (html) to the file called "statspage.txt"
Line 134-135: We set some variables that (losp) will contain the lines of html in the stats page, and (I) a counter for which line we're on...
Line 137-140: This is where we set the variables where the skill, exp, rank, and stat stuff will be stored...
Line 141: This stats the For Next statement... it essentially loop through everything until "Next I". code here will be executed once for every line of HTML in the page.
Line 142: On this like we look 4 lines up form the line we're on and strip the HTML from that line. It put this data in the variable called "possiblename".
Line 143: Same thing as line 142 except we look only 3 lines up and set the data into "possiblerank".
Line 144: Here we look on the line above the one we're on. this will be just a line with a number, no html to strip. This will actually have the skill level in it. we put this into the variable called "possiblestat"
Line 145: This is the line that we're actually going up from. This has the actual skill experience in it. we put this in "possibleexp"
Line 146: On this line we check to see if the skill name is "Overall" if it is, we continue, if not ignore...
Line 147: Assuming the skill name is Overall we put the overall level into the text box named "overlvl".
Line 148: Assuming the skill name is Overall we put the overall rank into the text box named "overrank".
Line 149: Assuming the skill name is Overall we put the overall exp into the text box named "overexp".
Line 150: Close the If Statement.
Line 151-250: Same as 146-150, except that it puts all the skills into their appropriate text boxes.
Line 251: On this line we check to see if the levels are available for the following skills: attack, defence, strength, prayer, and hits. if they ALL are then we continue to line 252...
Line 252: On this line we use a combat formula of mine to find the user's APPROXIMATE combat level. We put this in the comlvl text box.
Line 253: Exit the combat check, if statement.
Line 254: Look back though to the beginning of the For Next statement (Line 141).
Line 255: Here we close the socket to the runescape site. This is necessary because if we didn't, an error would occur next time we try to lookup someone's stats.
Line 256: Deletes the page that the stats HTML is stored.
Line 257: Exit the wscHTTP_Close Sub.
That's It For The Coding And Explanation! Now To Test It!
For The Complete Source Code You can Download It Here: Lookup Source
VI. Testing
A. Quick Compile
Press F5, Your program should start, enter your runescape username, click "Get Stats" and your stats should appear shortly. IF they don't appear in under about 5-10 seconds PM me the error and what was highlighted by VB. When and if people start sending me errors i will add some error and solution part to this guide.
VII. Compiling
A. Compile
Go To File > Then point to "Make Project1.exe" (Project1.exe may be replaced with something else). A dialog should pop-up, browse to where you would like to place the exe. Name it what you want, and save it! Note: If You Wish, you may adit some misc. propertied by clicking options on the dialog.
VII. Final Remarks
A. Just A Few
Well, like i've said above i know this code could have been a lot more efficient. PLEASE do not flame about that... On Second Thought Don't flame me at all... If you have something to say, please control yourself!
VII. Frequently Asked Questions
Q. Where can I get VB? Is it Free?
A. Well, VB is a very extensive program put out my Microsoft, Its also very expensive if you obtain it legally. I Paid $190 for VB6 back about 1-2 years ago... its about $200 for a brand new copy of .NET...
Q. OMG OMG OMG IT DOSNT WORK, WHATS WRONG??!!
A. Well, Send me the code i'll look at it, tell you what's wrong. When i fix the problem i'll add your problem and my solution to the Testing section.
VII. Credits
Well, Me For Making The Guide... RSC for allowing me to distribute it... Inferno For proof reading it... And Busybyeski for making me finish it =P
And of course RuneScape For Allowing Me and everyone to use their Hiscore Database!
Well that's all to this guide... I Guess Good Luck And Happy Coding!
Thank You,
Webmaster (Webmaster) |