Sign in to follow this  
Followers 0
EndFunc

Quick array help?

7 posts in this topic

I have the function I'm trying to do which is supposed to read lines in a txt file but its not working. I tried to use arrays to do it below but its not working. I need it to read everline until its done and output it to an edit box. Is there a way to do this with Arrays? Should I even use arrays to do this? Any help or suggestions is appreciated.

Func iRetrieve() ;Retrieve individual files or folders saved during transfer
GUICtrlSetData($Console,"Checking for individual files or folders to retrieve." & @CRLF & @CRLF, 1)
If FileExists(@ScriptDir & "\statusf") Then
$sFile = FileOpen(@ScriptDir & "\statusf", 0)
Local $iFRet = FileReadLine(@ScriptDir & "\statusf")
Local $fArray = _ArrayCreate($iFRet)
For $s = 1 To $fArray[0]
;_ArrayDisplay($fArray[0], $AppTitle)
GUICtrlSetData($Console, "Retrieving individual file " & $fArray[$s] & " saved to " & @ComputerName & @CRLF & @CRLF, 1)
Next
ElseIf FileExists(@ScriptDir & "\statusd") Then
$rFile = FileOpen(@ScriptDir & "\statusd", 0)
Local $iDRet = FileReadLine(@ScriptDir & "\statusd")
Local $rArray = _ArrayCreate($iDRet)
For $r = 1 To $rArray[0]
GUICtrlSetData($Console, "Retrieving indiviual folder " & $rArray[$r] & " saved to " & @ComputerName & @CRLF & @CRLF, 1)
Next
Else
GUICtrlSetData($Console,"No individual files or folders to retrieve." & @CRLF, 1)
EndIf   
EndFunc

EndFuncAutoIt is the shiznit. I love it.

Share this post


Link to post
Share on other sites



I edit you code to be correct... Spot the difference!

Func iRetrieve() ;Retrieve individual files or folders saved during transfer
GUICtrlSetData($Console,"Checking for individual files or folders to retrieve." & @CRLF & @CRLF, 1)
If FileExists(@ScriptDir & "\statusf.txt") Then
$sFile = FileOpen(@ScriptDir & "\statusf.txt", 0)
Local $iFRet = FileReadLine(@ScriptDir & "\statusf.txt")
Local $fArray = _ArrayCreate($iFRet)
For $s = 1 To $fArray[0]
_ArrayDisplay($fArray[0], $AppTitle)
GUICtrlSetData($Console, "Retrieving individual file " & $fArray[$s] & " saved to " & @ComputerName & @CRLF & @CRLF, 1)
Next
ElseIf FileExists(@ScriptDir & "\statusd.txt") Then
$rFile = FileOpen(@ScriptDir & "\statusd.txt", 0)
Local $iDRet = FileReadLine(@ScriptDir & "\statusd.txt")
Local $rArray = _ArrayCreate($iDRet)
For $r = 1 To $rArray[0]
GUICtrlSetData($Console, "Retrieving indiviual folder " & $rArray[$r] & " saved to " & @ComputerName & @CRLF & @CRLF, 1)
Next
Else
GUICtrlSetData($Console,"No individual files or folders to retrieve." & @CRLF, 1)
EndIf   
EndFunc

I thinks thats what you want...

Share this post


Link to post
Share on other sites

I edit you code to be correct... Spot the difference!

Func iRetrieve() ;Retrieve individual files or folders saved during transfer
GUICtrlSetData($Console,"Checking for individual files or folders to retrieve." & @CRLF & @CRLF, 1)
If FileExists(@ScriptDir & "\statusf.txt") Then
$sFile = FileOpen(@ScriptDir & "\statusf.txt", 0)
Local $iFRet = FileReadLine(@ScriptDir & "\statusf.txt")
Local $fArray = _ArrayCreate($iFRet)
For $s = 1 To $fArray[0]
_ArrayDisplay($fArray[0], $AppTitle)
GUICtrlSetData($Console, "Retrieving individual file " & $fArray[$s] & " saved to " & @ComputerName & @CRLF & @CRLF, 1)
Next
ElseIf FileExists(@ScriptDir & "\statusd.txt") Then
$rFile = FileOpen(@ScriptDir & "\statusd.txt", 0)
Local $iDRet = FileReadLine(@ScriptDir & "\statusd.txt")
Local $rArray = _ArrayCreate($iDRet)
For $r = 1 To $rArray[0]
GUICtrlSetData($Console, "Retrieving indiviual folder " & $rArray[$r] & " saved to " & @ComputerName & @CRLF & @CRLF, 1)
Next
Else
GUICtrlSetData($Console,"No individual files or folders to retrieve." & @CRLF, 1)
EndIf   
EndFunc

I thinks thats what you want...

Thanks, but the difference I see is that you put the files with .txt ext on them. I actually left them off on purpose becaues it still writes to it fine but now I'm just trying to read from it. I end up getting nothing. It doesn't error but it doesn't read the file and put the data in the edit box.

Any other suggestions?


EndFuncAutoIt is the shiznit. I love it.

Share this post


Link to post
Share on other sites

Thanks, but the difference I see is that you put the files with .txt ext on them. I actually left them off on purpose becaues it still writes to it fine but now I'm just trying to read from it. I end up getting nothing. It doesn't error but it doesn't read the file and put the data in the edit box.

Any other suggestions?

Ok.... Is there any chance of the full code? It'll make it easier to see how to fix the problem.

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Ok.... Is there any chance of the full code? It'll make it easier to see how to fix the problem.

Hey ok, I redid after finding _Filereadtoarray() and it half way works now. The problem is it only does the first Case and not both even though both conditions are true. Any suggestions with the Case? The code is pretty long but if you need it can post.

While 1
    $rMsg = GUIGetMsg()
 Select 
    Case $rMsg
    If FileExists(@ScriptDir & "\statusf") Then
    Local $iFRet 
    If Not _FileReadToArray(@ScriptDir & "\statusf",$iFRet) Then
       MsgBox(4096,"Error", " Error reading log to Array     error:" & @error)
       Exit
    EndIf
    For $f = 1 To $iFRet[0]
    GUICtrlSetData($Console, "Retrieving individual file " & $iFRet[$f] & " saved to " & @ComputerName & @CRLF & @CRLF, 1)
    Next
    EndIf
    Case $rMsg
    If FileExists(@ScriptDir & "\statusd") Then
    Local $iDRet 
    If Not _FileReadToArray(@ScriptDir & "\statusd",$iDRet) Then
       MsgBox(4096,"Error", " Error reading log to Array     error:" & @error)
       Exit
    EndIf
    For $r = 1 To $iDRet[0]
    GUICtrlSetData($Console, "Retrieving individual folder" & $iDRet[$r] & " saved to " & @ComputerName & @CRLF & @CRLF, 1)
    Next
    EndIf
EndSelect
ExitLoop
WEnd
Edited by EndFunc

EndFuncAutoIt is the shiznit. I love it.

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

hi,

; you have not shown the case options "Case $rMsg="1" or whatever, to let a case be chosen?

Randall

Geez, all along I had it. I guess I'm tired and need sleep. It works pefect if I just take it out of the loop because its a function.

Thanks for the help

If FileExists(@ScriptDir & "\statusf") Then
    Local $iFRet 
    If Not _FileReadToArray(@ScriptDir & "\statusf",$iFRet) Then
       MsgBox(4096,"Error", " Error reading log to Array     error:" & @error)
       Exit
    EndIf
    For $f = 1 To $iFRet[0]
    GUICtrlSetData($Console, "Retrieving individual file " & $iFRet[$f] & " saved to " & @ComputerName & @CRLF & @CRLF, 1)
    Next
    EndIf
    If FileExists(@ScriptDir & "\statusd") Then
    Local $iDRet 
    If Not _FileReadToArray(@ScriptDir & "\statusd",$iDRet) Then
       MsgBox(4096,"Error", " Error reading log to Array     error:" & @error)
       Exit
    EndIf
    For $r = 1 To $iDRet[0]
    GUICtrlSetData($Console, "Retrieving individual folder" & $iDRet[$r] & " saved to " & @ComputerName & @CRLF & @CRLF, 1)
    Next
    EndIf
Edited by EndFunc

EndFuncAutoIt is the shiznit. I love it.

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  
Followers 0