Solved

Listbox help - items in a listbox

Posted on 2002-03-23
7
251 Views
Last Modified: 2010-05-02
Hey-
I am making a program that stores filenames in a list box....later on i want the program to go through each file in the listbox.  How do i tell the program to go to the fifth(or fourth, or third, or 100th...) item in a listbox?

Thanks!!

I never use this so i am making it worth a lot
0
Comment
Question by:short_fat_n_black
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 3

Expert Comment

by:jbil
ID: 6891626
List1.ListIndex = 5' or 4 or 3 or 100
0
 
LVL 3

Expert Comment

by:Bahnass
ID: 6891647
Dear Beautiful

List1.ListIndex = 5
makes 5th selected as if user choosed it


if U need to get 5th filwe name

debug.print List1.list(5)

So if user choosed some file and U need it to process

such as

Sub list1_click()
Dim I as integer
I=List1.ListIndex
FileName=List1.list(I)
end sub

thin tall, white n married !!!!!!!!
hhope that helps
0
 
LVL 3

Accepted Solution

by:
GeneM earned 300 total points
ID: 6891679
The following program loads 4 file names into list 1 when the form is loaded.  On clicking Command1 it prints each of the file names.

Private Sub Command1_Click()
    Dim i As Integer
    For i = 0 To List1.ListCount - 1
        Debug.Print List1.List(i)
    Next i
End Sub

Private Sub Form_Load()
    List1.AddItem "C:\Autoexec.bat"
    List1.AddItem "C:\My Documents"
    List1.AddItem "C:\My Pictures"
    List1.AddItem "C:\Temp"
End Sub
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 6891867
short_fat_n_bla is not a valid member
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 6891868
Please ignore previous bogus message.

Thanks,
Anthony
0
 
LVL 5

Expert Comment

by:kcm76
ID: 6891881
U accept the filenumber from the user say in text1.text.
then as many experts said, use listindex property to point the file like

nFileNumber = Cint(text1.text)
if nFileNumber < list1.listcount then
   list1.listindex = nFileNumber
else
   Msgbox "There are " & list1.listcount & " files only"
end if


ALL THE BEST
KCM

*********************************************
To  Bahnass
list1.listindex = 5 will not select the fifth item. It will select the sixth item as the listindex starts with zero.

**********************************************

0
 
LVL 2

Expert Comment

by:anand_007
ID: 6892115
Use
       option base 1
in the start of your code, to set your index to 1 if you do not want it to start from zero! And hey, I don't get your problem. Use a combo-box having style 2 so that no one can add onto the box. Now use the on_Click property for the combo and get the name of the file as combo_box.Text! Proceed to open this file. Simple! Hope you accept this as an answer, since I've used this trick loads of times!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question