Jump to content

Column Format


Recommended Posts

I have the following:

ListView with 5 columns ( 0 to 4)

Column 3 is actually empty (with 0 column width in Listview), so the viewer sees 4 columns of data.

 I am looking to print out the data by using the attached snippet of code. But I am stumped as to how to do the following -

Format the printed columns so column 0 is, say 30 characters wide, and columns 1,2 and 4 (remember 3 is not seen) are 10 wide.

I can make all the columns the same width(as below), but that is not what i want to achieve. How would it be done? As it stands I end up with column "run over" resulting in some data pushing the next column of data over to the right.  I was hoping to not trim the data in column 0 (the longest) as a solution to the "run over" (or whatever it is professionally called).

 

Thank you in advance for any guidance or even a better solution. I am green at this.

Hobbyist

For $x = 0 To _GUICtrlListView_GetItemCount($List5) - 1
                    For $j = 0 To 4
                    $it = _GUICtrlListView_GetItemText($List5, $x, $j)
                    $itt &= StringFormat('%-30s', $it)
                    Next
                    $itt &= @LF
                    Next

                    FileWrite(@TempDir & "\" & $ABC & "  " & "Log.txt", $itt)

                    $print = _FilePrint(@TempDir & "\" & $ABC & "  " & "Log.txt")
                    If FileExists(@TempDir & "\" & $ABC & "  " & "Log.txt") Then FileDelete(@TempDir &  "\" & $ABC & "  " & " Log.txt")

 

Link to comment
Share on other sites

I don't got your point. maybe if you illustrate better.

Create an dummy example for us. and put what ouput you expect.

 

Saludos

Link to comment
Share on other sites

  • Moderators

Hobbyist,

I did something very similar in _ArrayDisplay, so not too difficult to recreate it in this simpler form:

#include <GUIConstantsEx.au3>
#include <GuiListView.au3>

$hGUI = GUICreate("Test", 500, 500)

$cLV = GUICtrlCreateListView("", 10, 10, 400, 200)
_GUICtrlListView_AddColumn($cLV, "Column 0", 90)
_GUICtrlListView_AddColumn($cLV, "Column 1", 90)
_GUICtrlListView_AddColumn($cLV, "Column 2", 90)
_GUICtrlListView_AddColumn($cLV, "Column 3", 0)
_GUICtrlListView_AddColumn($cLV, "Column 4", 90)

For $i = 0 To 9
    GUICtrlCreateListViewItem("Item " & $i & "-0|Item " & $i & "-1|Item " & $i & "-2||Item " & $i & "-4", $cLV)
Next

$cFormat = GUICtrlCreateButton("Format", 10, 450, 80, 30)


GUISetState()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $cFormat

            ; Final result
            $sFormatted = ""
            ; Loop through lines
            For $i = 0 To _GUICtrlListView_GetItemCount($cLv) - 1
                ; Get line content
                $aLine = _GUICtrlListView_GetItemTextArray($cLV, $i)
                ; Loop through columns
                For $j = 1 To $aLine[0]
                    ; For each column
                    $sText = $aLine[$j]
                    ; set default width
                    $iWidth = 10
                    ; Adjust according to column number - remember to use 1-based element, not 0-based column
                    Switch $j
                        Case 1 ; Column 0 - increase width
                            $iWidth = 30
                        Case 4 ; Column 3 - ignore
                            ContinueLoop

                    EndSwitch

                    ; Check how many spaces to add
                    $iAdd = $iWidth - StringLen($sText)
                    For $k = 1 To $iAdd

                        $sText &= " "
                    Next
                    ; Add result to final result
                    $sFormatted &= $sText

                Next
                ; Create new line
                $sFormatted &= @CRLF
            Next
            ; Display result
            ConsoleWrite($sFormatted & @CRLF)
    EndSwitch



WEnd

Please ask if you have any questions.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

Hobbyist,

Glad I could help.

That was just a "proof of concept" script - remember that if there is a chance that the item will be wider than the allowed width, you might have to trim it rather then add spaces, so you really need a check on the item length before doing anything at all.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

m23

 

I did finally think of a question, after tinkering with this for a bit.

Here is what I tried. Using the width parameters in the script, I entered Item 1 (column 1) with 8 character and Item 2 (column 1) with 22 characters.  I also replaced blanks with an asterik to help see what was going on.  Expected to see 22 *'s added to the first one and 8 *'s added to the second one.  I did.  I also saw that data in column 2 for the second entry was moved further to the right.  I'm not understanding this, since the width is 30 and the data length is under that.  If the length was over 30 I would see it as being such.  I understand your comment on the truncating in that case.

Should the data in Column 2 be lined up the same if data in Column 1 is at/under the 30 width parameter?  Or what am I missing.

 

thanks 

Hobbyist

Link to comment
Share on other sites

  • Moderators

Hobbyist,

I replaced the data input in the code I posted above with this:

GUICtrlCreateListViewItem("12345678|Item 0-1|Item 0-2||Item 0-4", $cLV)                ; 8 chars in first line
GUICtrlCreateListViewItem("1234567890123456789012|Item 0-1|Item 0-2||Item 0-4", $cLV)  ; 22 in second
For $i = 2 To 9
    GUICtrlCreateListViewItem("Item " & $i & "-0|Item " & $i & "-1|Item " & $i & "-2||Item " & $i & "-4", $cLV)
Next

which matches what you said you did - and I got the expected result:

12345678**********************Item 0-1**Item 0-2**Item 0-4**
1234567890123456789012********Item 0-1**Item 0-2**Item 0-4**
Item 2-0**********************Item 2-1**Item 2-2**Item 2-4**
Item 3-0**********************Item 3-1**Item 3-2**Item 3-4**
Item 4-0**********************Item 4-1**Item 4-2**Item 4-4**
Item 5-0**********************Item 5-1**Item 5-2**Item 5-4**
Item 6-0**********************Item 6-1**Item 6-2**Item 6-4**
Item 7-0**********************Item 7-1**Item 7-2**Item 7-4**
Item 8-0**********************Item 8-1**Item 8-2**Item 8-4**
Item 9-0**********************Item 9-1**Item 9-2**Item 9-4**

Perhaps if you posted your code I might be able to see why you do not get the same result.

M23

 

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Hey M23

Here is the code. As you can see I took yours and just dropped in some file reading for simulation.  I commented  out your listview populating.  And put an * for spacing.  Also the Test file is attached (CSV) with some random entries. I do not understand what I am doing wrong.  Thanks again.

Hobbyist

#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <MsgBoxConstants.au3>
$hGUI = GUICreate("Test", 500, 500)

 $cLV = GUICtrlCreateListView("", 10, 10, 400, 200)
_GUICtrlListView_AddColumn($cLV, "Column 0", 90)
_GUICtrlListView_AddColumn($cLV, "Column 1", 90)
_GUICtrlListView_AddColumn($cLV, "Column 2", 90)
_GUICtrlListView_AddColumn($cLV, "Column 3", 0)
_GUICtrlListView_AddColumn($cLV, "Column 4", 90)

$logfile2 = FileOpen("c:\Dash Board\01 Monthly Log\Test Data.csv", 0)


    $csv = FileRead($logfile2)
    $csv = StringStripWS($csv, 7)
    $rows = StringSplit($csv, @CRLF)
    Dim $aLog[$rows[0] + 1][5]

    $aLog[1][0] = $rows[0]
    For $i = 1 To $rows[0]

        $temp = StringSplit($rows[$i], ",", 2)
        For $j = 0 To UBound($temp) - 1

            $aLog[$i][$j] = $temp[$j]
        Next
    Next
    FileClose($logfile2)


    For $i = 0 To UBound($aLog) - 1
        $aLog[$i][1] = Number($aLog[$i][1])
    Next

_arraydisplay($alog)

_GUICtrlListView_AddArray($cLV, $alog)



;~ For $i = 0 To 9
;~     GUICtrlCreateListViewItem("Item " & $i & "-0|Item " & $i & "-1|Item " & $i & "-2||Item " & $i & "-4", $cLV)
;~ Next

$cFormat = GUICtrlCreateButton("Format", 10, 450, 80, 30)


GUISetState()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $cFormat

            ; Final result
            $sFormatted = ""
            ; Loop through lines
            For $i = 0 To _GUICtrlListView_GetItemCount($cLv) - 1
                ; Get line content
                $aLine = _GUICtrlListView_GetItemTextArray($cLV, $i)
                ; Loop through columns
                For $j = 1 To $aLine[0]
                    ; For each column
                     $sText = $aLine[$j]
                    ; set default width
                    $iWidth = 10
                    ; Adjust according to column number - remember to use 1-based element, not 0-based column
                    Switch $j
                        Case 1 ; Column 0 - increase width
                            $iWidth = 30
                        Case 4 ; Column 3 - ignore
                            ContinueLoop

                    EndSwitch

                    ; Check how many spaces to add
                    $iAdd = $iWidth - StringLen($sText)
                    For $k = 1 To $iAdd

                        $sText &= "*"
                    Next
                    ; Add result to final result

                    $sFormatted &= $sText

                Next
                ; Create new line
                $sFormatted &= @CRLF
            Next
            ; Display result
            ConsoleWrite($sFormatted & @CRLF)
    EndSwitch


WEnd

 

Test Data.csv

Link to comment
Share on other sites

  • Moderators

Hobbyist,

Works fine for me - as long as I deal with column 2 which has some longer elements:

#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <File.au3>

; Why did I bother writing a new version of this function to read csv files? <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
Local $aLog, $sFile = @ScriptDir & "\test data.csv"
_FileReadToArray($sFile, $aLog, $FRTA_NOCOUNT, ",")
_ArrayDisplay($alog)

$hGUI = GUICreate("Test", 500, 500)

 $cLV = GUICtrlCreateListView("", 10, 10, 400, 200)
_GUICtrlListView_AddColumn($cLV, "Column 0", 90)
_GUICtrlListView_AddColumn($cLV, "Column 1", 90)
_GUICtrlListView_AddColumn($cLV, "Column 2", 90)
_GUICtrlListView_AddColumn($cLV, "Column 3", 0)
_GUICtrlListView_AddColumn($cLV, "Column 4", 90)

_GUICtrlListView_AddArray($cLV, $alog)

$cFormat = GUICtrlCreateButton("Format", 10, 450, 80, 30)

GUISetState()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $cFormat



            ; Final result
            $sFormatted = ""
            ; Loop through lines
            For $i = 0 To _GUICtrlListView_GetItemCount($cLv) - 1
                ; Get line content
                $aLine = _GUICtrlListView_GetItemTextArray($cLV, $i)
                ; Loop through columns
                For $j = 1 To $aLine[0]
                    ; For each column
                     $sText = $aLine[$j]
                    ; set default width
                    $iWidth = 10
                    ; Adjust according to column number - remember to use 1-based element, not 0-based column
                    Switch $j
                        Case 1 ; Column 0 - increase width
                            $iWidth = 30
                        Case 3 ; Column 2 - increase width <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
                            $iWidth = 15
                        Case 4 ; Column 3 - ignore
                            ContinueLoop

                    EndSwitch



                    ; Check how many spaces to add
                    $iAdd = $iWidth - StringLen($sText)
                    For $k = 1 To $iAdd



                        $sText &= "_"
                    Next
                    ; Add result to final result

                    $sFormatted &= $sText



                Next
                ; Create new line
                $sFormatted &= @CRLF
            Next
            ; Display result
            ConsoleWrite($sFormatted & @CRLF)
    EndSwitch



WEnd

And I get:

"OMOZON.COM"__________________155_______"MISC"_________"OmericOn Express"
"OROGOS"______________________14.55_____"GOS"__________"OmericOn Express"
"OROGOS"______________________16.6______"GOS"____________________
"DIERbornS"___________________5.64______"FOOD"_________"OmericOn Express"
"EQUIP RENTOL"________________10.8______"LONDSCOPE"____"OmericOn Express"
"MOGPIES"_____________________35.81_____"TIM Out"______"CiticOrd"
"NEW BOLONCE"_________________268.22____"CLOTHES"______"OmericOn Express"
"PONERO BREOD"________________21.21_____"TIM OUT"______"OmericOn Express"
"SOPPINGTON GORDENS"__________65.53_____"LONDSCOPE"____"CiticOrd"
"SOPPINGTON GORDENS"__________114.69____"LONDSCOPE"____"CiticOrd"
"SPEEDY GOS"__________________20.95_____"MISC"_________"OmericOn Express"
"SPORTS"______________________20.44_____"TIM OUT"______"OmericOn Express"
"THE HOME DEPOT"______________11.44_____"MISC"_________"OmericOn Express"
"THE HOME DEPOT"______________12.19_____"MISC"_________"OmericOn Express"
"THE HOME DEPOT"______________14.44_____"MISC"_________"OmericOn Express"
"THE HOME DEPOT"______________17.23_____"Misc"_________"OmericOn Express"
"THE HOME DEPOT"______________19.97_____"MISC"_________"OmericOn Express"
"WOLGREENS"___________________14.55_____"MISC"_________"OmericOn Express"
"WOL-MORT"____________________17.94_____"MISC"_________"OmericOn Express"
"WOL-MORT"____________________21.27_____"MISC"_________"OmericOn Express"
"WORLD OUTDOOR EMPLOEE"_______9.48______"LONDSCOPE"____"OmericOn Express"
"WORLD OUTDOOR EMPLOEE"_______31.59_____"LONDSCOPE"____"OmericOn Express"

Looks correctly formatted to me.

Would you be interested in developing the script to measure the ListView elements dynamically so that you always get a formatted return?

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Dynamically determining the formatted return does indeed make a whole lot of sense, so yes.

Now for the "moment of wisdom"... would the difference in the way the csv file is read make a difference in the output?  Your code is flawless, so it would seem the input of data would be the culprit or is that an incorrect conclusion?  If you didn't run my code, could I ask you to run it and see it you get the results I did?  Its my nature to wanna know "why".  That way I would know how to correct what I thought I knew.

Sorry to be a Pain.

 

Hobbyist

Link to comment
Share on other sites

  • Moderators

Hobbyist,

When I read the file using your code I get the following result:

******************************0*****************************
"OLDI"************************46.46*****"FOOD"**************
"OLDI"************************121.75****"FOOD"****"OmericOn Express"
"OMOZON.COM"******************155*******"MISC"****"OmericOn Express"
"OROGOS"**********************14.55*****"GOS"*****"OmericOn Express"
"OROGOS"**********************16.6******"GOS"***************
"DIERbornS"*******************5.64******"FOOD"****"OmericOn Express"
"EQUIP RENTOL"****************10.8******"LONDSCOPE""OmericOn Express"
"MOGPIES"*********************35.81*****"TIM Out"*"CiticOrd"
"NEW BOLONCE"*****************268.22****"CLOTHES"*"OmericOn Express"
"PONERO BREOD"****************21.21*****"TIM OUT"*"OmericOn Express"
"SOPPINGTON GORDENS"**********65.53*****"LONDSCOPE""CiticOrd"
"SOPPINGTON GORDENS"**********114.69****"LONDSCOPE""CiticOrd"
"SPEEDY GOS"******************20.95*****"MISC"****"OmericOn Express"
"SPORTS"**********************20.44*****"TIM OUT"*"OmericOn Express"
"THE HOME DEPOT"**************11.44*****"MISC"****"OmericOn Express"
"THE HOME DEPOT"**************12.19*****"MISC"****"OmericOn Express"
"THE HOME DEPOT"**************14.44*****"MISC"****"OmericOn Express"
"THE HOME DEPOT"**************17.23*****"Misc"****"OmericOn Express"
"THE HOME DEPOT"**************19.97*****"MISC"****"OmericOn Express"
"WOLGREENS"*******************14.55*****"MISC"****"OmericOn Express"
"WOL-MORT"********************17.94*****"MISC"****"OmericOn Express"
"WOL-MORT"********************21.27*****"MISC"****"OmericOn Express"
"WORLD OUTDOOR EMPLOEE"*******9.48******"LONDSCOPE""OmericOn Express"
"WORLD OUTDOOR EMPLOEE"*******31.59*****"LONDSCOPE""OmericOn Express"

So you were reading the file correctly - albeit with an additional first line. There was a cut and paste error which meant I missed the 2 "OLDI" lines when I posted my result earlier - I have checked again and those lines do appear in my code. As I mentioned, the only formatting error was the result of not adjusting column 2, which threw off the alignment of column 4.

So it was not the file reading that caused your problem.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

Hobbyist,

The dynamic width checking code:

#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <File.au3>
#include <Array.au3>

Local $aLog, $sFile = @ScriptDir & "\test data.csv"
_FileReadToArray($sFile, $aLog, $FRTA_NOCOUNT, ",")
;_ArrayDisplay($aLog)

$hGUI = GUICreate("Test", 500, 500)

 $cLV = GUICtrlCreateListView("", 10, 10, 400, 200)
_GUICtrlListView_AddColumn($cLV, "Column 0", 90)
_GUICtrlListView_AddColumn($cLV, "Column 1", 90)
_GUICtrlListView_AddColumn($cLV, "Column 2", 90)
_GUICtrlListView_AddColumn($cLV, "Column 3", 0)
_GUICtrlListView_AddColumn($cLV, "Column 4", 90)

_GUICtrlListView_AddArray($cLV, $alog)


$cFormat = GUICtrlCreateButton("Format", 10, 450, 80, 30)

GUISetState()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $cFormat
            ; Array to hold width of widest element in each column
            Local $aColWidest[UBound($aLog, 2)]
            ; Loop through columns
            For $i = 0 To UBound($aLog, 2) - 1
                ; Loop through rows
                For $j = 0 To UBound($aLog, 1) - 1
                    ; Determine longest element
                    If StringLen($aLog[$j][$i]) > $aColWidest[$i] Then
                        $aColWidest[$i] = StringLen($aLog[$j][$i])
                    EndIf
                Next
            Next
            ; just for interest
            _ArrayDisplay($aColWidest, "", Default, 8)

            ; Now add at 5 additional spaces to each item in each column
            ; Copy array and delete empty column
            $aResult = $aLog
            _ArrayColDelete($aResult, 3)
            ; Now add correct number of characters to each element
            For $i = 0 To UBound($aResult, 2) - 1
                For $j = 0 To UBound($aResult, 1) - 1
                    ; Check how many to add
                    $iAdd = $aColWidest[$i] - StringLen($aResult[$j][$i]) + 5
                    For $k = 1 To $iAdd
                        $aResult[$j][$i] &= "_"
                    Next
                Next
            Next
            ; Display result
            ConsoleWrite(_ArrayToString($aResult, ""))

    EndSwitch

WEnd

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

I so appreciate your efforts, since being relatively new to this, I am sometimes at a lost as to "cause and effect".

So having eliminated the file reading, I had an additional thought and i think "bingo" might be appropriate.

The Autoit version I am using must be the culprit. Version 3.3.10.2.  I installed the latest version on a different computer and it works just like you indicated.  Without your conversation I would have continued to think I was doing something wrong. So my task today is to upgrade the computer I spend time on and move forward.

Thanks again and I am interested in the dynamic approach.

Hobbyist

 

Link to comment
Share on other sites

  • Moderators

Hobbyist,

Glad you found the answer to the problem. Do ask if you have any questions on the dynamic code.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • 4 weeks later...

@M23

If you see this post, I am following up with an additional question to your solution.

I attached your code with some insertions (identified with ;/////////) as I am attempting to try to print the column headers as well, thinking it would be nice to have such labeling.  Long/short - it really doesn't fully work, though I was trying to follow your method for printing the column data.  What I find (if I insert a message box to be able to see each "next") is I get all the column headings but then get the last one multiple times.  Think it might be my for/next???

Any way if you could check my feeble attempt, I would appreciate it.

#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <File.au3>

; Why did I bother writing a new version of this function to read csv files? <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
Local $aLog, $sFile = @ScriptDir & "\test data.csv"
_FileReadToArray($sFile, $aLog, $FRTA_NOCOUNT, ",")
_ArrayDisplay($alog)

$hGUI = GUICreate("Test", 500, 500)

 $cLV = GUICtrlCreateListView("", 10, 10, 400, 200)
_GUICtrlListView_AddColumn($cLV, "Column 0", 90)
_GUICtrlListView_AddColumn($cLV, "Column 1", 90)
_GUICtrlListView_AddColumn($cLV, "Column 2", 90)
_GUICtrlListView_AddColumn($cLV, "Column 3", 0)
_GUICtrlListView_AddColumn($cLV, "Column 4", 90)

_GUICtrlListView_AddArray($cLV, $alog)

$cFormat = GUICtrlCreateButton("Format", 10, 450, 80, 30)

GUISetState()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $cFormat



            ; Final result
            $sFormatted = ""
            $sFormatted2 = "" ;///////////////////////
            ; Loop through lines
            For $i = 0 To _GUICtrlListView_GetItemCount($cLv) - 1
                ; Get line content
                $aLine = _GUICtrlListView_GetItemTextArray($cLV, $i)
                ; Loop through columns
                For $j = 1 To $aLine[0]

                    If $i = 0 Then ;///////////////////////
                        $aInfo = _GUICtrlListView_GetColumn($cLV, ($j) - 1) ;///////////////////////

                    EndIf ;////////////////////////////


                    ; For each column
                    $sText = $aLine[$j]
                    $sText = StringMid($sText, 1, 25);///////////////////////
                    $stextme = StringMid($aInfo[5], 1, 25);///////////////////////
                    ; set default width
                    $iWidth = 10
                    ; Adjust according to column number - remember to use 1-based element, not 0-based column
                    Switch $j
                        Case 1 ; Column 0 - increase width
                            $iWidth = 30
                        Case 3 ; Column 2 - increase width <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
                            $iWidth = 15
                        Case 4 ; Column 3 - ignore
                            ContinueLoop

                    EndSwitch



                    ; Check how many spaces to add
                    $iAdd = $iWidth - StringLen($sText)
                    $iAdd2 = $iWidth - StringLen($stextme);///////////////////////
                    For $k = 1 To $iAdd
                        $sText &= "_"
                    Next

                    For $k = 1 To $iAdd2;///////////////////////
                        $stextme&= "_"
                    Next


                    ; Add result to final result

                    $sFormatted &= $sText
                    $sFormatted2 &= $stextme;///////////////////////

                Next
                ; Create new line
                $sFormatted &= @CRLF
                $sFormatted2 &= @CRLF
            Next
            ; Display result
             ConsoleWrite($sFormatted2 & @CRLF)
;//////////////////
            ConsoleWrite($sFormatted & @CRLF)
    EndSwitch



WEnd

 

Link to comment
Share on other sites

  • Moderators

Hobbyist,

Sorry for the delay in replying - I am on holiday at the moment and the forum is not my first priority (reducing the sherry lake and seafood mountain certainly is!).

I have adjust my own script rather than yours - I hope the changes are clear enough:

#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <File.au3>
#include <Array.au3>

Local $aLog, $sFile = @ScriptDir & "\test data.csv"
_FileReadToArray($sFile, $aLog, $FRTA_NOCOUNT, ",")
;_ArrayDisplay($aLog)

$hGUI = GUICreate("Test", 500, 500)

 $cLV = GUICtrlCreateListView("", 10, 10, 400, 200)
_GUICtrlListView_AddColumn($cLV, "Column 0", 90)
_GUICtrlListView_AddColumn($cLV, "Column 1", 90)
_GUICtrlListView_AddColumn($cLV, "Column 2", 90)
_GUICtrlListView_AddColumn($cLV, "Column 3", 0)
_GUICtrlListView_AddColumn($cLV, "Column 4", 90)

_GUICtrlListView_AddArray($cLV, $alog)


$cFormat = GUICtrlCreateButton("Format", 10, 450, 80, 30)

GUISetState()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $cFormat
            ; Array to hold width of widest element in each column
            Local $aColWidest[UBound($aLog, 2)]
            Local $aColTitles[UBound($aLog, 2)]
            ; Loop through columns
            For $i = 0 To UBound($aLog, 2) - 1
                ; Get column title and set as longest
                $aColTitles[$i] = (_GUICtrlListView_GetColumn ( $cLV, $i))[5]
                $aColWidest[$i] = StringLen($aColTitles[$i])
                ; Loop through rows
                For $j = 0 To UBound($aLog, 1) - 1
                    ; Determine longest element
                    If StringLen($aLog[$j][$i]) > $aColWidest[$i] Then
                        $aColWidest[$i] = StringLen($aLog[$j][$i])
                    EndIf
                Next
            Next
            ; just for interest
            ;_ArrayDisplay($aColWidest, "", Default, 8)

            ; Now add at 5 additional spaces to each item in each column
            $iSpacing = 5
            ; Copy array and delete empty column
            $aResult = $aLog
            _ArrayColDelete($aResult, 3)
            ; Delete corresponding column title
            _ArrayDelete($aColTitles, 3)
            ; Now add correct number of characters to each element
            For $i = 0 To UBound($aResult, 2) - 1
                ; Adjust column titles
                $iAdd = $aColWidest[$i] - StringLen($aColTitles[$i]) + $iSpacing
                For $k = 1 To $iAdd
                    $aColTitles[$i] &= "_"
                Next
                ; Loop through rows
                For $j = 0 To UBound($aResult, 1) - 1
                    ; Check how many to add to each column
                    $iAdd = $aColWidest[$i] - StringLen($aResult[$j][$i]) + $iSpacing
                    For $k = 1 To $iAdd
                        $aResult[$j][$i] &= "_"
                    Next
                Next
            Next
            ; Display result - column titles first
            ConsoleWrite(_ArrayToString($aColTitles, "") & @CRLF)
            ConsoleWrite(_ArrayToString($aResult, "") & @CRLF)

    EndSwitch

WEnd

Please ask if not.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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...