Solved

Listbox help - items in a listbox

Posted on 2002-03-23
7
222 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

863 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now