Jump to content
Hobbyist

CSV File To Array To Listview

Recommended Posts

Hobbyist

Here is what I have:

;CSV file has 9 columns, one of which is blank in the middle of the data set. Columns have a header row.
; Number of rows is not known at time of reading file.
;End result is to add the file via the array to the ListView without column heading or element count from the array.

What I am getting is an array with element count and header from CSV file. And of course its ending up in the Listview.

I used an example I found on the site and changed it a bit(as commented) to get to where I thought it would work.

I need help in understanding what I am doing wrong or even suggestions on how to do it better/correctly.

Thanks in advance for help

Hobbyist.

$Myfile2= "C:\Backyard Dig Bush\American\Analysis\tree.csv"

    $csv = FileRead($Myfile2)
    ;$csv = StringStripWS($csv, 7) ; I commented this out as there is a BLANK field in the middle of the data set in each line
, so "white space" was an issue, I think.

    $rows = StringSplit($csv, @CRLF,1) ;used the "1" to eliminate the double spacing per help section
, as @CRLF caused a double spacing.
    Dim $aLogBush[$rows[0] + 1][9]
    $aLogBush[1][0] = $rows[0]
    For $i = 0 To   $rows[0]

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

            $aLogBush[$i][$j] = $temp[$j]
        Next
    Next
_ArrayDisplay($aLogBush)

_GUICtrlListView_AddArray($List500, $aLogBush)

 

Share this post


Link to post
Share on other sites
MikahS

Can you post the creation of the listview, and give us an idea of how you would like it to look. I understand you don't want the header or count? Is this for your listview or the _ArrayDisplay you are doing of the Array? The more information the better. 


Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Share this post


Link to post
Share on other sites
Melba23

Hobbyist,

Using this file:

Col 0,Col 1,Col21,Col 3,Col 4,Col 5,Col 6,Col 7,Col 8
Data 00,Data 01,Data 02,Data 03,,Data 05,Data 06,Data 07,Data 08
Data 10,Data 11,Data 12,Data 13,,Data 15,Data 16,Data 17,Data 18

I would create the ListView like this:

#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <GUIListView.au3>
#include <Array.au3>
#include <File.au3>

; Read csv file into array
Local $aArray

_FileReadToArray ("Data.csv", $aArray, $FRTA_COUNT, ",")

; Create GUI
$hGUI = GUICreate("Test", 600, 500)

; Create ListView

$cLV = GUICtrlCreateListView("", 10, 10, 580, 300)
; Add columns (count is in the array)
For $i = 0 To $aArray[0][1] - 1
    _GUICtrlListView_AddColumn($cLV, $aArray[1][$i], 60)
Next

; Remove the count and header rows
_ArrayDelete($aArray, "0;1")

; Add data
_GUICtrlListView_AddArray($cLV, $aArray)

GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    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 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

 

Share this post


Link to post
Share on other sites
Hobbyist

Thanks M231

And yes - QUESTIONS....

I did a copy and paste of your code (which is sleeker than mine) to see it in action and LEARN something.

I also saved your data set and then also used mine.

I got the following errors

warning:$FTRA_COUNT;possibly used before declaration.

error: _FileReadToArray() called with wrong number of args.

error: $FRTA_COUNT:undeclared global variable.

 

I definitely want to see yours in action, as it is something I have not seen before.  

What could be the source of the errors?

Using:

SciTE
Version 3.4.1
    Mar 30 2014 21:57:28

 

Thanks and sorry for being a pain on this.

Hobbyist

Share this post


Link to post
Share on other sites
iamtheky

https://www.autoitscript.com/autoit3/docs/libfunctions/_FileReadToArray.htm

replace it with the magic number 1 for now and I would suppose the constants (or magic strings) are in a newer file.au3 than the one you are including so you should hit alt-i and see what arguments differ in your file and/or just install the lastest version and screw troubleshooting.

Edited by boththose
- issues

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
Share on other sites
Hobbyist

boththose

 

Iam really new at this stuff.  What are you referring to when you say "install latest version" ?  SciTE?  file.au3?

Share this post


Link to post
Share on other sites
iamtheky

you will get all the latest include files with latest version of autoit.  SciTE version matters very little when troubleshooting.

Edited by boththose

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
Share on other sites
Hobbyist

OK - I'll try that.

One last newbie question if you don't mind.

 

Backward compatibility.  Although the little things I coded so far are for my learning purposes, I wouldn't want to lose their functionality or whatever you call it.  

 

Thanks

Share this post


Link to post
Share on other sites
iamtheky

no worries, most changes are small, like an additional parameter.  So while they are script breaking, they are not terribly difficult to modify.  And you can always keep the old versions of autoit to compile legacy scripts rather than update them.


,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
Share on other sites
Hobbyist

boththose

If I may ask another question before it veers off topic too far...

I did go to the home page and download the latest version, as per your suggestion.

I am hestitant to do such because of potential problems and I am NO expert in this stuff to begin with.

Any way, downloaded it and installed it on a laptop rather than my desktop because I didn't want to lose what IS working now.

On the laptop, installation says successful, but when running Autoit or SCE I get the following error

"The procedure entry point DecoderPointer could not be located in the dynamic link library Kernell32.dll."

Huh!?

Laptop runs XP (yes its old but I keep it around) versus my desktop running Vista.  I did not have any issues with installation of the version I have been running.

Share this post


Link to post
Share on other sites
iamtheky

 I have never experienced that issue.  I would post a new topic as that is a different, much more catastrophic issue, and the people you want answering that thread are probably not reading this one. 


,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
Share on other sites
Melba23

Hobbyist,

Minimum OS requirements are now Windows XP SP3

You say the laptop is old - is it at least SP3?

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

 

Share this post


Link to post
Share on other sites
Hobbyist

M23 & boththose

 

I am so sorry for my last question.  I just did some research on the error message and see its the SP3 issue.

I was going down the very cautious road of installing the newer Autoit.  

Thanks again for your patience and knowledge.

 

Hobbyist

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

×