Jump to content

Recommended Posts

Posted (edited)

Good Day,

User, "Water", was kindly assisting me trying to get a "handle" on arrays, and though the information was 'interesting", I am still at al total loss to really-and-truly understand arrays.
• My only "issue" here is that Excel focuses on [Column-then-row, A1], rather than [Row-then-column, 1A].

Take, for example, the following:

Spoiler

; Part 1
Local $sKeyname = "HKEY_CURRENT_USER\Software\FabFilter\Pro-MB\1.0"
Local $sValuename = "showInteractiveHelp"
Local $sRegSZ = "REG_DWORD"
Local $sString = "00000000"

Local $sKeyname = "HKEY_CURRENT_USER\Software\FabFilter\Pro-MB\1.0"
Local $sValuename = "showWelcomeHint"
Local $sRegSZ = "REG_DWORD"
Local $sString = "00000000"

Local $sKeyname = "HKEY_CURRENT_USER\Software\FabFilter\Pro-MB\1.0"
Local $sValuename = Bundle"LicenseText"

Local $sKeyname = "HKEY_CURRENT_USER\Software\FabFilter\Pro-MB\1.0"
Local $sValuename = "LicenseText"
Local $sRegSZ = "REG_SZ"
Local $sString = "Product"

; Part 2
Local $sKeyname = "HKEY_CURRENT_USER\Software\FabFilter\Pro-Q\3.0"
Local $sValuename = "showInteractiveHelp"
Local $sRegSZ = "REG_DWORD"
Local $sString = "00000000"

Local $sKeyname = "HKEY_CURRENT_USER\Software\FabFilter\Pro-Q\3.0"
Local $sValuename = "showWelcomeHint"
Local $sRegSZ = "REG_DWORD"
Local $sString = "00000000"

Local $sKeyname = "HKEY_CURRENT_USER\Software\FabFilter\Pro-Q\3.0"
Local $sValuename = Bundle"LicenseText"

Local $sKeyname = "HKEY_CURRENT_USER\Software\FabFilter\Pro-Q\3.0"
Local $sValuename = "LicenseText"
Local $sRegSZ = "REG_SZ"
Local $sString = "Product"

; Part 3
Local $sKeyname = "HKEY_CURRENT_USER\Software\FabFilter\Pro-R\2.0"
Local $sValuename = "showInteractiveHelp"
Local $sRegSZ = "REG_DWORD"
Local $sString = "00000000"

Local $sKeyname = "HKEY_CURRENT_USER\Software\FabFilter\Pro-R\2.0"
Local $sValuename = "showWelcomeHint"
Local $sRegSZ = "REG_DWORD"
Local $sString = "00000000"

Local $sKeyname = "HKEY_CURRENT_USER\Software\FabFilter\Pro-R\2.0"
Bundle"LicenseText"=

Local $sKeyname = "HKEY_CURRENT_USER\Software\FabFilter\Pro-R\2.0"
Local $sValuename = "LicenseText"
Local $sRegSZ = "REG_SZ"
Local $sString = "Product"

In the above example, there are three parts, with each part...other that the physical data, being identical to each other.

How would the above be best incorporated into an array?

Edited by mr-es335
typos
  • mr-es335 changed the title to Data-To-Arrays
Posted
Quote

My only "issues" here is that Excel focuses on [Column-then-row, A1], rather than [Row-then-column, 1A].

The Array UDF offers function _ArrayTranspose.
Excel offers the Transpose method (e.g. $oExcel.Transpose).

Should be a good starting point :)

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Posted

Simple Example? Already available in the helpfile. At least for ArrayTranspose 🙂

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Posted

You have two types of common arrays

1 dimensional array

$aArray[Row Index#] example

$aArray[0]
$aArray[1]
etc...

2 dimensional array

$aArray[Row Index No.][Column Index No.] example

$aArray[0][0] ;~ Row 0, Column 0
$aArray[0][1] ;~ Row 0, Column 1
$aArray[1][0] ;~ Row 1, Column 0
$aArray[1][1] ;~ Row 1, Column 1

So in your example you could use 2 dimensional array

;~ Keyname: In Excel this would be A1
$aArray[0][0] = "HKEY_CURRENT_USER\Software\FabFilter\Pro-MB\1.0"
;~ Valuename: In Excel this would be B1
$aArray[0][1] = "showInteractiveHelp"
;~ RegType: In Excel this would be C1
$aArray[0][2] = "REG_DWORD"
;~ RegData: In Excel this would be D1
$aArray[0][3] = "00000000"

;~ Keyname: In Excel this would be A2
$aArray[1][0] = "HKEY_CURRENT_USER\Software\FabFilter\Pro-MB\1.0"
;~ Valuename: In Excel this would be B2
$aArray[1][1] = "showWelcomeHint"
;~ RegType: In Excel this would be C2
$aArray[1][2] = "REG_DWORD"
;~ RegData: In Excel this would be D2
$aArray[1][3] = "00000000"

etc...

You can then use loop to iterate through the array for example:

For $i = 0 To Ubound($aArray) - 1 ;~ Loop from index 0 to last row of the array
    RegWrite($aArray[$i][0], $aArray[$i][1], $aArray[$i][2], $aArray[$i][3])
Next

 

Posted

I had a quick look at the Excel-File you posted.
OMG - Can you please tell me why you store it this way? I have never seen something like this before.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Posted (edited)

water,

I use Excel to assist me with writing scripts that employ "common" data. So the sample.xls produces the following for me [I simply strip out the tabs]:

Spoiler

; -----------------------------------------------
Local $sKeyname1="HKEY_CURRENT_USER\Software\FabFilter\Pro-MB\1.0"
Local $sValuename1="BundleLicenseText"
Local $sRegSZ1="REG_SZ"
Local $sString1=""
RegWrite($sKeyname1, $sValuename1, $sRegSZ1, $sString1)
; -----------------
Local $sKeyname2="HKEY_CURRENT_USER\Software\FabFilter\Pro-MB\1.0"
Local $sValuename2="LicenseText"
Local $sRegSZ2="REG_SZ"
Local $sString2="Product:"
RegWrite($sKeyname2, $sValuename2, $sRegSZ2, $sString2)
; -----------------
Local $sKeyname3="HKEY_CURRENT_USER\Software\FabFilter\Pro-MB\1.0"
Local $sValuename3="showInteractiveHelp"
Local $sRegSZ3="REG_DWORD"
Local $sString3="00000000"
RegWrite($sKeyname3, $sValuename3, $sRegSZ3, $sString3)
; -----------------
Local $sKeyname4="HKEY_CURRENT_USER\Software\FabFilter\Pro-MB\1.0"
Local $sValuename4="showWelcomeHint"
Local $sRegSZ4="REG_DWORD"
Local $sString4="00000000"
RegWrite($sKeyname4, $sValuename4, $sRegSZ4, $sString4)
; -----------------------------------------------
Local $sKeyname1="HKEY_CURRENT_USER\Software\FabFilter\Pro-Q\3.0"
Local $sValuename1="BundleLicenseText"
Local $sRegSZ1="REG_SZ"
Local $sString1=""
RegWrite($sKeyname1, $sValuename1, $sRegSZ1, $sString1)
; -----------------
Local $sKeyname2="HKEY_CURRENT_USER\Software\FabFilter\Pro-Q\3.0"
Local $sValuename2="LicenseText"
Local $sRegSZ2="REG_SZ"
Local $sString2="Product:"
RegWrite($sKeyname2, $sValuename2, $sRegSZ2, $sString2)
; -----------------
Local $sKeyname3="HKEY_CURRENT_USER\Software\FabFilter\Pro-Q\3.0"
Local $sValuename3="showInteractiveHelp"
Local $sRegSZ3="REG_DWORD"
Local $sString3="00000000"
RegWrite($sKeyname3, $sValuename3, $sRegSZ3, $sString3)
; -----------------
Local $sKeyname4="HKEY_CURRENT_USER\Software\FabFilter\Pro-Q\3.0"
Local $sValuename4="showWelcomeHint"
Local $sRegSZ4="REG_DWORD"
Local $sString4="00000000"
RegWrite($sKeyname4, $sValuename4, $sRegSZ4, $sString4)
; -----------------------------------------------
Local $sKeyname1="HKEY_CURRENT_USER\Software\FabFilter\Pro-R\2.0"
Local $sValuename1="BundleLicenseText"
Local $sRegSZ1="REG_SZ"
Local $sString1=""
RegWrite($sKeyname1, $sValuename1, $sRegSZ1, $sString1)
; -----------------
Local $sKeyname2="HKEY_CURRENT_USER\Software\FabFilter\Pro-R\2.0"
Local $sValuename2="LicenseText"
Local $sRegSZ2="REG_SZ"
Local $sString2="Product:"
RegWrite($sKeyname2, $sValuename2, $sRegSZ2, $sString2)
; -----------------
Local $sKeyname3="HKEY_CURRENT_USER\Software\FabFilter\Pro-R\2.0"
Local $sValuename3="showInteractiveHelp"
Local $sRegSZ3="REG_DWORD"
Local $sString3="00000000"
RegWrite($sKeyname3, $sValuename3, $sRegSZ3, $sString3)
; -----------------
Local $sKeyname4="HKEY_CURRENT_USER\Software\FabFilter\Pro-R\2.0"
Local $sValuename4="showWelcomeHint"
Local $sRegSZ4="REG_DWORD"
Local $sString4="00000000"
RegWrite($sKeyname4, $sValuename4, $sRegSZ4, $sString4)
; -----------------------------------------------

 

Edited by mr-es335
Posted

Subz,

What is wrong with this? ...something is...

#include <Array.au3>

Local $aArray[0][0]

;So in your example you could use 2 dimensional array
;~ Keyname: In Excel this would be A1
$aArray[0][0] = "HKEY_CURRENT_USER\Software\FabFilter\Pro-MB\1.0"
;~ Valuename: In Excel this would be B1
$aArray[0][1] = "showInteractiveHelp"
;~ RegType: In Excel this would be C1
$aArray[0][2] = "REG_DWORD"
;~ RegData: In Excel this would be D1
$aArray[0][3] = "00000000"

For $i = 0 To UBound($aArray) - 1 ;~ Loop from index 0 to last row of the array
    RegWrite($aArray[$i][0], $aArray[$i][1], $aArray[$i][2], $aArray[$i][3])
Next

 

Posted

Hello,

Thanks to sleepydvdr, the commented line works, whilst the non-commented lines does not! Why?

#include <Array.au3>

Local $avArray[4][4]

$avArray[0][0] = "HKEY_CURRENT_USER\Software\FabFilter\Pro-MB\1.0"
$avArray[1][0] = "BundleLicenseText"
$avArray[2][0] = "REG_SZ"
$avArray[3][0] = "Me"

_ArrayDisplay($avArray, "")

For $i = 0 To 3
    ;RegWrite($avArray[0][0], $avArray[1][0], $avArray[2][0], $avArray[3][0])
    RegWrite($avArray[$i][0], $avArray[$i][0], $avArray[$i][0], $avArray[$i][0])
Next

 

Posted (edited)

As a coder you want to become, you should know that "does not work" isn't an acceptable description of a bug :)

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Posted

Even without further troubleshooting information from you, the cause of the problem is fairly obvious.

The solution is: Learn the basics of AutoIt! That includes arrays!

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Posted

water,

No offense is meant to be indte4nded...so if I do come across in this manner...please forgive me...

"the cause of the problem is fairly obvious"...to you apparently...but NOT to me!!

"The solution is: Learn the basics of AutoIt! That includes arrays!" ...I thought that I was! I gather NOT!

 

Posted

Talking about arrays: Your code tells me that you do not understand how arrays work. Subz tried to tell you, but ...
You created an array with 4 rows and 4 columns, but only fill the first column of all rows.
Then you loop through all rows. Your code passes the same cell 4 times to RegWrite. That returns an error.

Add debugging code to your script to make sure all function calls work properly. I already posted code in one of your threads that exaclty tells you what went wrong.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Posted (edited)

Okay,

So how is this?

Objective: Test for a single column with four rows!

; To test each in turn, comment-out each #cs and #ce
#include <Array.au3>

;Local $aArray[A][B]
;[A] = Rows
;[B] = Columns

#cs
; So, for a 1 row, 1 col array, employ: Local $aArray[1][1]
Local $aArray[1][1]
$aArray[0][0] = "Col1 Row1"
; To access that data, employ: ConsoleWrite($aArray[0][0] & @CRLF)
ConsoleWrite($aArray[0][0] & @CRLF)
#ce

#cs
; For a 2 row, 1 col array, employ: Local $aArray[2][1]
Local $aArray[2][1]
$aArray[0][0] = "Col1 Row1"
$aArray[1][0] = "Col1 Row2"
; To access that data, employ: ConsoleWrite($aArray[0][0] & $aArray[1][0] & @CRLF)
ConsoleWrite($aArray[0][0] & @CRLF & $aArray[1][0] & @CRLF)
#ce

#cs
; For a 3 row, 1 col array, employ: Local $aArray[3][1]
Local $aArray[3][1]
$aArray[0][0] = "Col1 Row1"
$aArray[1][0] = "Col1 Row2"
$aArray[2][0] = "Col1 Row3"
; To access that data, employ: ConsoleWrite($aArray[0][0] & @CRLF & $aArray[1][0] & @CRLF& $aArray[2][0] & @CRLF)
ConsoleWrite($aArray[0][0] & @CRLF & $aArray[1][0] & @CRLF & $aArray[2][0] & @CRLF)
#ce

#cs
; And finally, for a 4 row, 1 col array, employ: Local $aArray[4][1]
Local $aArray[4][1]
$aArray[0][0] = "Col1 Row1"
$aArray[1][0] = "Col1 Row2"
$aArray[2][0] = "Col1 Row3"
$aArray[3][0] = "Col1 Row4"
; To access that data, employ: ConsoleWrite($aArray[0][0] & @CRLF & $aArray[1][0] & @CRLF & $aArray[2][0] & @CRLF & $aArray[3][0] & @CRLF)
ConsoleWrite($aArray[0][0] & @CRLF & $aArray[1][0] & @CRLF & $aArray[2][0] & @CRLF & $aArray[3][0] & @CRLF)
#ce

;_ArrayDisplay($aArray, "Original Array")

PS: I do believe that it is imperative to understand that - in my understanding, "logic" is the key to a good programmer! I tend to consider myself a being "methodical" - not logical! Therefore, unless I am able to see clearly - a method, no amount of logic will make any sense to me....no matter how si9mple such logic is being presented.

Objective 2: To test for two columns with four rows - with a focus on Column 1:

; To test each in turn, comment-out each #cs and #ce
#include <Array.au3>

;Local $aArray[A][B]
;[A] = Row
;[B] = Column

#cs
; So, for a 1 row, 2 col array, employ: Local $aArray[1][2]
Local $aArray[1][2]
$aArray[0][0] = ""
$aArray[0][1] = "Col2 Row1"
#ce

#cs
; For a 2 row, 2 col array, employ: Local $aArray[2][2]
Local $aArray[2][2]
$aArray[0][0] = ""
$aArray[0][1] = "Col2 Row1"
$aArray[1][0] = ""
$aArray[1][1] = "Col2 Row2"
#ce

#cs
; For a 3 row, 1 col array, employ: Local $aArray[3][3]
Local $aArray[3][2]
$aArray[0][0] = ""
$aArray[0][1] = "Col2 Row1"
$aArray[1][0] = ""
$aArray[1][1] = "Col2 Row2"
$aArray[2][0] = ""
$aArray[2][1] = "Col2 Row3"
#ce

#cs
; And finally, for a 4 row, 1 col array, employ: Local $aArray[4][1]
Local $aArray[4][2]
$aArray[0][0] = ""
$aArray[0][1] = "Col2 Row1"
$aArray[1][0] = ""
$aArray[1][1] = "Col2 Row2"
$aArray[2][0] = ""
$aArray[2][1] = "Col2 Row3"
$aArray[3][0] = ""
$aArray[3][1] = "Col2 Row4"
#ce

_ArrayDisplay($aArray, "")

 

Edited by mr-es335
Posted

Finally!

#include <Array.au3>

;$aArray[A][B]
;[A] = Row
;[B] = Column

Local $aArray[4][4]
$aArray[0][0] = "Col1 Row1"
$aArray[1][0] = "Col1 Row2"
$aArray[2][0] = "Col1 Row3"
$aArray[3][0] = "Col1 Row4"

$aArray[0][1] = "Col2 Row1"
$aArray[1][1] = "Col2 Row2"
$aArray[2][1] = "Col2 Row3"
$aArray[3][1] = "Col2 Row4"

$aArray[0][2] = "Col3 Row1"
$aArray[1][2] = "Col3 Row2"
$aArray[2][2] = "Col3 Row3"
$aArray[3][2] = "Col3 Row4"

$aArray[0][3] = "Col4 Row1"
$aArray[1][3] = "Col4 Row2"
$aArray[2][3] = "Col4 Row3"
$aArray[3][3] = "Col4 Row4"

_ArrayDisplay($aArray, "")

I finally SEE METHOD IN THIS!

Posted (edited)

ioa747,

#include <Array.au3>

Local $sNumofRows = 0
Local $sNumofCols = 0

Local $Array[$sNumofRows][$sNumofCols]

For $row = 0 To UBound($Array) - 1
    For $column = 0 To UBound($Array,$sNumofRows) - 1
        $Array[$row][$column] = $row & ":" & $column
    Next
Next

_ArrayDisplay($Array, "")

Observations
So, apparently, you can have "0 rows and 1 column"...but NOT, "1 row and 0 columns"!!

Does generates an error...
Local $sNumofRows = 1
Local $sNumofCols = 0

Does not generates an error...
Local $sNumofRows = 0
Local $sNumofCols = 1

Edited by mr-es335

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
  • Recently Browsing   2 members

×
×
  • Create New...