Solved

Listbox help - items in a listbox

Posted on 2002-03-23
7
229 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
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
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 
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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Suggested Solutions

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…

803 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