Solved

Difficult Structures

Posted on 2004-10-17
18
183 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
ID: 12332093
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
ID: 12332108
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
ID: 12332202
so you need a treeview not a listview
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 2

Author Comment

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

Expert Comment

by:Mikal613
ID: 12332368
0
 
LVL 2

Author Comment

by:x_terminat_or_3
ID: 12332382
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
ID: 12332410
"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
ID: 12332550
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
ID: 12332559
how are you gonna show that tree in your website?
0
 
LVL 2

Author Comment

by:x_terminat_or_3
ID: 12332572
<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
ID: 12332596
0
 
LVL 2

Author Comment

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

Accepted Solution

by:
jimbobmcgee earned 500 total points
ID: 12337565
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
ID: 12337855
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
ID: 12342578
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
ID: 12344775
Once connected, it's all the same; access, cvs, odbc,...

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

Expert Comment

by:jimbobmcgee
ID: 12345766
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
ID: 12346397
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

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.

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
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…

776 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