Solved

Listbox help - items in a listbox

Posted on 2002-03-23
7
210 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
Comment Utility
List1.ListIndex = 5' or 4 or 3 or 100
0
 
LVL 3

Expert Comment

by:Bahnass
Comment Utility
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
Comment Utility
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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 75

Expert Comment

by:Anthony Perkins
Comment Utility
short_fat_n_bla is not a valid member
0
 
LVL 75

Expert Comment

by:Anthony Perkins
Comment Utility
Please ignore previous bogus message.

Thanks,
Anthony
0
 
LVL 5

Expert Comment

by:kcm76
Comment Utility
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
Comment Utility
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

763 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

9 Experts available now in Live!

Get 1:1 Help Now