Solved

Many Lists

Posted on 2002-06-17
12
161 Views
Last Modified: 2010-05-02
Hi,
I'm writing a program, the way it needs to work is, i need to have a listbox with a list of text files...and in each text file there is about 130,000 lines. I need to have a way to go through each item in the file then go on to the next file, but the thing is, i cant just do a loop and go that way, i have to be able to get the next item in random places in the program, so i was thinking a function but i cant think of a way to do this, because it would be innefective to jsut keep openin gthe file and scanning to the place in the file to get the next item...can anyone help me out with this?
0
Comment
Question by:BrianGEFF719
  • 4
  • 3
  • 2
  • +3
12 Comments
 
LVL 26

Expert Comment

by:EDDYKT
ID: 7083490
I think you can read the whole file at one shot and then use instr to find your str


ie.
Dim ff As Integer, Filename As String, s As String
   
    Filename = "your file"
    ff = FreeFile
    Open Filename For Binary Access Read Lock Read Write As #ff
    s = Space$(LOF(ff))
    Get #ff, , s
    Close ff
0
 
LVL 38

Expert Comment

by:PaulHews
ID: 7083536
>be able to get the next item in random places in the program

What are the rules to abandon the file we have open and go to the next one?
0
 
LVL 19

Author Comment

by:BrianGEFF719
ID: 7088779
here is what i was thinking, just load 30,000 items at a time to another listbox, then when the listbox that contains the items gets empty load up another 30,000 until we hit the end of the lsit, then goto the next list...but it just doesnt seem effective to me. AND ITS NOT RANDOM ITS EACH LINE ONE AFTER ANOTHER
0
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
LVL 19

Author Comment

by:BrianGEFF719
ID: 7115127
I have not received an answer for my question, I'm going to delete it. If anyone has any last comments that they think may help please post them and i wont delete the question.


-Brian
0
 
LVL 1

Expert Comment

by:Moondancer
ID: 7115210
Listening for updates, and hope that Experts respond here with help for you.

We are doing to do some server transitioning today and may experience a little down time.

Moondancer - EE Moderator
0
 
LVL 38

Expert Comment

by:PaulHews
ID: 7115271
Brian, I am still trying to understand your problem.  It sounds as if you want to open each file in sequential mode, read each line and process it.  A structured way to do that would be with a loop:

    Dim i As Integer
    Dim hFile As Integer
    Dim strLine As String
    For i = 0 To lstFiles.ListCount - 1
        hFile = FreeFile
        Open lstFiles.List(i) For Input As #hFile
        Do While Not EOF(hFile)
            Line Input #hFile, strLine
            'code to process line
        Loop
    Next i

So why isn't this approach suitable?
0
 
LVL 38

Expert Comment

by:PaulHews
ID: 7115272
Forgot to close:

    Dim i As Integer
    Dim hFile As Integer
    Dim strLine As String
    For i = 0 To lstFiles.ListCount - 1
        hFile = FreeFile
        Open lstFiles.List(i) For Input As #hFile
        Do While Not EOF(hFile)
            Line Input #hFile, strLine
            'code to process line
        Loop
        Close #hFile
    Next i
0
 
LVL 26

Expert Comment

by:EDDYKT
ID: 7116058
As what I said, you can read the whole file in one shot and then use split function to separate each line.


ie.
dim arr, i as long

arr = split(s, vbcrlf)

for i=0 to ubound(arr)-1

' process your string
'arr(i)
next

Another thing I want to point out is listbox is slow if you add more than 30000 items, use listview

for more info
http://www.experts-exchange.com/jsp/qManageQuestion.jsp?ta=visualbasic&qid=20299351
0
 
LVL 19

Author Comment

by:BrianGEFF719
ID: 7116064
here is what i was thinkin, write a sub to load list items to a INVISIBLE listbox, and ill load 30,000 items at a time and when the list gets empty, it will just call the sub again, and the sub will ahve the place it left off as a static....do u ppl think that would work?
0
 
LVL 38

Accepted Solution

by:
PaulHews earned 200 total points
ID: 7117015
You might get it to work, but it's not very efficient to load a list for this purpose.  Controls are slower than variables, and in this case, you are accessing the listbox 3 times for each of the 100K+ lines.  Once to add the item, once to process it and once to remove it.  And as Eddy pointed out, the listbox gets slower the more stuff you add to it.  It's just not designed to efficiently handle large numbers of items.  Add to that the complexity of arranging exactly 30000 lines at a time (how do you read in the lines in the first place?) and you have a nasty/inefficient/slow system that you will not be proud of, and that will be difficult for you to debug and for others to understand.

Eddy's method will be quite fast.  The only danger when reading in large amounts of data into memory is that you can have memory problems if the system is low on memory, or if the files are particularly large.  If those are not a concern then this is the way to go.

My method will be slower by comparison (and depending what kind of processing you are doing on each line, it may take quite a long time) but it doesn't read everything into memory at one time.  In programming, this is the compromise you usually make: use more memory and get more speed.

There is another in method you could use, but I wouldn't suggest it until you have more programming experience.  It involves using binary file methods to read the file in fairly large chunks, splitting those chunks into lines and processing each chunk in turn until the file is finished.  This is a compromise between the first two methods; not blowing out the memory and not wasting time in many small disk reads.


0
 
LVL 49

Expert Comment

by:DanRollins
ID: 7911054
Hi BrianGEFF719,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:

    Accept PaulHews's comment(s) as an answer.

BrianGEFF719, if you think your question was not answered at all or if you need help, just post a new comment here; Community Support will help you.  DO NOT accept this comment as an answer.

EXPERTS: If you disagree with that recommendation, please post an explanatory comment.
==========
DanRollins -- EE database cleanup volunteer
0
 

Expert Comment

by:SpideyMod
ID: 7967638
per recommendation

SpideyMod
Community Support Moderator @Experts Exchange
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Excel - Save a copy of work book 13 84
Visual Studio search word table and return Cell index 8 60
TT Auto Dashboard 13 92
IF ELSE Statement in Excel Macro VBA 16 62
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…
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…
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…
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…

786 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