Solved

Difficult Structures

Posted on 2004-10-17
18
181 Views
Last Modified: 2010-05-02
Hi all

I have a file with records:

lvl|thread|title|description|filename

| is the field seperator and vbcrlf is the record seperator

What needs to be done is to load the file in a structure based on lvl and thread so I can make a tree

thread 0 lvl 0 title
thread 0 lvl 0 title
    thread 0 lvl 1 title
        thread 0 lvl 2 title
thread 1 lvl 0 title
      thread 1 lvl 1 title

etc

0
Comment
Question by:x_terminat_or_3
  • 9
  • 6
  • 3
18 Comments
 
LVL 48

Expert Comment

by:Mikal613
Comment Utility
just load it to file as is

thread 0 lvl 0 title
thread 0 lvl 0 title
thread 0 lvl 1 title
thread 0 lvl 2 title
thread 1 lvl 0 title
thread 1 lvl 1 title

and load in the program with nested loops
dim CurrLvl as number
dim CurrThread

Do until eof(1) 'Your file pointer
   
    IF level <> currlvl
        LoadNext and indent
  else
     loadnext
  end if

    Undertstand?
0
 
LVL 2

Author Comment

by:x_terminat_or_3
Comment Utility
Not exactly


This seems to simple

I need to recreate the treestructure in memory and then be able to walk trough the tree like this:


thread 0
   level 0
       document 1
     level 1
            document 1
            document 2
       level 2
           document 1
       level 3
           document 1
thread 1
     level 0
         document 1

etc

 
0
 
LVL 48

Expert Comment

by:Mikal613
Comment Utility
so you need a treeview not a listview
0
 
LVL 2

Author Comment

by:x_terminat_or_3
Comment Utility
who said anything about listviews or treeviews?  It needs to be loaded in a structure in memory
0
 
LVL 48

Expert Comment

by:Mikal613
Comment Utility
0
 
LVL 2

Author Comment

by:x_terminat_or_3
Comment Utility
I know about classes, collections, and all that, it's just that I'm stuck and need help

0
 
LVL 48

Expert Comment

by:Mikal613
Comment Utility
"so I can make a tree" means  a treeview??

Can you explain what you want in depth?
0
 
LVL 2

Author Comment

by:x_terminat_or_3
Comment Utility
I have a website which is rather big and has many documents in subdirectories.

I have indexed all the pages into a file with the following format:

lvl|threadid|title|description|filename

The program needs to interpret the file and output a sitemap that recreates the tree with nested <UL>s

example:
thread 0
   level 0
       document 1
     level 1
            document 1
            document 2
       level 2
           document 1
       level 3
           document 1
thread 1
     level 0
         document 1
0
 
LVL 48

Expert Comment

by:Mikal613
Comment Utility
how are you gonna show that tree in your website?
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 2

Author Comment

by:x_terminat_or_3
Comment Utility
<UL>
  <!-- this is lvl 0 -->
  <li>DocTitle 1<br>
        DocDescription 1
       <a href="docurl1">docurl1</a>
       <UL>
         <! this is lvl 1 -->
         <li>DocTitle 2<br>

..
...
0
 
LVL 48

Expert Comment

by:Mikal613
Comment Utility
0
 
LVL 2

Author Comment

by:x_terminat_or_3
Comment Utility
So how can I implement this with my requirements?
0
 
LVL 16

Accepted Solution

by:
jimbobmcgee earned 500 total points
Comment Utility
What about using a recordset from your flat file (might have to change to CSV)?  That way you could SELECT based on level or thread numbers, as well as using GROUP BY, e.g.:

    RS.Open "SELECT [title], [desc], [file] FROM thiscsvtable WHERE [thread] = 'thread1' AND [lvl] = 'lvl1'"

would give you all the documents in thread 1, lvl 1.

You could also enumerate all the threads with:

    RS.Open "SELECT DISTINCT [thread] FROM thiscsvtable"

Or get a little more complicated, with:

    RSThreads.Open "SELECT DISTINCT [thread] FROM thiscsvtable"
    RSThreads.MoveFirst
    Do Until RSThreads.EOF

         'WRITE THREAD HEADER HERE
         
         RSLvls.Open "SELECT [lvl] FROM thiscsvtable WHERE [thread] = '" & RSThreads.Fields(0).Value & "'"
         RSLvls.MoveFirst
         Do Until RSLvls.EOF

              'WRITE LVL HEADER HERE

              RSDocs.Open "SELECT [title], [desc], [file] FROM thiscsvtable WHERE [thread] = '" & _
                                  RSThreads.Fields(0).Value & "' AND [lvl] = '" & _
                                  RSLvls.Fields(0).Value & "'"

              RSDocs.MoveFirst
              Do Until RSDocs.EOF

                   'WRITE DOC LINKS HERE
                   RSDocs.MoveNext

              Loop
              RSDocs.Close
              RSLvls.MoveNext

         Loop
         RSLvls.Close
         RSThreads.MoveNext

     Loop
     RSThreads.Close

You'll need to find out the methods and best practices when dealing with CSV-based recordsets, if you are planning on doing this on-the-fly.  If it is a one-off, it might be worth pasting your data into an Access table...

HTH

J.

(NB: If you are going to do it all with arrays/VB, maybe you should recompile your flat file, so it does not have the 'thread' and 'lvl' text?  e.g.:

     0|0|title1|desc1|file1
     0|1|title2|desc2|file2
     1|0|title3|desc3|file3
     ...etc.

Otherwise, you may find it more complicated to calculate, as you'd have to strip 'thread' and 'lvl' from your fields, in order to process them as numbers...)
0
 
LVL 2

Author Comment

by:x_terminat_or_3
Comment Utility
jimbo

I think I like this approach.


NB: the file doesn't have the thread and lvl txt in it, I just posted it here so you would understand it better.



Regards


x
0
 
LVL 16

Expert Comment

by:jimbobmcgee
Comment Utility
You will need to find out how to reference columns directly using CSVs and SQL; the code I posted would work best with an Access database (with the right connection strings).

Glad I helped,

Thanks for the points

J.
0
 
LVL 2

Author Comment

by:x_terminat_or_3
Comment Utility
Once connected, it's all the same; access, cvs, odbc,...

database.recordsets(r).fields(f).value
0
 
LVL 16

Expert Comment

by:jimbobmcgee
Comment Utility
Is there any way of opening a connection to a CSV and using SQL on it, other that "SELECT * FROM..."?

Say if you wanted sum of the third column, with group by first column?
0
 
LVL 2

Author Comment

by:x_terminat_or_3
Comment Utility
I may be wrong, but I think it don't matter what kind of database you use.  Only difference is how to connect
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

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.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…

772 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

12 Experts available now in Live!

Get 1:1 Help Now