Dgameman1 Posted December 12, 2015 Posted December 12, 2015 (edited) Here is the part of the code I'm currently having trouble withFor $Ti = 1 To _FileCountLines($UsernameFilePath) $line = FileReadLine($UsernameFilePath, $Ti) For $Ui = 0 To UBound($TexansUsernames) If $TexansUsernames[$Ui] == $line Then ConsoleWrite("1") Else ConsoleWrite("0") EndIf Next Next The goal is to go through all the txt in UsernameFilePath and compare with the array TexansUsername.I want it to get the first line of UsernameFilePath and check it through every TexansUsername, if there's a match, I want it to print 1, if there's no match, I would like it to print 0As it is right now, this is what occurs in the console 0100000000000000000000000000000000"C:\Users\Daniel\Desktop\TexansPmer.au3" (38) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.:If $TexansUsernames[$Ui] == $line ThenIf ^ ERROR Edited December 12, 2015 by Dgameman1
JohnOne Posted December 12, 2015 Posted December 12, 2015 Means nothing without both a sample file and sample array. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans.
Danp2 Posted December 12, 2015 Posted December 12, 2015 For $Ui = 0 To UBound($TexansUsernames)should be:For $Ui = 0 To UBound($TexansUsernames) - 1 Dgameman1 1 Latest Webdriver UDF Release Webdriver Wiki FAQs
Dgameman1 Posted December 13, 2015 Author Posted December 13, 2015 (edited) For $Ui = 0 To UBound($TexansUsernames)should be:For $Ui = 0 To UBound($TexansUsernames) - 1 Thank you so much.Much appreciated Edited December 13, 2015 by Dgameman1
Dgameman1 Posted December 13, 2015 Author Posted December 13, 2015 (edited) I changed my code a bit and I got the error againArray variable has incorrect number of subscripts or subscript dimension range exceeded.:If $GoneWildUsernames[$Ui] == $line ThenIf ^ ERROR$UsernameFileOpen = FileOpen($UsernameFilePath, 0) _ArrayDisplay($TexansUsernames) $TexansUsernames = _ArrayUnique($TexansUsernames) _ArrayDisplay($TexansUsernames) For $Ti = 1 To _FileCountLines($UsernameFilePath) $line = FileReadLine($UsernameFilePath, $Ti) For $Ui = 0 To UBound($TexansUsernames) - 1 If $TexansUsernames[$Ui] == $line Then _ArrayDelete($TexansUsernames, $Ui) Else ConsoleWrite($TexansUsernames[$Ui] & @LF) EndIf Next ConsoleWrite(@LF) NextHere is a picture of the list of $TexansUsernamesAnd let's just say the text inside of $UsertnamesFilePath isichru4jamt9000flyryanOoerImNotJesusverugancanipaybychecknoahjk Edited December 13, 2015 by Dgameman1
JohnOne Posted December 13, 2015 Posted December 13, 2015 When using _Arraydelete you need to loop through the array backwards, ubound -1 to 0 AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans.
Dgameman1 Posted December 14, 2015 Author Posted December 14, 2015 When using _Arraydelete you need to loop through the array backwards, ubound -1 to 0Thank you very much And just to make sure my code is working the way I want it.What it should do is go through and the selected Username is inside the File, then I want it to delete the username from the array.Does my code do that?
JohnOne Posted December 14, 2015 Posted December 14, 2015 It's not about the file, it's about the array.If you count up, and delete an element, it will not be there when you get to the count because it's been removed. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans.
Dgameman1 Posted December 14, 2015 Author Posted December 14, 2015 But when I use arraydisplay, nothing in has been deleted in the username array
JohnOne Posted December 14, 2015 Posted December 14, 2015 What is your new code? AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans.
kylomas Posted December 14, 2015 Posted December 14, 2015 (edited) Dgameman1,Try this quick and dirty (no error checking...)#include <array.au3> Local $aUsernames = FileReadToArray(@ScriptDir & '\usernames.txt') Local $aTexannames = FileReadToArray(@ScriptDir & '\texannames.txt') _ArrayDisplay(_RemoveTexanNames($aUsernames, $aTexannames)) Func _RemoveTexanNames(ByRef $a1, ByRef $a2) $a1 = _ArrayUnique($a1) $a2 = _ArrayUnique($a2) for $i = $a1[0] to 1 step -1 for $j = 1 to $a2[0] if $a1[$i] = $a2[$j] then _arraydelete($a1,$i) $a1[0] -= 1 ExitLoop EndIf Next next return $a1 EndFunc ;==>_RemoveTexanNameskylomas Edited December 14, 2015 by kylomas code correction Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill
mikell Posted December 14, 2015 Posted December 14, 2015 (edited) Assuming that there is a relationship with your previous topic, the fastest way by far is to use Scripting.DictionaryThis code gets the $TexansUsernames list from the site, then matches names in 'usernames.txt' which are present in the array $TexansUsernames and return them in a new array#Include <Array.au3> ; read usernames.txt into an array $aUsernames Local $aUsernames = FileReadToArray(@ScriptDir & '\usernames.txt') ; grab the TexansUsernames into an array $aTexansUsernames $source = BinaryToString(InetRead("https://www.reddit.com/r/texans", 1)) $aTexansUsernames = StringRegExp($source,'user/(.*?)"', 3) ;_ArrayDisplay($TexansUsernames) ; create the SD objects Local $sdUsernames = ObjCreate("Scripting.Dictionary") Local $sdTexansUsernames = ObjCreate("Scripting.Dictionary") Local $sdResult = ObjCreate("Scripting.Dictionary") ; fill the SD Usernames with the $aUsernames content For $i In $aUsernames $sdUsernames.Item($i) Next ; fill the SD TexansUsernames with the $aTexansUsernames content For $i In $aTexansUsernames $sdTexansUsernames.Item($i) Next ; compare and fill the SD Result For $i In $aUsernames If $sdTexansUsernames.Exists($i) Then $sdResult.Item($i) Next ; Build the $aResult array $aResult = $sdResult.Keys() _ArrayDisplay($aResult, "$aResult") Edited December 14, 2015 by mikell added comments
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