Jump to content

How to save one array in another


Docfxit
 Share

Go to solution Solved by kylomas,

Recommended Posts

I have successfully saved a registry key in $a[0].  Because $a is used in a different routine I'd like to save the contents of $a in another array that I chose called $Entries.  There will always be one line with a number of columns $a.  I need to increment $Entries to put each line of $a into a new line of $Entries so I can write $Entries to a file later.  I couldn't figure out how to write each line of $a to a file adding each line to the same file. That's the reason for saving the line into $Entries to be written to the file later.

#RequireAdmin
#include <Array.au3>
#include <File.au3>
#include <_RegEnumKeyValEx.au3>
; The above #included script was written by DXRW4E
;     and can be found here: http://www.autoitscript.com/forum/topic/144234-regenumkeyvalex-regenumkeyex-regenumvalex/?p=1207033


Global $Entries[5] [5], $a, $t, $i, $Error, $Extended, $KeyName

$i += 1
$KeyName = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon"
$a = _RegEnumValEx($KeyName, 128 + 256 + 32, "AutoAdminLogon")
ConsoleWrite("Return = " & $a & " - $Error = " & $Error & " - $Extended = " & $Extended & @LF)
_ArrayDisplay($a)
$Entries[$i][0] = $a
_ArrayDisplay($Entries) ;Does not show anything added

What am I doing wrong in saving the line of $a into the array $Entries?

Thank you,

Docfxit

Edited by Docfxit
Link to comment
Share on other sites

Hi Docfxit

you are storing the whole array $a into one element of the array $Entries, and this is ok, doing so you are making an array of arrays, what you are doing wrong is trying to display it with _ArrayDisplay, you can't show with _ArrayDisply an array of arrays.
You have to extract back the Array stored in $Entries and then use _ArrayDisplay to display it. Something like this:

_ArrayDisplay($a)
$Entries[$i][0] = $a
; ....
$b = $Entries[$i][0] ; retrieve the array
_ArrayDisplay($b)

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Link to comment
Share on other sites

Thank you for the reply...

The array of an array is getting too complicated.  I found out how to append to a file, so I'd like to figure out what is wrong with this code.  I'm getting an error saying:

"C:ProgramsAutoIt3IncludeFile.au3" (660) : ==> Error parsing function call.:
Func _FileWriteFromArray($sFilePath, Const ByRef $aArray, $iBase = Default, $iUBound = Default, $sDelimeter = "|")
Func _FileWriteFromArray($sFilePath, Cons^ ERROR
 

#RequireAdmin
#include <Array.au3>
#include <File.au3>
#include <FileConstants.au3>
#include <_RegEnumKeyValEx.au3>
; The above #included script was written by DXRW4E
;     and can be found here: http://www.autoitscript.com/forum/topic/144234-regenumkeyvalex-regenumkeyex-regenumvalex/?p=1207033
;AutoIt_Debugger_Command:Enable_Debug

Global $a, $t, $i, $Error, $Extended, $KeyName
Local Const $ExtensionsFile = @ScriptDir & "\%OriginalRegistryKeys.txt"
Local $hExtensionsFile = FileOpen($ExtensionsFile, $FO_APPEND)
FileCreate($hExtensionsFile, "")

$i += 1
$KeyName = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon"
$a = _RegEnumValEx($KeyName, 128 + 256 + 32, "AutoAdminLogon")
_FileWriteFromArray($hExtensionsFile, $a & @CRLF)

 FileClose($hExtensionsFile)

; Create a file.
Func FileCreate($hExtensionsFile, $sString)
    Local $bReturn = True ; Create a variable to store a boolean value.
    If FileExists($hExtensionsFile) = 0 Then $bReturn = FileWrite($hExtensionsFile, $sString) = 1 ; If FileWrite returned 1 this will be True otherwise False.
    Return $bReturn ; Return the boolean value of either True of False, depending on the return value of FileWrite.
EndFunc   ;==>FileCreate

Thank you,

Docfxit

Link to comment
Share on other sites

  • Solution

Change

_FileWriteFromArray($hExtensionsFile, $a & @CRLF)

to

_FileWriteFromArray($hExtensionsFile, $a)

You could have referenced your array within an array like this...

_ArrayDisplay($Entries[0])

kylomas

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

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...