Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 191
  • Last Modified:

Difficult Structures

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
x_terminat_or_3
Asked:
x_terminat_or_3
  • 9
  • 6
  • 3
1 Solution
 
Mikal613Commented:
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
 
x_terminat_or_3Author Commented:
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
 
Mikal613Commented:
so you need a treeview not a listview
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
x_terminat_or_3Author Commented:
who said anything about listviews or treeviews?  It needs to be loaded in a structure in memory
0
 
Mikal613Commented:
0
 
x_terminat_or_3Author Commented:
I know about classes, collections, and all that, it's just that I'm stuck and need help

0
 
Mikal613Commented:
"so I can make a tree" means  a treeview??

Can you explain what you want in depth?
0
 
x_terminat_or_3Author Commented:
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
 
Mikal613Commented:
how are you gonna show that tree in your website?
0
 
x_terminat_or_3Author Commented:
<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
 
Mikal613Commented:
0
 
x_terminat_or_3Author Commented:
So how can I implement this with my requirements?
0
 
jimbobmcgeeCommented:
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
 
x_terminat_or_3Author Commented:
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
 
jimbobmcgeeCommented:
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
 
x_terminat_or_3Author Commented:
Once connected, it's all the same; access, cvs, odbc,...

database.recordsets(r).fields(f).value
0
 
jimbobmcgeeCommented:
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
 
x_terminat_or_3Author Commented:
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 9
  • 6
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now