Quantcast
Channel: VBForums - Visual Basic 6 and Earlier
Viewing all articles
Browse latest Browse all 21273

[Help] Subscript out of range

$
0
0
Hey, I've read the FAQ and my VB knowledge is quite lacking. Without too much explanation, this code is a snippet from a script for a bot that manages battle.net chat. (stealthbot)

I'm having trouble recently for no apparent reason with this script, it's quite odd.

Code:

Private Function maxPages(prod, clan, realm)
 
  If NOT ScInet.StillExecuting Then
      If realm = "kalimdor" Then
        data = CStr(ScInet.OpenURL("http://asialadders.battle.net/war3/ladder/" & prod & "-clan-profile.aspx?Gateway=" & realm & "&ClanTag=" & clan))
      Else
        data = CStr(ScInet.OpenURL("http://classic.battle.net/war3/ladder/" & prod & "-clan-profile.aspx?Gateway=" & realm & "&ClanTag=" & clan))
      End If
     
      If InStr(data, "Error") Then
        maxPages = "Battle.net is currently down or the website is updating. Please try again later."
        Exit Function
      End If
           
      temp = Split(data, "pageno=")(2) <<<<<<<<< Offending line
      temp = Left(temp, 1)
     
      maxPages = CInt(temp)
  End If
End Function

This is the function, the error message is;
[08:54:49 PM] Scripting runtime error '9' in KickInactive: (line 129; column 0)
[08:54:49 PM] Subscript out of range: '[number: 2]'

The offending line is;
temp = Split(data, "pageno=")(2)

Now looking at the code, you can see it's simply trying to count the number of pages to load as it's grabbing the activity of the users to remove them for inactivity. Weird thing is though, Battle.net has several servers and ladders, my script works fine with the all servers and ladders expect for one for idk why.
Code:

http://classic.battle.net/war3/ladder/w3xp-clan-profile.aspx?clantag=mn&Gateway=Northrend&sortfield=rank%20desc,%20online%20desc&sortdir=asc&pageno=2
Thats the link it grabs, it'll be grabbing "pageno" at the end of the link and this is for the "Northrend" server which it works fine but..

Code:

http://classic.battle.net/war3/ladder/w3xp-clan-profile.aspx?ClanTag=MN&Gateway=Azeroth&SortField=rank%20DESC,%20online%20desc&SortDir=Asc&PageNo=2
It doesn't work on this link, I'm not sure why as they're the exact same?

I don't think you need the entire script, but here it is if you need it.

[spoiler]
Code:

Script("Name") = "KickInactive"
Script("Author") = "The-Black-Ninja"
Script("Major") = 1
Script("Minor") = 0
Script("Revision") = 1
Script("Description") = "Kicks inactive members"


Private clanInactives

Sub Event_Load()

  Set clanInactives = CreateObject("Scripting.Dictionary")
  clanInactives.CompareMode = 1

  CreateCmds()
 
  Call CreateObj("LongTimer", "RemoveMembers")
  RemoveMembers.Interval = 10
  RemoveMembers.Enabled = False
End Sub


Sub Event_Command(cmd)

  Select Case Lcase(cmd.Name)
      Case "clanclean"
        If NOT (cmd.HasAccess) Then Exit Sub
       
        clanInactives.RemoveAll
       
        realm = GetRealm(BotVars.Server)
        prod = StrReverse(BotVars.Product)
       
        maxPage = maxPages(prod, BotVars.Clan, realm)
        totalPages = maxPage
       
        If NOT IsNumeric(totalPages) Then
            cmd.Respond totalPages
            Exit Sub
        End If       
       
        If scInet.StillExecuting Then
            cmd.Respond "Bot is busy. Try again later."
            Exit sub
        End If       
       
        For j = 1 To maxPage
            If realm = "kalimdor" Then
              data = CStr(ScInet.OpenURL("http://asialadders.battle.net/war3/ladder/" & prod & "-clan-profile.aspx?ClanTag=" & BotVars.Clan & "&Gateway=" & realm & "&SortField=rank%20DESC,%20online%20desc&SortDir=Asc&PageNo=" & j))           
            Else
              data = CStr(ScInet.OpenURL("http://classic.battle.net/war3/ladder/" & prod & "-clan-profile.aspx?ClanTag=" & BotVars.Clan & "&Gateway=" & realm & "&SortField=rank%20DESC,%20online%20desc&SortDir=Asc&PageNo=" & j))           
            End If
           
            dataIso = Split(Split(data, "Last Online</a></td>")(1), "</table>")(0)
            sSection = Split(dataIso, "<img src=""/war3/ladder/portraits/")

            For i = 1 To UBound(sSection)           
              temp = Mid(sSection(i), InStr(sSection(i), "rankingRow"">")+12)
              lOnline = Mid(temp, InStr(temp, "rankingRow"">")+12)
              lOnline = Left(lOnline, InStr(lOnline, "</")-2):lOnline = Replace(lOnline, CHR(9), vbNullString):lOnline = Replace(lOnline, vbNewLine, vbNullString):lOnline = Trim(lOnline)
             
              If InStr(lOnline, "Day") > 0 OR InStr(lOnline, "Days") > 0 Then
                  tDay = Left(lOnline, InStr(lOnline, " ")-1)
                  If (Int(tDay) => Int(GetSettingsEntry("DaysInactive"))) Then
                    temp = Mid(sSection(i), InStr(sSection(i), "PlayerName=")+11)
                    temp = Mid(temp, InStr(temp, """>")+2)
                    pName = Left(temp, InStr(temp, "</a")-1)
                    If NOT GetDBEntry(pName).HasFlag(GetSettingsEntry("ExemptFlag")) Then
                        addchat vbGreen, pName & " is inactive for " & tDay & " day(s)."
                        clanInactives.Item(pName) = True
                    End If
                  End If
              End If
            Next             
        Next
       
        If clanInactives.Count > 0 Then
            cmd.Respond clanInactives.Count & " inactive members found. Removal initialized."
            RemoveMembers.Enabled = True
        End If                   
  End Select
End Sub
                             

Sub RemoveMembers_Timer()

  If clanInactives.Count > 0 Then
      a = clanInactives.Keys
      AddChat vbGreen, "Removing " & a(0)
      Clan.GetMember(a(0)).Kickout
      clanInactives.Remove a(0)
  Else
      RemoveMembers.Enabled = False     
  End If     
End Sub

Private Sub CreateCmds()

  If GetSettingsEntry("DaysInactive")=vbNullString Then WriteSettingsEntry "DaysInactive", 40
  If GetSettingsEntry("ExemptFlag")=vbNullString Then WriteSettingsEntry "ExemptFlag", "S"

  Set cmd = OpenCommand("clanclean")
  If cmd Is Nothing Then
                Set cmd = CreateCommand("clanclean")       
      With cmd
        .Description = "Removes all clan users who are inactive for X amount of days."
        .RequiredRank = 200
        .Save
      End With
  End If
End Sub


Private Function maxPages(prod, clan, realm)
 
  If NOT ScInet.StillExecuting Then
      If realm = "kalimdor" Then
        data = CStr(ScInet.OpenURL("http://asialadders.battle.net/war3/ladder/" & prod & "-clan-profile.aspx?Gateway=" & realm & "&ClanTag=" & clan))
      Else
        data = CStr(ScInet.OpenURL("http://classic.battle.net/war3/ladder/" & prod & "-clan-profile.aspx?Gateway=" & realm & "&ClanTag=" & clan))
      End If
     
      If InStr(data, "Error") Then
        maxPages = "Battle.net is currently down or the website is updating. Please try again later."
        Exit Function
      End If
           
      temp = Split(data, "pageno=")(10000000)
      temp = Left(temp, 1)
     
      maxPages = CInt(temp)
  End If
End Function

 
Private Function GetRealm(server)
   
  If InStr(LCase(server), "battle.net") > 0 Then
      If InStr(Lcase(server), "useast")>0 Then
        GetRealm = "azeroth"
      ElseIf InStr(Lcase(server), "uswest")>0 Then
        GetRealm = "lordaeron"
      ElseIf InStr(Lcase(server), "europe")>0 Then
        GetRealm = "northrend"
      ElseIf InStr(Lcase(server), "asia")>0 Then
        GetRealm = "kalimdor"
      End If
  Else
      If InStr(server, "63.240.") Then
        GetRealm = "azeroth"
      ElseIf InStr(server, "63.241.") Then
        GetRealm = "lordaeron"
      ElseIf InStr(server, "213.248.") Then
        GetRealm = "northrend"
      ElseIf InStr(server, "211.233.") Then
        GetRealm = "kalimdor"
      End If
  End If       
End Function

[/spoiler]


Thanks for all your help in advance!

Viewing all articles
Browse latest Browse all 21273

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>