-
Mar 24th, 2006, 09:21 PM
#1
Thread Starter
Member
[RESOLVED] Runtime error '9': subscript out of range
Hi i have made a little application for a game i play which tells me how many players there are in each server.
the game has 120 worlds. but 121 buttons . world 116 isnt used at all.
My problem is i run my program with world 116 in it, i get this error Runtime error '9': subscript out of range.an it points this part of the code which is in red font colour .
VB Code:
Private Function worldplayerslist()
Dim worlds(121) As String, temp() As String, temp2 As String, temp3 As String, temp4 As String
On Error GoTo skip2
Text2.Text = Inet1.OpenURL("http://runescape.com/serverlist.ws?plugin=0&lores.x=163&lores.y=74")
DoEvents
For num = 1 To 121
On Error GoTo offline
[COLOR=Red]temp2 = Left(Split(Text2.Text, "World " & num & "<")(1), 30)[/COLOR]
temp3 = InStr(1, temp2, "Players")
temp4 = InStr(1, temp2, "empty")
If (temp4 > 0) Then
temp2 = "OFFLINE"
Else
If (temp3 > 0) Then
temp2 = Split(Split(temp2, " Players")(0), "<td>")(1)
Else
temp2 = "Full"
End If
End If
Text1(num - 1).Text = temp2
GoTo skip
offline:
Text1(num - 1).Text = "Offline"
skip:
Next num
skip2:
End Function
Private Sub Form_Load()
frmWait.Show
Me.Show
frmWait.ZOrder 0
Me.ZOrder 1
Timer1.Enabled = False
Call worldplayerslist
Unload frmWait
For g = 0 To 105
Text1(g).Locked = True
Next g
mnuStart.Enabled = True
mnuStop.Enabled = False
End Sub
Private Sub mnuExit_Click()
If Timer1.Enabled = True Then
MsgBox "You must first disable the automatic refresh.", vbCritical, "Hold It Right There!"
Else
Unload Me
End If
End Sub
Private Sub mnuRefresh_Click()
Timer1.Enabled = False
mnuStart.Enabled = True
mnuStop.Enabled = False
frmWait.Show
Me.Show
frmWait.ZOrder 0
Me.ZOrder 1
Timer1.Enabled = False
Call worldplayerslist
Unload frmWait
End Sub
Private Sub mnuSet_Click()
If Timer1.Enabled = True Then
MsgBox "You must first disable the automatic refresh.", vbCritical, "Hold It Right There!"
GoTo skip2
End If
frmSet.Show
skip2:
End Sub
Private Sub mnuStop_Click()
Timer1.Enabled = False
mnuStart.Enabled = True
mnuStop.Enabled = False
End Sub
Private Sub mnuStart_Click()
Timer1.Enabled = True
mnuStart.Enabled = False
mnuStop.Enabled = True
End Sub
Private Sub Timer1_Timer()
Call worldplayerslist
End Sub
Please could some one explain what i have done wrong?
Many thanks
Sheepy
-
Mar 24th, 2006, 09:30 PM
#2
Hyperactive Member
Re: Runtime error '9': subscript out of range
This would happen if Text2.Text did not contain the split value, which would result in a single-element array, thereby causing a reference to the second element to fail.
-
Mar 24th, 2006, 09:41 PM
#3
Thread Starter
Member
Re: Runtime error '9': subscript out of range
how could i fix this. its picking ling my head
Many thanks
-
Mar 24th, 2006, 09:51 PM
#4
Frenzied Member
Re: Runtime error '9': subscript out of range
Originally Posted by Sheepy_Daz
how could i fix this. its picking ling my head
Many thanks
Don't let the user enter the world, have all the world in a combo box.
Also (I used to play rune scape 4 years ago (I was rank top 20) Now I rank like 20k lol)
I think this is against the rules of the game to use a software
P.S. RS NAME USED TO BE Wiz126
-
Mar 24th, 2006, 09:53 PM
#5
Thread Starter
Member
Re: Runtime error '9': subscript out of range
Its not an application where people can clik an enter a world. this application only shows how many people are online.
you can use your own software. as long as it abides by jagex's rules. there are many world switchers out now. Just want my own personal one
-
Mar 24th, 2006, 10:17 PM
#6
Frenzied Member
Re: Runtime error '9': subscript out of range
i think this happened because the variable named text2 is not an array and split function normally returns all the values distributed in an array
On error goto Trap
Trap:
in case of emergency, drop the case...
****************************************
If this post has been resolved. Please mark it as "Resolved" by going through the "Thread Tools" above and clicking on the "Mark Thread Resolved " option. if a post is helpful to you, Please Rate it by clicking on the Rate link right below the avatar
-
Mar 25th, 2006, 09:45 AM
#7
Thread Starter
Member
Re: Runtime error '9': subscript out of range
What would i need to do to correct this?
sheepy
-
Mar 25th, 2006, 09:53 AM
#8
Re: Runtime error '9': subscript out of range
Originally Posted by Sheepy_Daz
What would i need to do to correct this?
sheepy
VB Code:
If InStr(1, Text2.Text, "<") <> 0 Then
temp2 = Left(Split(Text2.Text, "World " & num & "<")(1), 30)
temp3 = InStr(1, temp2, "Players")
temp4 = InStr(1, temp2, "empty")
Else
...
-
Mar 25th, 2006, 10:21 AM
#9
Thread Starter
Member
Re: Runtime error '9': subscript out of range
thanks for you reply. i have tried what you have said an i get another compiler error. Next without for an in this part of the code.
This part in red gets highlighted yellow, an the part in red down the bottom is what gets highlighted in blue
VB Code:
[COLOR=Red]Private Function worldplayerslist()[/COLOR]
Dim worlds(117) As String, temp() As String, temp2 As String, temp3 As String, temp4 As String
On Error GoTo skip2
Text2.Text = Inet1.OpenURL("http://runescape.com/serverlist.ws?lores.x=396&lores.y=217&plugin=0&order=WMLP")
DoEvents
For num = 1 To 117
On Error GoTo Offline
If InStr(1, Text2.Text, "<") <> 0 Then
temp2 = Left(Split(Text2.Text, "World " & num & "<")(1), 30)
temp3 = InStr(1, temp2, "Players")
temp4 = InStr(1, temp2, "empty")
If (temp4 > 0) Then
temp2 = "OFFLINE"
Else
If (temp3 > 0) Then
temp2 = Split(Split(temp2, " Players")(0), "<td>")(1)
Else
temp2 = "Full"
End If
End If
Text1(num - 1).Text = temp2
GoTo skip
Offline:
Text1(num - 1).Text = "Offline"
skip:
[COLOR=red]Next[/COLOR] num
skip2:
End Function
Any ideas?
-
Mar 25th, 2006, 10:30 AM
#10
Re: Runtime error '9': subscript out of range
You are missing the End If for the If Instr... line.
-
Mar 25th, 2006, 10:45 AM
#11
Thread Starter
Member
Re: Runtime error '9': subscript out of range
now im getting runtime error 13. type mismatch. the part in red is getting highlighted :-S Please excuse me as im fairly new to vb an dont no much about the error or runtime messages
VB Code:
Private Function worldplayerslist()
Dim worlds(117) As String, temp() As String, temp2 As String, temp3 As String, temp4 As String
On Error GoTo skip2
Text2.Text = Inet1.OpenURL("http://runescape.com/serverlist.ws?lores.x=396&lores.y=217&plugin=0&order=WMLP")
DoEvents
For num = 1 To 117
On Error GoTo Offline
If InStr(1, Text2.Text, "<") <> 0 Then
End If
temp2 = Left(Split(Text2.Text, "World " & num & "<")(1), 30)
temp3 = InStr(1, temp2, "Players") = 0
temp4 = InStr(1, temp2, "empty") = 0
[COLOR=Red]If (temp4 > 0) Then[/COLOR]
temp2 = "OFFLINE"
Else
If (temp3 > 0) Then
temp2 = Split(Split(temp2, " Players")(0), "<td>")(1)
Else
temp2 = "Full"
End If
End If
Text1(num - 1).Text = temp2
GoTo skip
Offline:
Text1(num - 1).Text = "Offline"
skip:
Next num
skip2:
End Function
Sheepy
-
Mar 25th, 2006, 11:08 AM
#12
Re: Runtime error '9': subscript out of range
Couple of things going on here. First, you are testing string types against integer types. temp4 is declared as a string, and you are testing to see if it is > 0. This leads to the second thing. When you give temp4 a value in this line,
VB Code:
temp4 = InStr(1, temp2, "empty") = 0
this is what happens. The InStr returns a number if it finds the search string, or 0 if it doesn't. Then, it is compared to see if it equals zero. So, it if is found, temp4 is set to false. If it is not found, temp4 is set to true. Problem is, since temp4 is a string, the boolean that you are returning gets cast to a string "True" or "False". Thus, the type mismatch.
Check out the code below, it might not be exactly what you need, but it will compile clean and let you work from there. (I changed the error handling and the GoTos because they were driving me batty).
VB Code:
Private Function worldplayerslist()
Dim worlds(117) As String, temp() As String, temp2 As String, temp3 As Long, temp4 As Long
On Error GoTo ErrHand
Text2.Text = Inet1.OpenURL("http://runescape.com/serverlist.ws?lores.x=396&lores.y=217&plugin=0&order=WMLP")
DoEvents
For num = 1 To 117
If InStr(1, Text2.Text, "<") <> 0 Then
temp2 = Left(Split(Text2.Text, "World " & num & "<")(1), 30)
temp3 = InStr(1, temp2, " Players")
temp4 = InStr(1, temp2, "empty")
Else
'Do whatever you want to do when there is no delimiter. IE:
temp2 = "Offline"
End If
If (temp4 > 0) Then
temp2 = "OFFLINE"
Else
If (temp3 > 0) Then
temp2 = Split(Split(temp2, " Players")(0), "<td>")(1)
Else
temp2 = "Full"
End If
End If
Text1(num - 1).Text = temp2
Next num
ErrHand:
If Err.Number <> 0 Then
'Recover from your error. Probably a bad example, but something like this:
temp2 = "Offline"
Resume Next
End If
End Function
-
Mar 25th, 2006, 11:15 AM
#13
Thread Starter
Member
Re: Runtime error '9': subscript out of range
The way you explained that was very helpful thanks. ill give this a try an let you know how i get on :-)
Thanks
Sheepy
-
Mar 25th, 2006, 11:27 AM
#14
Thread Starter
Member
Re: Runtime error '9': subscript out of range
ok compiles fine, still 1 problem tho :-S.
all worlds after 116 are coming up as full, even tho there not full. if you get me?
is there some way i can cut world 116 out of the code or get it not to check for world 116? as is doesnt get used for anything.
-
Mar 25th, 2006, 11:40 AM
#15
Re: Runtime error '9': subscript out of range
You can try resetting your variable at the bottom of the loop, otherwise I'd have to see what the input text looked like.
VB Code:
Text1(num - 1).Text = temp2
temp2 = vbNullString 'Add these three lines.
temp3 = 0
temp4 = 0
Next num
-
Mar 25th, 2006, 12:14 PM
#16
Thread Starter
Member
Re: Runtime error '9': subscript out of range
No Joy with resetting the variables.
I sort of know whats happening, just dunno how to fix it. what gets me is if the other worlds are full it dont mess it up at all.
because ther is no world 116 it gets messed up
Last edited by Sheepy_Daz; Mar 25th, 2006 at 12:18 PM.
-
Mar 25th, 2006, 07:10 PM
#17
Thread Starter
Member
Re: Runtime error '9': subscript out of range
Sorry to double post, but problem solved.
Thanks to all who helped
Sheepy
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|