Darien

"For...In" not working with _FileReadToArray

6 posts in this topic

#1 ·  Posted

Hello,

 

When executing the script below (file "Excecoes_Desktop.txt" attached), the "For ... In" loop does not execute. I wonder why?

 

#include <File.au3>

Dim $matriz_excecoes_predefinidas [1]
_FileReadToArray ( "C:\Excecoes_Desktop.txt" , $matriz_excecoes_predefinidas , 0 , Chr(9) )

_ArrayDisplay ($matriz_excecoes_predefinidas)

For $excecao_predefinida In $matriz_excecoes_predefinidas

    MsgBox(0,"",$excecao_predefinida)

Next

Excecoes_Desktop.txt

Share this post


Link to post
Share on other sites



#2 ·  Posted

The _ArrayDisplay() also doesn't do anything ...right?

I think you wan to change this line:

_FileReadToArray ( "Excecoes_Desktop.txt" , $matriz_excecoes_predefinidas)

Jos


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

For me the _ArrayDisplay() works. You should not have copied the file "Excecoes_Desktop.txt" to C:

Edited by Darien

Share this post


Link to post
Share on other sites

#4 ·  Posted

Agree...  but try anyway what I suggested.  With those parameters, the array changes from single to multiple columns which causes the issue in the For ..In loop.

Jos 


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

I did, I had to remove the CHR (9):

 

#include <File.au3>

Dim             $matriz_excecoes_predefinidas [1]
_FileReadToArray ( "C:\Excecoes_Desktop.txt" , $matriz_excecoes_predefinidas , 0 )

_ArrayDisplay ($matriz_excecoes_predefinidas)

For $excecao_predefinida In $matriz_excecoes_predefinidas

    MsgBox(0,"",$excecao_predefinida)

Next

Thank you.

Edited by Darien

Share this post


Link to post
Share on other sites

#6 ·  Posted

Please note that if you use a For/To loop instead of a For/In, like this

For $i = 1 to UBound($matriz_excecoes_predefinidas)-1 
    MsgBox(0,"",$matriz_excecoes_predefinidas[$i])
Next

then you get an error msgbox with the cause of the failure written inside  :)

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now