Jump to content
Sign in to follow this  
Zein

FileReadToArray parameter count?

Recommended Posts

#include "..\Include\Array.au3"
#include "..\Include\File.au3"
#include "..\Include\AutoItConstants.au3"

Local $aRetArray
Local $sFilePath = "n.csv"

 _FileReadToArray($sFilePath, $aRetArray, ",")
; _FileReadToArray($sFilePath, $aRetArray, $FRTA_COUNT, ",")
 _ArrayDisplay($aRetArray, "Original", Default, 8)

The above code shows two versions of _FileReadToArray and both don't work as expected.
The first one doesn't use the comma as a delimiter. (so I get a single column array)  I tried adding "Default" between $aRetArray and "," then it told me it had an incorrect number of parameters. 

I looked again at the documentation:
 

#include <File.au3>
_FileReadToArray ( $sFilePath, ByRef $vReturn [, $iFlags = $FRTA_COUNT [, $sDelimiter = ""]] )


And I with or without the flags params I should be getting a 2D array due to my file being a csv. 
I then tried a regular flag, $FRTA_COUNT, and it tells me that I'm using a variable $FRTA_COUNT while it's not declared. Tried putting in 1 instead and it told me again, incorrect number of params. 

 

Share this post


Link to post
Share on other sites

Your call to _FileReadToArray in the code above has the wrong parameter in the third position. Try 

_FileReadToArray($sFilePath, $aRetArray, $FRTA_COUNT, ",")

As for it returning a 2D, if you could post an example of the csv that would help greatly to determine whether you need to use the $FRTA_INTARRRAYS parameter.


"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Share this post


Link to post
Share on other sites

Sounds like you're using an older version of AutoIt.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
16 minutes ago, JLogan3o13 said:

Your call to _FileReadToArray in the code above has the wrong parameter in the third position. Try 

_FileReadToArray($sFilePath, $aRetArray, $FRTA_COUNT, ",")

As for it returning a 2D, if you could post an example of the csv that would help greatly to determine whether you need to use the $FRTA_INTARRRAYS parameter.

No matter what I do, having anything between $aRetArray and "," gives me an error.
This is a sample csv.

q/b,1,2,ST,1-MAN,9,p,
q/b,1,2,ST,1-MAN,9,p,
q/b-a,1,2,WD,1-MAN,2,p,
q/b-a,1,2,WD,1-MAN,6,p,
q/b,1,2,ST,1-MAN,1,p,
q/b-a,1,2,FF,1-MAN,7,p,
z/b-a,1,2,FF,1-MAN,2,p,
z/b-a,1,2,FF,1-MAN,6,p,
z/b-a,1,3,FF,1-MAN,2,p,

 

 

15 minutes ago, BrewManNH said:

Sounds like you're using an older version of AutoIt.

I'm not working on a computer I can update it very easily on, but all my folders (Aut2Exe, AutoItX, Examples, Include, SciTE, etc.) are all dated 7/11/2018. The rest of the files in my AutoIt3 folder are dated back to 2013 besides the uninstall.exe which is also 7/11/2018.

Does that sound like too old a version of AutoIT to use _FileReadToArray?


Looked into the files and they're actually all from  2013. I'll work on getting it updated to the most recent version. Might not be able to though. Would that potentially break any of the code I'm currently using without issue? 

Edited by Zein

Share this post


Link to post
Share on other sites

This works fine for me:

#include "Array.au3"
#include "File.au3"
#include "AutoItConstants.au3"

Local $aRetArray[1000]
Local $sFilePath = "n.csv"

$rc=_FileReadToArray($sFilePath, $aRetArray, $FRTA_COUNT, ",")
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $rc = ' & $rc & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
_ArrayDisplay($aRetArray, "Original", Default, 8)

Jos


SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
1 hour ago, Jos said:

This works fine for me:

#include "Array.au3"
#include "File.au3"
#include "AutoItConstants.au3"

Local $aRetArray[1000]
Local $sFilePath = "n.csv"

$rc=_FileReadToArray($sFilePath, $aRetArray, $FRTA_COUNT, ",")
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $rc = ' & $rc & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
_ArrayDisplay($aRetArray, "Original", Default, 8)

Jos

Gives me the same error. I'll get my autoit updated.

Share this post


Link to post
Share on other sites
On 8/14/2018 at 12:50 PM, Jos said:

This works fine for me:

#include "Array.au3"
#include "File.au3"
#include "AutoItConstants.au3"

Local $aRetArray[1000]
Local $sFilePath = "n.csv"

$rc=_FileReadToArray($sFilePath, $aRetArray, $FRTA_COUNT, ",")
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $rc = ' & $rc & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
_ArrayDisplay($aRetArray, "Original", Default, 8)

Jos

Everything's updated. I keep getting $rc = 0 and then _ArrayDisplay says no array is being passed into it. 

Share this post


Link to post
Share on other sites

Ok, so my posted script gives you the clue why this (different data than posted earlier) is giving you problems:

Quote

@@ Debug(9) : $rc = 0
>Error code: 3

This means that _FileReadToArray() returns 0 and Error 3 meaning according the helpfile

Quote

Return Value

Success: 1 and $vReturn holds an array.
Failure: 0, @error flag set to non-zero and $vReturn is set to 0.
@error: 1 - Error opening specified file
2 - Unable to split the file
3 - File lines have different numbers of fields (only if $FRTA_INTARRAYS flag not set)
4 - No delimiters found (only if $FRTA_INTARRAYS flag not set)

Which is indeed the case when you look at your file!

Jos

 


SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

This example will create an 2D array with variable row lengths from a file.
I would be surprised if this didn't run on older AutoIt versions.

#include <array.au3>

Local $sFileName = "test.csv"

Local $hTimer = TimerInit() ; Begin the timer and store the handle in a variable.

$a1DArray = FileReadToArray($sFileName) ; Create 1D array
;_ArrayDisplay($a1DArray)

Local $a2DArray = _Array1DToVariableRow2D($a1DArray, "/-.,") ; Note: 1 or many row delimiters.
ConsoleWrite(StringFormat("Time taken: %.3f secs", TimerDiff($hTimer) / 1000) & @CRLF)

_ArrayDisplay($a2DArray)


; Parameter - "$a" is a 1D array.
; Output is a 2D array
;
Func _Array1DToVariableRow2D($a, $sRowDelimiter = ",")
    Local $iNumRows = UBound($a)
    Local $aRetArray[$iNumRows][300] ; For really large 2D array to be ReDim latter when the maximum number of columns is found.
    Local $MCol ; Max number of columns from all rows.

    For $r = 0 To $iNumRows - 1
        $aTemp = StringSplit($a[$r], $sRowDelimiter, 2)
        If UBound($aTemp) > $MCol Then
            $MCol = UBound($aTemp)
            If $MCol > UBound($aRetArray) Then ReDim $aRetArray[UBound($aRetArray)][UBound($aRetArray, 2) + 300]
        EndIf
        For $c = 0 To UBound($aTemp) - 1
            $aRetArray[$r][$c] = $aTemp[$c]
        Next
    Next
    ReDim $aRetArray[$iNumRows][$MCol]
    Return $aRetArray
EndFunc   ;==>_Array1DToVariableRow2D

 

Share this post


Link to post
Share on other sites
On 8/17/2018 at 5:20 PM, Jos said:

Ok, so my posted script gives you the clue why this (different data than posted earlier) is giving you problems:

This means that _FileReadToArray() returns 0 and Error 3 meaning according the helpfile

Which is indeed the case when you look at your file!

Jos

 

I fixed it and the same error occurs. The csv I gave you was just a stripped version of my actual csv which has some-what private data. And opening my original in Excel shows that the rows are all aligned with the same number of fields. I think the error was actually a blank line at the end of my csv. Which, would yield the error I guess that some rows had different fields.

 

 

On 8/17/2018 at 10:28 PM, Malkey said:

This example will create an 2D array with variable row lengths from a file.
I would be surprised if this didn't run on older AutoIt versions.

#include <array.au3>

Local $sFileName = "test.csv"

Local $hTimer = TimerInit() ; Begin the timer and store the handle in a variable.

$a1DArray = FileReadToArray($sFileName) ; Create 1D array
;_ArrayDisplay($a1DArray)

Local $a2DArray = _Array1DToVariableRow2D($a1DArray, "/-.,") ; Note: 1 or many row delimiters.
ConsoleWrite(StringFormat("Time taken: %.3f secs", TimerDiff($hTimer) / 1000) & @CRLF)

_ArrayDisplay($a2DArray)


; Parameter - "$a" is a 1D array.
; Output is a 2D array
;
Func _Array1DToVariableRow2D($a, $sRowDelimiter = ",")
    Local $iNumRows = UBound($a)
    Local $aRetArray[$iNumRows][300] ; For really large 2D array to be ReDim latter when the maximum number of columns is found.
    Local $MCol ; Max number of columns from all rows.

    For $r = 0 To $iNumRows - 1
        $aTemp = StringSplit($a[$r], $sRowDelimiter, 2)
        If UBound($aTemp) > $MCol Then
            $MCol = UBound($aTemp)
            If $MCol > UBound($aRetArray) Then ReDim $aRetArray[UBound($aRetArray)][UBound($aRetArray, 2) + 300]
        EndIf
        For $c = 0 To UBound($aTemp) - 1
            $aRetArray[$r][$c] = $aTemp[$c]
        Next
    Next
    ReDim $aRetArray[$iNumRows][$MCol]
    Return $aRetArray
EndFunc   ;==>_Array1DToVariableRow2D

 

Works without issue! Thank you!

 

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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By learner123
      Hi All,
       
      I am new to this AUTO IT and I have created a script that will open an app,enter pin and copy the code generated to clipboard. My java code call this autoIT script and use the copied generated code from clipboard.
      This works fine when server  window is on focus. My server is an windows server. 
      But when I minimize or disconnect the server, the script opens the app.exe but doesn't copy any value to clipboard.  
      Can anyone help me on this 😐
       
      Run("C:\Program Files (x86)\RSA SecurID Software Token\SecurID.exe")
      Local $hWnd=WinWait("abc - RSA SecurID Token") ; waits until the window is the active window
      $hWin = WinGetHandle("abc - RSA SecurID Token");
      ControlSend($hWnd,"","","1111") ; simulates pressing the Home key
      ControlSend($hWnd,"","","{ENTER}");
      ControlSend($hWnd,"","","^c");
      Sleep(1000) ;
      ControlSend($hWnd,"","","^c");
       
    • By learner123
      Hi All,
      So I have created a small autoIT script to enter pin into a RSA token(app which generate new code every 30 second), and copy the generated code.
      I have a java application which requires this code so every time my java-code requires this RSA code, it runs the autoIT script and the copied generated code is then used in my java application. 
      I have deployed this code on a windows server and it works fine when I am logged in and the window is on focus, But as soon as I schedule task and disconnect the server (not logged out only disconnect), or even minimize the server window, the autoIT scripts fails and its not able to copy the value.
       
      Please find below the code for AUTOIT.
       
      WinActivate("rsa - RSA SecurID Token") ; activates the window that has old in the tilte bar
      WinWaitActive("rsa - RSA SecurID Token") ; waits until the window is the active window
      Send("1111") ; simulates pressing the Home key, enters password to get the code
      Send("{ENTER}") ; simulates pressing the Enter key
      Sleep(1000) ;
      Send("^c") ; simulates pressing the CTRL+c keys (copy)
       
      Also I saw some post regarding that WINACTIVE only works when window is active. But my below AUTO IT script to handle windows pop up  works perfectly fine when the server is disconnected. 
       
      Opt("WinTitleMatchMode", 1)
      WinWait("https://url","","10")
      WinWaitActive("https://url","","10")
      Sleep(2000)
      Send("userid")
      Sleep(1000)
      Send("{TAB}")
      Sleep(1000)
      Send("passwrd")
      Send("{TAB}")
      Sleep(500)
      Send("{ENTER}")
       
       
    • By JuanFelipe
      Hello gyus, I try to make a code to login in a web page in my job, buy i can’t understand why my form is blocked, this is my code: 
      #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <StringConstants.au3> #include <WindowsConstants.au3> #include <WinAPIFiles.au3> #include <FileConstants.au3> #include <File.au3> #include <Array.au3> #include <IE.au3> #include <Excel.au3> #include <GuiEdit.au3> #include <GuiStatusBar.au3> #include <DateTimeConstants.au3> #include <Date.au3> #Region ### START Koda GUI section ### Form=C:\noentry\koda_1.7.3.0\Forms\spoa.kxf $Form1 = GUICreate("Eva y Vehículos", 1200, 1000, 10, 10) $prueba = GUICtrlCreateButton("Prueba",10,990,50,20) ;VARIABLES ========================================================================================== $psi = "https://psi.policia.gov.co/PSI/Login.aspx?ReturnUrl=%2fPSI#no-back-button" $chequeVehiculos = "https://psi.policia.gov.co/PSI/frm_lista_chk.aspx" $evaluacionEva = "https://psi.policia.gov.co/PSI/eva_frmver.aspx" $oIE = ObjCreate("Shell.Explorer.2") $GUIActiveX = GUICtrlCreateObj ($oIE, 10, 10, 1180, 980) ;GUICtrlSetState(-1, $GUI_DISABLE) GUISetState(@SW_SHOW) $oIE.navigate($psi) ;_IELoadWait($oIE) _InicioSesion() #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $prueba _InicioSesion() EndSwitch WEnd Func _InicioSesion() Local $username = _IEGetObjByName($oIE, "txtUsuario") Local $pass = _IEGetObjByName($oIE, "txtClave") Local $logina = _IEGetObjByName($oIE, "btnIngresar") $username.value="example" $pass.value="examplepass" _IEAction($logina, 'click') _IELoadWait($oIE) MsgBox(16,"","") EndFunc  
    • By shelly
      Here is the below code for handling pop-up when window is  inactive ..but I don't know how to change sleep and when i run this script it runs sometimes and sometimes it stops .
      ControlSend("Policy Decisions -- Webpage Dialog","","Internet Explorer_Server1","{SPACE}")
      ControlSend("Policy Decisions -- Webpage Dialog","","Internet Explorer_Server1","{DOWN}")
      ControlSend("Policy Decisions -- Webpage Dialog","","Internet Explorer_Server1","{ENTER}")
      --- these 3 lines never worked while TAB lines works sometimes but not in accurate way
      I am new too AutoIt .. help me out why this script behaves in strange way
      ControlFocus("Policy Decisions -- Webpage Dialog","","Internet Explorer_Server1")
      Sleep(3000)
      ControlSend("Policy Decisions -- Webpage Dialog", "", "Internet Explorer_Server1","1")
      ControlSend("Policy Decisions -- Webpage Dialog","","Internet Explorer_Server1","{TAB}")
      ControlSend("Policy Decisions -- Webpage Dialog", "", "Internet Explorer_Server1","the request is send")
      Sleep(3000)
      ControlSend("Policy Decisions -- Webpage Dialog","","Internet Explorer_Server1","{TAB}")
      ControlSend("Policy Decisions -- Webpage Dialog","","Internet Explorer_Server1","{TAB}")
      ControlSend("Policy Decisions -- Webpage Dialog","","Internet Explorer_Server1","{TAB}")
      ControlSend("Policy Decisions -- Webpage Dialog","","Internet Explorer_Server1","{TAB}")
      ControlSend("Policy Decisions -- Webpage Dialog","","Internet Explorer_Server1","{TAB}")
      ControlSend("Policy Decisions -- Webpage Dialog","","Internet Explorer_Server1","{TAB}")
      ControlSend("Policy Decisions -- Webpage Dialog","","Internet Explorer_Server1","{TAB}")
      Sleep(3000)
      ControlSend("Policy Decisions -- Webpage Dialog","","Internet Explorer_Server1","{TAB}")
      ControlSend("Policy Decisions -- Webpage Dialog","","Internet Explorer_Server1","{TAB}")
      ControlSend("Policy Decisions -- Webpage Dialog","","Internet Explorer_Server1","{TAB}")
      ControlSend("Policy Decisions -- Webpage Dialog","","Internet Explorer_Server1","{TAB}")
      ControlSend("Policy Decisions -- Webpage Dialog","","Internet Explorer_Server1","{TAB}")
      ControlSend("Policy Decisions -- Webpage Dialog","","Internet Explorer_Server1","{TAB}")
      Sleep(3000)
      ControlSend("Policy Decisions -- Webpage Dialog","","Internet Explorer_Server1","{TAB}")
      ControlSend("Policy Decisions -- Webpage Dialog","","Internet Explorer_Server1","{TAB}")
      ControlSend("Policy Decisions -- Webpage Dialog","","Internet Explorer_Server1","{SPACE}")
      Sleep(3000)
      ControlSend("Policy Decisions -- Webpage Dialog","","Internet Explorer_Server1","{TAB}")
      ControlSend("Policy Decisions -- Webpage Dialog","","Internet Explorer_Server1","{TAB}")
      Sleep(3000)
      ControlSend("Policy Decisions -- Webpage Dialog","","Internet Explorer_Server1","{TAB}")
      ControlSend("Policy Decisions -- Webpage Dialog","","Internet Explorer_Server1","{TAB}")
      Sleep(3000)
      ControlSend("Policy Decisions -- Webpage Dialog","","Internet Explorer_Server1","{TAB}")
      ControlSend("Policy Decisions -- Webpage Dialog","","Internet Explorer_Server1","{DOWN}")
      ControlSend("Policy Decisions -- Webpage Dialog","","Internet Explorer_Server1","{TAB}")
      Sleep(3000)
      ControlSend("Policy Decisions -- Webpage Dialog","","Internet Explorer_Server1","{TAB}")
      ControlSend("Policy Decisions -- Webpage Dialog","","Internet Explorer_Server1","{ENTER}")
       
×
×
  • Create New...