Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Index FileListBox

2 views
Skip to first unread message

LondonLad

unread,
Dec 28, 2009, 4:19:01 AM12/28/09
to
Hi
My original post asked if when I clicked an item (say 2nd in list) in File1
for the same item in the list of File2 to be highlighted.
The answer was yes use

File2.ListIndex = File1.ListIndex

this gives an error when I check File2.ListIndex = 0 and File1.ListIndex = 1
my assumption was that FileListBox2 was not indexed so I used this code to
index the list
Copied from Sample Code @
http://vbnet.mvps.org/index.html

Dim Num as Long ' = Num of Items in List
Dim i as Long ' = i Index Number
Dim xName() as String ' = Var

fPath = Dir.Path

For Num = 0 To File2.ListCount - 1
If File1.ListCount > 0 Then
i = i + 1
ReDim Preserve xName(1 to i)
xName(i) = fPath &"\" & File2.List(Num)
End If
Next
has this indexed the File2 it seems not
This has not solved the problem can you help please?

Larry Serflaten

unread,
Dec 28, 2009, 6:20:03 AM12/28/09
to

"LondonLad" <Lond...@discussions.microsoft.com> wrote

> My original post asked if when I clicked an item (say 2nd in list) in File1
> for the same item in the list of File2 to be highlighted.
> The answer was yes use
>
> File2.ListIndex = File1.ListIndex
>
> this gives an error when I check File2.ListIndex = 0 and File1.ListIndex = 1
> my assumption was that FileListBox2 was not indexed so I used this code to
> index the list

Go back to using the above command in the Click event and find
out why it gives you an error. What is the error? Is there any other
code in the click event (of either control)?

LFS


LondonLad

unread,
Dec 28, 2009, 9:18:01 AM12/28/09
to
Hi Larry
The error I get is:-
Invalid Property Array Index
and as I said when I check File2.ListIndex = 0 and File1.ListIndex = 1 this
is after I have run the code I posted.
Any ideas

"Larry Serflaten" wrote:

> .
>

Larry Serflaten

unread,
Dec 28, 2009, 12:07:29 PM12/28/09
to

"LondonLad" <Lond...@discussions.microsoft.com> wrote

> The error I get is:-
> Invalid Property Array Index
> and as I said when I check File2.ListIndex = 0 and File1.ListIndex = 1 this
> is after I have run the code I posted.
> Any ideas

Before the failing statement add a debug statement:

Debug.Print File1.ListCount, File2.ListCount

Check to see if the list sizes match....

LFS


LondonLad

unread,
Dec 30, 2009, 4:58:01 AM12/30/09
to
Hi Larry
Yes I did that already and they are both the same number
that's why I could not understand the error.
Rick Rothstein gave me the code so I knew it was good but cannot understand
why it fails.
Stuck unless you have any other ideas


"Larry Serflaten" wrote:

> .
>

Larry Serflaten

unread,
Dec 30, 2009, 7:42:14 AM12/30/09
to

"LondonLad" <Lond...@discussions.microsoft.com> wrote

> Hi Larry
> Yes I did that already and they are both the same number
> that's why I could not understand the error.
> Rick Rothstein gave me the code so I knew it was good but cannot understand
> why it fails.
> Stuck unless you have any other ideas

Start a new project and add two file list boxes to act as you want.
See if it happens there, and if not, find the difference in your original
program. If that also errors, post the code so we can try it on our own
system...

LFS


LondonLad

unread,
Dec 30, 2009, 10:26:02 AM12/30/09
to
Hi Larry
The code I am using was not written by me so I cannot post it here, and I do
not know how to load a FileListBox.
Stuck again

"Larry Serflaten" wrote:

> .
>

Nobody

unread,
Dec 30, 2009, 11:37:16 AM12/30/09
to
"LondonLad" <Lond...@discussions.microsoft.com> wrote in message
news:55C86CE2-876D-47BA...@microsoft.com...

> Hi Larry
> The code I am using was not written by me so I cannot post it here, and I
> do
> not know how to load a FileListBox.
> Stuck again

You can share some of it without needing the author's permission, even if
the author require permission:

http://en.wikipedia.org/wiki/Fair_use


Larry Serflaten

unread,
Dec 30, 2009, 11:43:12 AM12/30/09
to

"LondonLad" <Lond...@discussions.microsoft.com> wrote


> The code I am using was not written by me so I cannot post it here, and I do
> not know how to load a FileListBox.


As you might guess, its nearly impossible to tell you what is wrong
with your code, if you never show the code you are using....

LFS


LondonLad

unread,
Dec 31, 2009, 9:21:01 AM12/31/09
to
Hi Larry
If somebody can show me how to load a FileListBox I can post some code, this
will do 2 things, I will understand how to load some data and lastly I will
be able to clear an error in a project.
This error started after an earlier post where I asked if it was possible to
click an item in a FileListBox (File1) for the corresponding item in the next
FileListBox (File2) could be selected the answer I received was yes use
File2.ListIndex = File1.ListIndex.

"Larry Serflaten" wrote:

> .
>

Larry Serflaten

unread,
Dec 31, 2009, 1:48:55 PM12/31/09
to

"LondonLad" <Lond...@discussions.microsoft.com> wrote

> If somebody can show me how to load a FileListBox I can post some code,

Take a moment to consider that when programing was invented, people had
no one to tell them what to do! They had to look at the tools they had
(statements, commands) and figure a way to get the job done. That is still
the essence of programming; completing the task using the tools you have.

If you wait for someone to show you all the simple tasks, you'll be old
and gray before you get 3 projects done. What did you try?

If you put a file list box on a form it fills up with files, does it not???
Had you tried to test it yourself, you would have seen that.

None the less, here is a simple example. Add 2 FileList boxes to a new
form and paste in the code below....

LFS


Private Sub Form_Load()
File1.Pattern = "*.exe"
File2.Pattern = "*.dll"
'File1.Path = "C:\Temp"
'File2.Path = "C:\Temp"
File1.Enabled = False
End Sub

Private Sub File2_Click()
If File1.ListCount > File2.ListIndex Then
File1.ListIndex = File2.ListIndex
Else
File1.ListIndex = -1
End If
End Sub

LondonLad

unread,
Jan 1, 2010, 6:29:01 AM1/1/10
to
Hi Larry
First I would like to say a big thank you for sticking with me on this
problem.
Not to be flippant my hair is already grey I do try very hard to solve my
own problems, first by my books the on google but on this one I could not
seem to find anything that could help me, hence my request.
OK back to the problem i built the test prog as you said and it worked fine
I then tried to putting the same code in my project but I kept getting errors
either to do with Indexing or Stack errors.
But I now know what will stop the errors in my project I had the MultiSelect
= 1 Simple in the Test MultiSelect = 0 None when I change the project it
works fine.the Test will not work on MultiSelect = 1
so is there a way to get round this problem?

"Larry Serflaten" wrote:

> .
>

Nobody

unread,
Jan 1, 2010, 9:21:58 AM1/1/10
to

"LondonLad" <Lond...@discussions.microsoft.com> wrote in message
news:81152FD5-8EDD-4FE1...@microsoft.com...

> Hi Larry
> First I would like to say a big thank you for sticking with me on this
> problem.
> Not to be flippant my hair is already grey I do try very hard to solve my
> own problems, first by my books the on google but on this one I could not
> seem to find anything that could help me, hence my request.
> OK back to the problem i built the test prog as you said and it worked
> fine
> I then tried to putting the same code in my project but I kept getting
> errors
> either to do with Indexing or Stack errors.
> But I now know what will stop the errors in my project I had the
> MultiSelect
> = 1 Simple in the Test MultiSelect = 0 None when I change the project it
> works fine.the Test will not work on MultiSelect = 1
> so is there a way to get round this problem?

Check the Enabled property of both file lists. I think that some operations
that you can't do when it's disabled. Enable them all and see if the problem
disappears.


LondonLad

unread,
Jan 1, 2010, 11:11:01 AM1/1/10
to
Hi Nobody
Both FileListBox's Enabled
I just tried that but it did not make any difference

"Nobody" wrote:

> .
>

0 new messages