LerN Posted April 16, 2017 Share Posted April 16, 2017 Is that possible to use 2 for loops at the same time ? i don't think so, i have tried something like that but didn't work at all ... Local $loop $read = FileReadToArray($filename1) $read2 = FileReadToArray($filename2) For $i2 = 1 to ubound($read2) - 1 For $i3 = 1 to UBound($readdate) - 1 $loop &= $read[$i] & $read2[$i3] msgbox(0,"",$loop) Next Next ^ this code will work at the first time but the second time it will only read from second for loop so do u have any idea ? Link to comment Share on other sites More sharing options...
Kaworu Posted April 16, 2017 Share Posted April 16, 2017 Hi LerN, Not sure what you want to do, but you have undeclared variables like $i, $readdate. Local $loop $read = FileReadToArray($filename1) $read2 = FileReadToArray($filename2) For $i = 1 to ubound($read) - 1 For $j = 1 to UBound($read2) - 1 $loop &= $read[$i] & $read2[$j] msgbox(0,"",$loop) Next Next Link to comment Share on other sites More sharing options...
LerN Posted April 16, 2017 Author Share Posted April 16, 2017 Just now, Kaworu said: Hi LerN, Not sure what you want to do, but you have undeclared variables like $i, $readdate. Local $loop $read = FileReadToArray($filename1) $read2 = FileReadToArray($filename2) For $i = 1 to ubound($read) - 1 For $j = 1 to UBound($read2) - 1 $loop &= $read[$i] & $read2[$j] msgbox(0,"",$loop) Next Next That isn't the problem actually when u make loops like ^ first messagebox will read everything fine in the 2 files but the second messagebox will read the same for $read but it will update $read2 to the second line the in txt file that's the problem Link to comment Share on other sites More sharing options...
LerN Posted April 16, 2017 Author Share Posted April 16, 2017 Also yea i was wrong in using $readdate it must be $read2 Link to comment Share on other sites More sharing options...
Kaworu Posted April 16, 2017 Share Posted April 16, 2017 So could you please explain what would you like to achieve? What do you want msgbox to display when for loops through the array. Link to comment Share on other sites More sharing options...
czardas Posted April 17, 2017 Share Posted April 17, 2017 (edited) Understand that the second (internal loop) has to be completed (looped through entirely) on each iteration of the first loop. So if you were to read letters during the first loop, and numbers during the second loop; then the output might look something like this: A1, A2, A3 ==> B1, B2, B3 ==> C1, C2, C3 etc... It sounds to me that you want it to work differently: A1, B2, C3 etc... but that's not how it works. Edited April 17, 2017 by czardas operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
Subz Posted April 17, 2017 Share Posted April 17, 2017 Try something like: Local $sFileName1 = @ScriptDir & "\Filename1.txt" Local $sFileName2 = @ScriptDir & "\Filename2.txt" Local $aRead1 = FileReadToArray($sFileName1) Local $aRead2 = FileReadToArray($sFileName2) ;~ Assign smallest array count to $iRead Local $iRead = UBound($aRead1) > UBound($aRead2) ? UBound($aRead2) - 1 : UBound($aRead1) - 1 For $i = 0 To $iRead ConsoleWrite($aRead1[$i] & $aRead2[$i] & @CRLF) Next Link to comment Share on other sites More sharing options...
LerN Posted April 17, 2017 Author Share Posted April 17, 2017 Thank you Subz ! but could you please explain ? and : expression cuz i didn't understand it from the help file Link to comment Share on other sites More sharing options...
LerN Posted April 17, 2017 Author Share Posted April 17, 2017 and what if i wanted to add more files ? Link to comment Share on other sites More sharing options...
mikell Posted April 17, 2017 Share Posted April 17, 2017 56 minutes ago, LerN said: please explain ? and : expression Ternary operator result = (is this condition true) ? (if yes return this) : (if no return that) Link to comment Share on other sites More sharing options...
LerN Posted April 17, 2017 Author Share Posted April 17, 2017 Thank you mikell ! but could you tell me if i can use more than ? and more than : ... ? something like that : Local $sFileName1 = @ScriptDir & "\Filename1.txt" Local $sFileName2 = @ScriptDir & "\Filename2.txt" Local $sFileName3 = @ScriptDir & "\Filename3.txt" Local $sFileName4 = @ScriptDir & "\Filename4.txt" Local $aRead1 = FileReadToArray($sFileName1) Local $aRead2 = FileReadToArray($sFileName2) Local $aRead3 = FileReadToArray($sFileName3) Local $aRead4 = FileReadToArray($sFileName4) ;~ Assign smallest array count to $iRead Local $iRead = UBound($aRead1) > UBound($aRead2) > ubound($aread3) > ubound($aread4) ? UBound($aRead2) - 1 : UBound($aRead1) - 1 For $i = 0 To $iRead ConsoleWrite($aRead1[$i] & $aRead2[$i] & @CRLF) Next could you tell me how can i do that ? Link to comment Share on other sites More sharing options...
LerN Posted April 17, 2017 Author Share Posted April 17, 2017 Okay i have solved my problem by trying thanks all 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