Jump to content

[Solved] - Listing multiple arrays into multiple columns using seperators


Mikeman27294
 Share

Recommended Posts

Hello everyone.

I am making a small project for one of my classes at school, where the user inputs numbers, and the are sorted numerically (I didnt use array sort as this would defeat the whole purpose of the program). This works perfectly, however, I am also trying to list them as a desk check. Basically, this shows how the variables and outputs change throughout the program.

I have created a GUI for this with a List View, and I am adding my items like this:

GUICtrlCreateListViewItem('"'&$Array[$InnerCount]&'|'&$Array[$InnerCount+1]&'|'&$Temp&'"',$ListView)

I have also have tried

GUICtrlCreateListViewItem($Array[$InnerCount]&"|"&$Array[$InnerCount+1]&"|"&$Temp,$ListView)

and

GUICtrlCreateListViewItem('$Array[$InnerCount]&|&$Array[$InnerCount+1]&|&$Temp&,$ListView)

To make this easy to unserstand for those of you who dont understand me, let's assume that $array has 3 elements - 1, 2 and 3.

The problem is that the script will always take the literal value of the | instead of using it as a seperator, and so in the first cell, I have the values with the | inbetween them, not seperating them. So basically, the first column in the list view shows like this - "1|2|3", and the other columns are empty.

Is there something that I am not doing correctly?

Thanks.

Edited by Mikeman27294
Link to comment
Share on other sites

GUICtrlCreateListViewItem('"'&$Array[$InnerCount]&'|'&$Array[$InnerCount+1]&'|'&$Temp&'"',$ListView)
Hue. Why are you adding a leading and trailing quote(") mark to your data here. That's only needed for when there is some possible ambiguitie on what is and is not a delimiter/separator in a full string data set/line. Like with file(cmd) related commands that need to know when a space is a delimiter or part of the filespec.

GUICtrlCreateListViewItem($Array[$InnerCount]&"|"&$Array[$InnerCount+1]&"|"&$Temp,$ListView)
This one should work. ...

Check if your still have (|) set as active delimiter. (Its a Global setting, and you probably changed is somewhere earlier in your code.)

Use the AutoItSetOption() OR(short named version) Opt('GUIDataSeparatorChar', [new character, optional]) command for that.

$cCurrent = Opt('GUIDataSeparatorChar') ;; check current used one.
$cOld = Opt('GUIDataSeparatorChar', $cNew) ;; change, and backup old one.
Opt('GUIDataSeparatorChar', $cOld) ;; restore old one.

GUICtrlCreateListViewItem('$Array[$InnerCount]&|&$Array[$InnerCount+1]&|&$Temp&,$ListView)
Last, but not least. Keep track of your quote counts. As this code is missing one. Invalidating the command completely. -> should have triggered a syntax error. (for starters, as I spotted a second (typo) error in it to.) Edited by iEvKI3gv9Wrkd41u

"Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions."
"The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014)

"Believing what you know ain't so" ...

Knock Knock ...
 

Link to comment
Share on other sites

Hum. ... Only reason I can think of for there not being any data displayed is that your not feeding it any data.

Your sure your array cells contain any data to be displayed.

;; optional commands to help with checking your code for syntax errors. (assuming your using Scite4AutoIt3)
#AutoIt3Wrapper_Run_Au3Check=y
#AutoIt3Wrapper_Au3Check_Stop_OnWarning=y
#AutoIt3Wrapper_AU3Check_Parameters=-q -d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

_Example() ;; see GUICtrlCreateListViewItem code example in manual for more ...
_MsgWait()
Exit

;; === functions === ;;
Func _Example()
    Local $listview

    GUICreate("listview items", 220, 250, 100, 200, -1, $WS_EX_ACCEPTFILES)

    $listview = GUICtrlCreateListView("col1  |col2|col3  ", 10, 10, 200, 150)
    $item1 = GUICtrlCreateListViewItem("item-11|item-12|col-13", $listview)
;~  $item2 = GUICtrlCreateListViewItem("item-21|item-22|col-23", $listview)
    $item2 = GUICtrlCreateListViewItem("||", $listview) ;; no data in ... no data displayed.
    $item3 = GUICtrlCreateListViewItem("item-33|item-33|col-33", $listview)

    GUISetState()
EndFunc
Func _MsgWait()
    Local $iMsg
    Do
        $iMsg = GUIGetMsg()
    Until $iMsg = $GUI_EVENT_CLOSE
EndFunc

"Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions."
"The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014)

"Believing what you know ain't so" ...

Knock Knock ...
 

Link to comment
Share on other sites

...

I have also have tried

GUICtrlCreateListViewItem($Array[$InnerCount]&"|"&$Array[$InnerCount+1]&"|"&$Temp,$ListView)

...

This line does work when proper values are in the variables $Array, $InnerCount, $Temp, and $ListView.

My slant on "Listing multiple arrays into multiple columns" is :-

#include <Array.au3>

Local $Array1[5] = [1, 2, 3, 4, 5]
Local $Array2[6] = [11, 12, 13, 14, 15, 16]
Local $Array3[4] = [21, 22, 23, 24]

Local $Array[3] = [$Array1, $Array2, $Array3]

_ArraysDisplay($Array)

; Description - Displays any number of one dimensional arrays - one array per column.
; See _ArrayDisplay() for parameters
Func _ArraysDisplay(Const ByRef $Arr, $sTitle = "Array: ListView Display", $iItemLimit = -1, $iTranspose = 1, _
        $sSeparator = "", $sReplace = "|", $sHeader = "")

    Local $temp, $num = UBound($Arr), $max = UBound($Arr[0])

    For $i = 0 To $num - 1
        If $max < UBound($Arr[$i]) Then $max = UBound($Arr[$i])
    Next
    Dim $Array2D[$num][$max]

    For $i = 0 To $num - 1
        $temp = $Arr[$i]
        For $j = 0 To UBound($temp) - 1
            $Array2D[$i][$j] = $temp[$j]
        Next
    Next
    _ArrayDisplay($Array2D, $sTitle, $iItemLimit, $iTranspose, $sSeparator, $sReplace, $sHeader)
    Return
EndFunc   ;==>_ArraysDisplay
Link to comment
Share on other sites

Ok thanks.

Opt("GUIDataSeparatorChar", "|")
Local $ListView = _GUICtrlListView_Create($DeskCheckGUI, "", 0, 0, 500, 500)
_GUICtrlListView_SetColumnWidth($ListView, 0, 100)
_GUICtrlListView_SetExtendedListViewStyle($ListView, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES))
_GUICtrlListView_InsertColumn($ListView, 0, "Apples[Current]", 100)
_GUICtrlListView_InsertColumn($ListView, 0, "Apples[Current+1]", 100)
_GUICtrlListView_InsertColumn($ListView, 0, "Temporary", 100)
_GUICtrlListView_AddItem($ListView,$Array[$InnerCount]&"|"&$Array[$InnerCount+1]&"|"&$Temp)

It is showing the values again, but the problem is that it is inserting the | character again, instead of using it as a seperator.

Link to comment
Share on other sites

_GUICtrlListView_AddItem() only intended to add single items.

so its not using the 'GUIDataSeparatorChar' option to split up your input into seperate parts.

See _GUICtrlListView_AddItem() help example-code for more info.

Edited by iEvKI3gv9Wrkd41u

"Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions."
"The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014)

"Believing what you know ain't so" ...

Knock Knock ...
 

Link to comment
Share on other sites

Local $ListView = _GUICtrlListView_Create($DeskCheckGUI, "", 0, 0, 500, 500)

_GUICtrlListView_SetColumnWidth($ListView, 0, 100)
_GUICtrlListView_SetExtendedListViewStyle($ListView, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES))
_GUICtrlListView_InsertColumn($ListView, 0, "Apples[Current]", 100)
_GUICtrlListView_InsertColumn($ListView, 0, "Apples[Current+1]", 100)
_GUICtrlListView_InsertColumn($ListView, 0, "Temporary", 100)
_GUICtrlListView_AddItem($ListView, $Array[$InnerCount], 0)
_GUICtrlListView_AddItem($ListView, $Array[$InnerCount+1], 1)
_GUICtrlListView_AddItem($ListView, $Temp, 2)

Edited by Zedna
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...