igotandrew Posted December 28, 2008 Share Posted December 28, 2008 (edited) So I started using IE.au3 in my program, and I have made a web crawler for various websites. I made this function to help with some stuff. It's supposed to get the id of a page. But when my internet explorer times out or doesn't load, I get Func GetID($url) Local $x, $y $x = StringSplit($url, "?showpage=", 1) $y = StringSplit($x[2], "&f=", 1) Return $y[1] EndFunc ;==>Get C:\Documents and Settings\Drew\Desktop\d2jsp SV3\d2jsp SV.au3 (302) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.: $y = StringSplit($x[2], "&f=", 1) $y = StringSplit(^ ERROR Is there a way to fix this? ------------------- Second problem, I know it's completely unrelated, however I was told to just edit the post instead of spamming the forums. Func GetIdText() Local $i, $line, $file, $id[1000] Local Const $FilePath = @ScriptDir & "\ID.txt" $i = 1 If FileExists($FilePath) Then $file = FileOpen("ID.txt", 0) While 1 $line = FileReadLine($file) $id[$i] = FileReadLine($file) If @error = -1 Then ExitLoop $i = $i + 1 Wend$id[0] = $i For $i = 0 to $id[0] Msgbox(0, 0, $id[$i]) Next Else ;L("No 'ID.txt' file found. Not loading any past ID files.") EndIf EndFunc GetIdtext() Here is id.txt 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 It still counts the Chr(10) or Chr(13) left by filewriteline, is there a way to get rid of it? Edited December 28, 2008 by igotandrew Link to comment Share on other sites More sharing options...
goldenix Posted December 28, 2008 Share Posted December 28, 2008 well if you wont give us a sord of working sample code I can be more specific. more likely. But so far I can only guess:Problem 1: dimension range exceeded.: means there is nothing in your array & you are trying to get non existing value. for example if your array lenght is $y[0] & you are trying to get a value from $y[1] it will error. use _ArrayDisplay after $y = StringSplit($x[2], "&f=", 1) this will show you the array contents:#include <Array.au3> $y = StringSplit($x[2], "&f=", 1) _ArrayDisplay($y, "")cant help you further hire, need an example that I can execute. My Projects:[list][*]Guide - ytube step by step tut for reading memory with autoitscript + samples[*]WinHide - tool to show hide windows, Skinned With GDI+[*]Virtualdub batch job list maker - Batch Process all files with same settings[*]Exp calc - Exp calculator for online games[*]Automated Microsoft SQL Server 2000 installer[*]Image sorter helper for IrfanView - 1 click opens img & move ur mouse to close opened img[/list] Link to comment Share on other sites More sharing options...
FireFox Posted December 28, 2008 Share Posted December 28, 2008 (edited) @igotandrew For have two strings so $x[2], your url have to contain "?showpage=" , so if your url contain 0 time "?showpage=" you will have an error so you cant fix function just change your url... Func GetID($url) Local $x, $y $x = StringSplit($url, "?showpage=", 1) $y = StringSplit($x[2], "&f=", 1) Return $y[1] EndFunc;==>Get Cheers, FireFox. Edited December 28, 2008 by FireFox Link to comment Share on other sites More sharing options...
igotandrew Posted December 28, 2008 Author Share Posted December 28, 2008 Try it with this url."http://www.site.com/index.php?showpage=12387&f=20"So my function would first split it$x[1] = http://www.site.com/index.php$x[2] = 12387&f=20Then we split $x[2] with "&f="then $x[1] = 12387$x[2] = 20I believe that's how I wrote it, using that logic. Link to comment Share on other sites More sharing options...
igotandrew Posted December 28, 2008 Author Share Posted December 28, 2008 (edited) Return Value Returns an array, the first element ($array[0]) contains the number of strings returned, the remaining elements ($array[1], $array[2], etc.) contain the delimited strings. Meaning 2 would appear in $x[0] Unless you're thinking of a different function or were not on the same page here. Edited December 28, 2008 by igotandrew Link to comment Share on other sites More sharing options...
PsaltyDS Posted December 29, 2008 Share Posted December 29, 2008 Return Value Returns an array, the first element ($array[0]) contains the number of strings returned, the remaining elements ($array[1], $array[2], etc.) contain the delimited strings. Meaning 2 would appear in $x[0] Unless you're thinking of a different function or were not on the same page here. If the input string doesn't contain the expected delimiter, you may not get the array you want, or as many elements as you expect. It needs some error handling. This example uses StringRegExp(), but you could put similar error handling on your own version: $sURL = "http://www.site.com/index.php?showpage=12387&f=20" $RET = GetID($sURL) $iErrRET = @error MsgBox(64, "Results", "$RET = " & $RET & @CRLF & "@error = " & $iErrRET) Func GetID($url) Local $y = StringRegExp($url, "(?:\?showpage=)(\d+)(?:&f=20)", 3) Local $iErrSav = @error If IsArray($y) Then Return SetError($iErrSav, 0, $y[0]) Else Return SetError($iErrSav, 0, "") EndIf EndFunc;==>Get Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now