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
Solved

Listbox help - items in a listbox

Posted on 2002-03-23
7
235 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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…
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…

828 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