Jump to content

how to process multiple filenames on a listview


Recommended Posts

i want to let a user select multiple files, and then add it to a listview.

so, i use stringsplit to get a array, but what then???

see my code of what i tried XD

$var = FileOpenDialog(" Wim Image Mounter", " ", "Language Packs (*.Cab)", 1 + 2 + 4, "lp.cab")
 $Pack = StringSplit($var, "|")
 If Not @error Then
  ;Create listview items
  For $x = 0 To $Pack[0]
   $ListView1_[$x] = GUICtrlCreateListViewItem($Pack[+1], $ListView1)
  Next
 EndIf

now, i was suprised it didnt error ^^, but it also doesnt do what i want, fill my listview with the filenames :(

it repeats the first filename over and over, till the max number of files is reached...

any help is appriciated >_<

Damian666

and proud of it!!!
Link to comment
Share on other sites

On your fourth line of code try replacing $Pack[+1] with $Pack[$x].

The Wheel of Time turns, and Ages come and pass, leaving memories that become legend. Legend fades to myth, and even myth is long forgotten when the Age that gave it birth comes again.

Link to comment
Share on other sites

damn your fast XD

ok, that does work, but now i have the problem of having to seperate the first 2 array values, which ofcourse gimme the total number, and filepath in this context.

how would i set $x to begin at array entry 3?

and while were at it, when i have a listview with 3 colums, would it then be:

$var = FileOpenDialog(" Wim Image Mounter", " ", "Language Packs (*.Cab)", 1 + 2 + 4, "lp.cab")
$Pack = StringSplit($var, "|")
If Not @error Then
  ;Create listview items
  For $x = 0 To $Pack[0]
   $ListView1_[$x] = GUICtrlCreateListViewItem($Pack[$x] & "|" & $Pack[$x] & "|" & $Pack[$x], $ListView1)
  Next
EndIf

???

thanx for helping me out mate ^^

both of you >_<

Damian666

Edited by damian666
and proud of it!!!
Link to comment
Share on other sites

Yes, the that is how you would create a listview with columns. To make it begin at array entry 3, well, $x starts at 0, so do $Pack[$x + 3].

The Wheel of Time turns, and Ages come and pass, leaving memories that become legend. Legend fades to myth, and even myth is long forgotten when the Age that gave it birth comes again.

Link to comment
Share on other sites

hmm... but that seems to error mate...

==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.:

and it highlights the $Pack with the +3

also, when i select only 1 file, it doesnt show anything at all :S

sorry i ask so much, i have been using AI for 2 years now, but i never had to use arrays this much XD

Edit: the part of starting it on third entry i figured, it should be $x = 2 to $pack[0]

but it wont show anything on selecting only 1 file...

Damian666

Edited by damian666
and proud of it!!!
Link to comment
Share on other sites

Oh, duh, I should have realized that the dimension would have been exceeded. Stupid mistake. I guess I misunderstood your question. I thought that you wanted to populate the listview starting with the 3rd file selected. Woops.

This should work.

$var = FileOpenDialog(" Wim Image Mounter", " ", "Language Packs (*.Cab)", 1 + 2 + 4, "lp.cab")
$Pack = StringSplit($var, "|")

Dim $Packstartat3[$Pack[0] + 3]

For $i = 1 To $Pack[0]
    $Packstartat3[$i + 2] = $Pack[$i]
Next

If Not @error Then
    ;Create listview item
    For $x = 0 To $Pack[0]
        $ListView1_[$x] = GUICtrlCreateListViewItem($Packstartat3[$x], $ListView1)
    Next
EndIf

You won't, of course, have the first value of the new array being the dimensions, so you will have to use ubound if you need the dimensions.

Edited by Hawkwing

The Wheel of Time turns, and Ages come and pass, leaving memories that become legend. Legend fades to myth, and even myth is long forgotten when the Age that gave it birth comes again.

Link to comment
Share on other sites

This is faster!

$var = FileOpenDialog(" Wim Image Mounter", " ", "Language Packs (*.Cab)", 1 + 2 + 4, "lp.cab")
$Pack = StringSplit($var, "|")



If Not @error Then
    ;Create listview item
    For $x = 0 To $Pack[0] - 3
        $ListView1_[$x] = GUICtrlCreateListViewItem($Pack[$x + 3], $ListView1)
    Next
EndIf
Link to comment
Share on other sites

hmm... well... i rather not use ubound, that gets even harder for me then XD

i have this so far:

$var = FileOpenDialog(" Wim Image Mounter", " ", "Language Packs (*.Cab)", 1 + 2 + 4, "lp.cab")
 $Pack = StringSplit($var, "|")
 If Not @error Then
  ;Create listview items
  For $x = 2 To $Pack[0]
   $ListView1_[$x] = GUICtrlCreateListViewItem($Pack[1] & "\" & $Pack[$x], $ListView1)
   ConsoleWrite($Pack[1] & "\" & $Pack[$x] & @CRLF)
  Next
  $ListView1_[$x] = GUICtrlCreateListViewItem("", $ListView1)
 EndIf

only issue left, is when selecting 1 file, it wont show anything in my listview, multiple work great though ^^

Damian666

and proud of it!!!
Link to comment
Share on other sites

Better to get the practice with Ubound()

$aArray[0] only works for 1 based arrays and many times it's not a 1 based array that's returned.

For $i = 1 To Ubound($aArray) -1

or

For $i= 0 to Ubound($aArray) -1

Will work no matter what.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

yeah... i thought you would say that ^^

but seeying i have it working except that little issue, i can get off the hook for now >_<

because i guess using ubound in this context wont solve that problem right?

Damian666

and proud of it!!!
Link to comment
Share on other sites

Do For $x = 1 To... instead of $x = 2. I think you got that from my mistaken assumption that you wanted to leave out the first few files rather that have the array start at 3.

The Wheel of Time turns, and Ages come and pass, leaving memories that become legend. Legend fades to myth, and even myth is long forgotten when the Age that gave it birth comes again.

Link to comment
Share on other sites

Do For $x = 1 To... instead of $x = 2. I think you got that from my mistaken assumption that you wanted to leave out the first few files rather that have the array start at 3.

I thought he want to leave out 4 files $x = 3 remember?

Yap, you are not the only one confuse.

Link to comment
Share on other sites

I think he wanted to start the array at 3 and I thought he meant he wanted to start populating the listview at 3, therefore leaving out some files. Now we're all confused.

The Wheel of Time turns, and Ages come and pass, leaving memories that become legend. Legend fades to myth, and even myth is long forgotten when the Age that gave it birth comes again.

Link to comment
Share on other sites

its not that i want to populate it at line 3, i want it to start populating it from the beginning, but without the first few array entries, because those will gimme number of files, and filepath.

and i just need filenames.

as you see in my code, i use the combination of 2, to get filepath, AND filename to form myself a whole filepath.

only issue, when selecting 1 file only, it just doesnt show anything on the listview.

Damian666

and proud of it!!!
Link to comment
Share on other sites

If it's working completely except for that, just use an If...Else...Then and check $Pack for "|". If it doesn't have it then just put the one file on the listview, else use the For...Next that you already have working.

The Wheel of Time turns, and Ages come and pass, leaving memories that become legend. Legend fades to myth, and even myth is long forgotten when the Age that gave it birth comes again.

Link to comment
Share on other sites

oh duh... and here i am looking at some weird stuff to do the same easy thing... xD

thanx man, that will conclude our little help session for today, you learned me some stuff, always good ^^

thanx a bunch >_<, all of you.

Damian666

and proud of it!!!
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...