Sign in to follow this  
Followers 0
DickG

Column names/widths in multi-dimensional array

8 posts in this topic

Is it possible to specify column names in a multi-dimensional array?

For example, I am displaying an array that has 7 columns, each of which is shown as "Col(0)", "Col(1)", etc. at the top. Is it possible to change it to use column names like "Date," "Time", etc.?

Also, is it possible to set a column width? One of the columns is too narrow for the text, and I'd like to set the width to the widest cell.

Any of this possible?

Share this post


Link to post
Share on other sites



Can we see your code up to this point?


Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Is it possible to specify column names in a multi-dimensional array?

For example, I am displaying an array that has 7 columns, each of which is shown as "Col(0)", "Col(1)", etc. at the top. Is it possible to change it to use column names like "Date," "Time", etc.?

Also, is it possible to set a column width? One of the columns is too narrow for the text, and I'd like to set the width to the widest cell.

Any of this possible?

An array is a type of variable stored in AutoIt's process memory. AutoIt arrays can be multidimensional, but "column width" and "column name" have no meaning in memory storage. All array indexes in AutoIt are integers, for example $avArray[2][3][4] for a 3D array.

A ListView control has rows and columns, and the columns can have set width and names (header text). See the help file under GUICtrlCreateListView(), GUICtrlCreateListViewItem(), and the GuiListView.au3 UDF commands like _GuiCtrlListView_SetColumn().

;)

Edited by PsaltyDS

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

Yes, I know an array is just a list of variables, but _ArrayDisplay() shows generic columns "names" and I was hoping there was a way of giving those columns names. So I was referring to the display of the array, not the array variables themselves.

I started out using a ListView, but realized that using an array along with _ArrayDisplay() was so much easier. But now I realize the limitation of this approach.

Maybe I'll look into combining both: an array, then feeding that to a ListView where I can name the columns for display.

Thanks much for the advise, PSaltyDS.

An array is a type of variable stored in AutoIt's process memory. AutoIt arrays can be multidimensional, but "column width" and "column name" have no meaning in memory storage. All array indexes in AutoIt are integers, for example $avArray[2][3][4] for a 3D array.

A ListView control has rows and columns, and the columns can have set width and names (header text). See the help file under GUICtrlCreateListView(), GUICtrlCreateListViewItem(), and the GuiListView.au3 UDF commands like _GuiCtrlListView_SetColumn().

;)

Share this post


Link to post
Share on other sites

Yes, I know an array is just a list of variables, but _ArrayDisplay() shows generic columns "names" and I was hoping there was a way of giving those columns names. So I was referring to the display of the array, not the array variables themselves.

I started out using a ListView, but realized that using an array along with _ArrayDisplay() was so much easier. But now I realize the limitation of this approach.

Maybe I'll look into combining both: an array, then feeding that to a ListView where I can name the columns for display.

Thanks much for the advise, PSaltyDS.

I see now what you meant.

Note that the code for _ArrayDisplay() is in the Array.au3 UDF, which can be opened up in SciTE, studied, and modified like any other script. That would give you a place to start from, anyway.

;)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

Ah, excellent! I was not aware of that!

I was able to add column names by customizing Array.au3!

I saved a copy of the original Array.au3 as Array_Custom.au3, then found where it adds "Col ($i)" to the header. I then added my own code to cycle through and give each column a name. Now _ArrayDisplay() shows my column names!

I changed the original code in Array.au3 (starting at line 208) from this:

;; make LV header==================================================================
For $i = 1 To UBound($ar_2DArray, 2)
    $sTempHeader &= $GUIDataSeparatorChar & 'Col ' & $i - 1
Next
StringReplace($sTempHeader, $GUIDataSeparatorChar, "<")
If @extended > 252 Then
    $i_Pos = StringInStr($sTempHeader, $GUIDataSeparatorChar, 0, 252)
    $sTempHeader = StringLeft($sTempHeader, $i_Pos - 1)
EndIf
$s_NotDoneLine = StringReplace($sTempHeader, "Col", "ND")oÝ÷ Ù:-+ºÚ"µÍÎÈXZÙHXYOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOBÜ    ÌÍÚHHHÈPÝ[
    ÌÍØÌ^KBTÙ[XÝBPØÙH   ÌÍÚHHBBBIÌÍÐÛÛ[YHH  ][ÝÑ]I][ÝÂBPØÙH   ÌÍÚHHBBIÌÍÐÛÛ[YHH   ][ÝÕ[YI][ÝÂBPØÙH  ÌÍÚHHÂBBIÌÍÐÛÛ[YHH ][ÝÔÜYY  ][ÝÂBPØÙH   ÌÍÚHH
BBIÌÍÐÛÛ[YHH   ][ÝÒT ][ÝÂBPØÙH   ÌÍÚHH
BBBIÌÍÐÛÛ[YHH  ][ÝÓ][ÞI][ÝÂBPØÙH    ÌÍÚHH
BBIÌÍÐÛÛ[YHH   ][ÝÓÜÝXÚÙ]É][ÝÂBPØÙH ÌÍÚHH
ÂBBIÌÍÐÛÛ[YHH ][ÝÓÝI][ÝÂBPØÙH[ÙBBBIÌÍÐÛÛ[YHH ][ÝÐÛÛ  ][ÝÂQ[Ù[XÝIÌÍÜÕ[XY  [ÏH    ÌÍÑÕRQ]TÙ]ÜÚ [È ÌÍÐÛÛ[YB^

But then I discovered that if I specify "#include <Array_Custom1.au3> instead of "#include <Array.au3>", my script throws an error that says the array code is already there and points to Array.au3. So it looks like some other #include file is calling Array.au3 anyway.

I am including these files:

#include <Constants.au3>

#include <GuiConstants.au3>

#include <GuiConstantsEx.au3>

#include <GuiListView.au3>

#include <GuiEdit.au3>

#include <IE.au3>

#include <INet.au3>

#include <Date.au3>

#include <File.au3>

#include <Array.au3>

Is there a better way to modify Array.au3 without creating errors? For now, I made a copy of Array.au3 as MyArray.au3, modified MyArray.au3 to set my column names, then I rename Array.au3 to Array.txt and rename MyArray.au3 to Array.au3 before I run my script. I reverse that when I'm done. But there must be better way.

Thanks much for turning me on to this!!!!!!!

I see now what you meant.

Note that the code for _ArrayDisplay() is in the Array.au3 UDF, which can be opened up in SciTE, studied, and modified like any other script. That would give you a place to start from, anyway.

;)

Share this post


Link to post
Share on other sites

I think it would have bee easier to leave Array.au3 intact and just put the _ArrayDisplayCustom() function in Array_Custom.au3. Then you can use either the original _ArrayDisplay() or your own _ArrayDisplayCustom() as required.

;)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

OK, I tried this, and it works great!

Man, thanks for pointing me in the right direction. I was not aware of how to do this.

So, for the benefit of those who might read this later, wondering how to do something similar, here is what I did:

o Open Array.au3 and save as Array_Custom.au3.

o Open Array_Custom.au3 for editing.

o Delete all functions except _ArrayDisplay().

o Rename _ArrayDisplay() to _ArrayDisplayCustom().

o Customize the function with your own code.

o Save and close

In the script that will use the custom function:

o Add #Include <Array_Custom.au3>

o OK to keep #Include <Array.au3> as well.

o Use _ArrayDisplayCustom() instead of _ArrayDisplay where you want to use the custom function.

To add column names for a specific script, see earlier post for before/after code.

Thanks very much for your help, PSaltyDS. There is so much to learn, and this really helped me.

Dick

I think it would have bee easier to leave Array.au3 intact and just put the _ArrayDisplayCustom() function in Array_Custom.au3. Then you can use either the original _ArrayDisplay() or your own _ArrayDisplayCustom() as required.

;)

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