Solved

Many Lists

Posted on 2002-06-17
12
159 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
Comment Utility
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
Comment Utility
>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
Comment Utility
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
 
LVL 19

Author Comment

by:BrianGEFF719
Comment Utility
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
Comment Utility
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
Comment Utility
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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 38

Expert Comment

by:PaulHews
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
per recommendation

SpideyMod
Community Support Moderator @Experts Exchange
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Vb.net Listview 9 76
z = x + y – 1 6 55
Pull multiple cvs files into one access table 28 57
Access 2013 combo box not working 3 23
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…
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.
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 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…

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

11 Experts available now in Live!

Get 1:1 Help Now