-
File to treeview
I'm trying to import files with a strange format into a treeview. Here is a look at the file format:
EZ Keys Instant Phrase File
0.90c Beta Test
Words+ File
Conversation
.Control
..Please wait until I finish what I'm trying to say.
..Would you mind if I talk while you're interrupting?
..Excuse me. May I say something?
..Please let me finish.
..I have something to say about that.
.Agreement
..That's true
..I agree with that
..You're right about that
..Right on!
..I think that's correct
.Disagreement
..I don't agree with that
..No way!
..That's not true
..You're wrong about that
.Greetings
..New person
...Hello. How are you?
...I'm fine, thanks.
...I'm very pleased to meet you
...I'm doing well, thank you.
..Someone I know
...Hi. How have you been?
...What have you been up to?
...I'm fine, thanks.
...I'm doing well, thank you.
...Yo, bro. Whussup!
...What's happening?
...How have you been?
.Closings
..New person
...It's been a pleasure meeting you
...I hope to see you again
...I'm so glad I got to meet you
..Someone I know
...Goodbye!
...So long!
...See you later!
.Opinions
..What did you think about that?
..What did he or she think about that?
..You know what I think?
..I think that's OK.
..I think that's good.
..I don't think that's right.
..I think that's bad.
.Social
..Weekend
...Your weekend
....Did you have a good weekend?
....How was your weekend?
....What did you do on the weekend?
...My weekend
....I had a great weekend.
....I had a lousy weekend.
....I went somewhere special on the weekend.
...Next weekend
....What are you doing next weekend?
....I have plans for next weekend.
....I'm going somewhere special next weekend.
.Subject
..Let's change the subject.
..I don't want to talk about that right now.
..Please don't change the subject.
..It's a touch subject.
.Talk
..Openers
...I'd like to talk to you about something.
...Can we talk?
...I have something to say about that.
...We need to talk.
...I really need to talk with you.
.Questions about you
..Name, age, etc.
...What is your name?
...How old are you?
..Home, family
...Do you have any brothers and sisters?
...Where do you live?
..School
...What grade are you in?
...Where do you go to school?
...Who is your favorite teacher?
..Work
...Do you like that kind of work?
...How long have you been doing that?
...Where do you work?
Responses
.Absolutely not
.Certainly
.I'm sorry
.Not!
.No, thank you
.Thank you
.Thank you very much
.Yes, please
Exclamations
.Buzz off!
.Cowabunga, dude!
.Don't have a cow, man
.Get outa here!
.Good grief!
.Leave me alone!
Insults
.Integrity
..I wouldn't trust that person.
..What a slime!
..That person is not very honest.
.Intelligence
..If brains were gunpowder, you wouldn't have enough to blow your nose.
..If you had a brain, it would be like a BB in a boxcar.
.Looks
..I've seen prettier faces on alligators.
..Someone must have hit you with an ugly stick.
.Manners
..What a slob!
..I've seen pigs with better manners.
Interests
.Music
..I like to listen to music.
..I enjoy almost all kind of music.
.Sports
..General sports
...Do you like any kinds of sports?
...I like a lot of sports.
..Basketball
...Who is your favorite basketball team?
...Who is your favorite basketball player?
..Football
Knowing
.I'm not sure I want to know.
.Do I need to know that?
.How do you know that's true?
Likes and dislikes
.Likes
..Food
...Breads
....I like most kinds of bread.
....I like biscuits.
....I like good yeast rolls.
....I like toasted bagels.
...Candy
....I really like chocolate.
...I like pizza.
..Things
...I always liked that.
..People
...I like him.
...I like her.
...I like them.
...I always like him.
...I always like her.
...I always like them.
..Places
...I like that place.
...I always liked that place.
...I like to go there.
...I wish I could live there.
.Dislikes
..Food
...I don't like onions.
...I don't like mayonnaise.
..Things
...I never did like that.
..People
...I don't like him.
...I don't like her.
...I don't like them.
...I never liked him.
...I never liked her.
...I never liked them.
..Places
...I don't like that place.
...I never liked that place.
...I don't like to go there.
...I wouldn't want to live there.
This is
.This is fun!
.This is really boring.
.This is interesting.
.This is pretty bad.
.This is really bad.
.This is fantastic!
Here is the code I wrote:
Code:
Imports System.IO
Public Class Import
Public Function ImportEZK(ByVal Folder As String, ByRef Tree As TreeNodeCollection)
Directory.SetCurrentDirectory(Folder)
Dim Files As String()
Files = Directory.GetFiles(Folder, "*.phr")
For f As Byte = 0 To Files.GetUpperBound(0)
Tree.Add(Files(f).Substring(Files(f).LastIndexOf("\") + 1, Files(f).Length _
- Files(f).LastIndexOf("\") - 5))
Dim Lines As ArrayList = FileProcessing.GetFile(Files(f))
MakeTree(Tree(f), Lines.ToArray(GetType(String)), 3)
Next
End Function
Private Sub MakeTree(ByRef MyTreeNode As TreeNode, ByVal Lines As String(), ByVal LineNum As Integer, _
Optional ByVal Level As Integer = 0)
If LineNum > Lines.GetUpperBound(0) Then Exit Sub
Dim Cntr As Integer = 0
Dim Line As String = Lines(LineNum)
Dim c As Char = Line.Substring(Cntr, 1)
Do While c = "."
Cntr += 1
c = Line.Substring(Cntr, 1)
Loop
Select Case Cntr
Case Is < Level
Dim NewNode As TreeNode = MyTreeNode, x As Integer
For x = 1 To Level - Cntr
NewNode = NewNode.Parent
Next
NewNode.Nodes.Add(Line.Substring(Cntr, Line.Length - Cntr))
MakeTree(NewNode, Lines, LineNum + 1, Level - x)
Case Level
MyTreeNode.Nodes.Add(Line.Substring(Cntr, Line.Length - Cntr))
MakeTree(MyTreeNode, Lines, LineNum + 1, Level)
Case Level + 1
MyTreeNode.Nodes(MyTreeNode.Nodes.Count - 1).Nodes.Add(Line.Substring(Cntr, Line.Length - Cntr))
MakeTree(MyTreeNode.Nodes(MyTreeNode.Nodes.Count - 1), Lines, LineNum + 1, Level + 1)
End Select
End Sub
End Class
Two problems:
First, after it gets to the lower levels, it doesn't go back to the upper levels (Case Is < Level).
Second, it duplicates every file entry in reverse order, strange.
Like this:
CARS
FOOD
GENERAL
...
...
...
GENERAL
FOOD
CARS
I would appreciate any help.
Thanks!
-