|
-
Sep 2nd, 2000, 12:26 AM
#1
Thread Starter
Member
I want to break down contract text files into a multi-dimensional array, placing each section, point and sub-points into hierarchical elements.
File name: contract.txt
The file outline is typical for union contracts. It is divided into sections, which are divided into hierarchical sub-parts with progressive indentation to possibly the seventh level. Here’s an example showing only one element in each level of the hierarchy. Except for the section number, these naming conventions are typical throughout the file.
Section One
Section One, I
Section One, I.A
Section One, I.A.1
Section One, I.A.1.a
Section One, I.A.1.a.1}
Section One, I.A.1.a.1}a}
A database would be easier, but for reasons I won’t go into, a database will not work for what we want. I have searched the web for weeks, reading everything I found about arrays, but I haven’t seen anything like this.
Can someone please help me? I need to know where I can find a book, articles or a tutorial on this. Better yet, can someone please write me a section of example code? I’m a newbie, but I catch on quick! If this can be done, and I’m sure it can, I can do it! This will eliminate much work and possibly even get me a much-needed bonus. Drinks, anyone?
Another thing, I know this program will be slow because of the size of the file and the memory required, but I have 256k and the program is to be used in-house, so fast code and speed are something we can live without if we have to.
Please give me a suggestion on how to best do this and I’ll get back to you. I’m running Visual Studio 6. Don’t you just LOVE Visual Basic?!!!!
Thanks!
Wendy
-
Sep 2nd, 2000, 12:52 AM
#2
I'll try to give you a hand with this, but I'm not quite able to make the connection between the multi-dimensional array and the hierarchical nature of your file. Maybe it's not a multi-dimensional array but a series of related arrays (to simulate a set of tables in a DB) that you need? I guess the main question is, how do you envision the application accessing this data, and how do you envision the storage for this data? If you could provide a little more clarification, I could take a crack at it and earn a JD and coke!
"It's cold gin time again ..."
Check out my website here.
-
Sep 2nd, 2000, 01:14 AM
#3
Thread Starter
Member
Thanks!
I very well may be confused on needing a multi-dimensional array. I'm not familar with the one you mentioned.
We had planned on dumping and storing the array in a text file. The reason we need to use an array, instead of a database, is that we want the capability to view and edit ONLY a SMALL SECTION of the file, yet still have the capability of viewing the ENTIRE file as a whole. There are other reasons, but I hope this gives you an idea.
I guess what we are really trying to do is have a text file with a collapsable and expandable outline. An array seemed like the best way to go to me. I may be wrong.
Thanks again!
Wendy
-
Sep 2nd, 2000, 01:56 AM
#4
There is a way but it's kind of complicated.
From what I understand you want some way to store the data like in a treeview control (without the control of course).
My suggestion is to create a UDT which looks like this:
Code:
Type ContractSection
Contents As String
ID As String
Parent As String
End Type
Dim Contract() As ContractSection
Now you can fill the array with the data.
For example, if one of the sections is called "A. Blah", then the variables will contain:
Contents = "The contents of the section"
ID = "A. Blah"
Parent = "NoParent"
And let's say there is a sub-section to "A. Blah" which is called "A. (1). Yadda" then the variables will contain:
Contents = "Again, the contents of the section/sub-section
ID = "A. (1). Yadda"
Parent = "A. Blah"
This way you can know that this sub-section belongs to "A. Blah".
The order of sections doesn't matter since you will always be able to sort the list in a hierarchial order.
Any questions or suggestions, I'll be happy to help.
-
Sep 2nd, 2000, 08:02 AM
#5
Sc0rp has a good suggestion here! In conjunction with what he suggests, you could actually use the treeview control to visually represent the outline, and when the user clicks on a node of the tree, show the related text in a textbox for viewing or editing. Do you want to proceed along these lines?
BTW, is your text file organized in a way such that there is an identifying section number or sub-section ID on each record, and does each section and sub-section have text?
"It's cold gin time again ..."
Check out my website here.
-
Sep 2nd, 2000, 09:55 AM
#6
_______
<?>
Wendy
I can do this but it is read only at the moment. Do you want to make changes or just have the ability to read the data at Section (Whatever)
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
-
Sep 2nd, 2000, 11:36 AM
#7
Thread Starter
Member
Good Morning to BruceG and ScOrp! And thanks for the responses.
ScOrp has identified exactly what I think I need but I’m not sure if I need a multi-dimensional array or a series of related relays. I’m trying to learn about these in a couple of books right now. If anyone already knows this, please post the answer.
Let’s reduce this project to a much smaller scale and I believe it will be easier to understand and accomplish.
Firstly, Let’s change our file from a large union contract to a much smaller speech outline with the same outlining conventions. (If we can make this work on a small file, it will then be easier to make it work on a large file.)
A speech outline is broken into five “Sections.” Sections of the speech are “Title,” “Introduction,” “Thesis,” “Body” (or main presentation), and “Conclusion.” Each section has a varying number of sub-parts. The following example will show how the “Body” section might look: (Ignore the leading periods. They are to make it display as indented. I don’t know any other way to do it in this forum.)
Title:
Introduction:
Thesis:
Body: (It, and all sub-points are indexed simply as “Body”)
….I. Major point (It, and all sub-points are indexed as “Body.I”)
….II. Major point (It, and all sub-points are indexed as “Body.II”)
……..A. Main point (It, and all sub-points are indexed as “Body.II.A”)
……..B. Main point (It, and all sub-points are indexed as “Body.II.B”)
………….1. Minor point (It, and all sub-points are indexed as “Body.II.B.1”)
………….2. Minor point (It, and all sub-points are indexed as “Body.II.B.2”)
……………..a. Minor sub-point (It, and all sub-points are indexed as “Body.II.B.2.a”)
……………..b. Minor sub-point (It, and all sub-points are indexed as “Body.II.B.2.b”)
….III. etc.
Conclusion:
I envision each sub-point being stored or collapsed under the point just above it. In other words, double-clicking on “Body” would collapse and/or expand everything under it down to “conclusion,” which is the next point on the same level as “Body.”
When collapsed, “Body” would be the only thing that remains visible. All sub-points would be collapsed into it and would not be visible.
Similarly, double-clicking on “Body.II” would collapse and/or expand everything under it down to “Body.III,” which is the next point on the same level, etc.
I’ve actually done what I want to do on a small scale by simply cutting and pasting to multiple clipboards, but this was crude and unsuitable for large files. In that program, double-clicking on “body” would select and highlight everything down to “conclusion.”
It would then cut and paste the selected text to the clipboard. The next double-click on “body” would paste everything back.
That file was fully expanded before saving and saved as a text file. I had intended to write code that would make the file collapse down to just “sections” when it loaded. You could then have a full overview of the file and just expand the section you needed to view or edit. However, I gave up on that project because it became apparent that it was inadequate for what I wanted.
ScOrp. I envision not using a treeview because I want everything to take place in one text box. Other than that, your concept of what I want to do is correct.
To answer your specific questions, (1) every section and sub-section that appears will contain text. Actually it will BE text. (2) Every section and sub-section will effectively be indexed by following the outlining conventions. I.e. “Body.II.B.1.a,” etc.
Also, This will probably show what a newbie I am, but what does UTD stand for?
I have an appointment I have to make in a little while, so I will end this post for now. I will return later and see what’s developed.
I really appreciate you help!
There must be others out there who can help and who would benefit from this kind of code. Come on in guys and gals!
Thanks!
Wendy
-
Sep 2nd, 2000, 11:41 AM
#8
Thread Starter
Member
Hey! HeSaidJoe!
I was hoping you would jump into this.
Welcome aboard.
To answer your question, I must have the ability to edit the text when the section is expanded. I would be interested in knowing what's on your mind though.
thanks! Later.
Wendy
-
Sep 2nd, 2000, 12:15 PM
#9
Wendy
First:
UDT stands for User Defined Type. It's a way of using variable structures in different ways for different purposes. For example, the UDT I gave above:
Code:
Type ContractSection
Contents As String
ID As String
Parent As String
End Type
Then you can dim variables using your new type. Eg:
Code:
Dim Contract(5) As ContractSection
Now each item in the array has the sub-variables we declared in the UDT above. Eg:
Code:
Contract(3).Contents = "This is section 3 of the contract..."
Contract(3).ID = "III. 3rd section"
Contrcat(2).Parent = "III. 3rd section"
Etc...
I hope it clears things up a little. 
Second:
I don't think using a simple textbox is such a good idea since it's hard to separate parts in a textbox and it has very poor double-click support.
I think a treeview control without treelines and icons is the best way.
And another thing: You can store the information in a random-access file (explanation follows), which will increase the size of the original contract file a little (about 2%-3%).
Explanation:
When you store data in a random access file it's storing the data in records and fields (pretty much like a db, but without the bulky db file). It's the perfect way for this case.
-
Sep 2nd, 2000, 12:41 PM
#10
Thread Starter
Member
Thanks ScOrp,
I have limited knowledge about part of what you are saying, but it sounds good.
I'm off to an appointment and will be back on this tonight.
Wendy
-
Sep 2nd, 2000, 04:49 PM
#11
if i got the requirements right, then XML coud provide a good solution. as far as i understood XML, it was just designed to would you need. have a look on the MS homepage, if i remember right, there are XML related tools available there.
best regards
Alexander
-
Sep 2nd, 2000, 09:27 PM
#12
Instead of using a UDT I would suggest making a simple class with properties for each of the levels.
Then create a collection of this class. A collection might be a little bit slower then using an array of a UDT variable but it has a lot of advantages as well.
First of all you can use a key value for each item. You can loop through the collection with a For Each loop and it's much easier (and faster) to remove an item if needed.
-
Sep 3rd, 2000, 03:53 PM
#13
_______
<?>
Hi Wendy,
Was out of town for wedding...have one little glitch to fix so I can make it read/write and I think it's fixable..if I get it worked out, then I will post the code for you to play with.
Wayne
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
-
Sep 3rd, 2000, 04:51 PM
#14
Thread Starter
Member
Thanks guys! All of you!
I'm back. Took me several hours longer than I expected though.
I've done some research and reading on the different ways that have been suggested to do this. To be honest, I don't have enough experience to know which is the best way. I sure trust you guys, though. I've seen your knowledge put to good use in many, many posts. I must have read a thousand or so the last couple of weeks. To be honest, I've learned more from this forum than I will ever learn in class!
Back to the subject.
Sascha: I knew nothing about XML before today. I found quite a bit on it and it looks really good, but I'm not sure about it for this project. I think I need to stick with something I know a little about. (However, I found a lot of good info in the MSDN Library on XML.) Thanks for the suggestion.
Joacim: I think you're right. In an update somewhere down the road, I will probably develop and use a class collection. I've never created a collection before but after researching it yesterday, you can be sure that I will soon. Thanks for suggesting it.
HeSaidJoe: I'm going to keep reading until I see your code and then build on it. Who knows, I might even be able to improve it! <Laugh! That was a joke!>
To all: Hang in there with me. I'm trying to make daily classes, work evenings, study nights, find time for this and still have a life. Right now, this has my interest. I'm struggling to sleep because I can't get this off my mind. I love it!
Later,
Wendy
-
Sep 3rd, 2000, 05:41 PM
#15
_______
[code]
'basically I load your txt file into an array and split
'it at the word "Section"...I then list the splits in a listbox
'on click in the listbox I open a text file and load it the information
'pertaining to that particualar split
'when you close that file it will ask you to save changes and you
'reply yes. then you click on the Rewrite feature you replace the piece
'of code you just adjusted and then rejoin the array into a string
'and write it to your file.
'I also back up the contacts file to sparecopy before adjusting
'if you screw up you can reload your original version
'Wendy...if you want I can email you a zipped copy of the app
'so you won't have to cut and paste and build the basic app
'for testing...but you will have to let me know real real soon as
'I am leaving tonight to go a couple of day fishing trip
'anyone wanting to improve this monstrocity..feel free to do so
'the linebreaks are showing up in the listbox but they
'do not show in the file you create for reading so it's
'no big thing..
'make a new project
'frmSelection cmdCreateArray cmdDeleteReadFile lstShowBreakdown
'cmdQuit cmdReWrite
'
'this is the content of your contacts.txt file
Section One
Jimmy is a cleaner but he makes good when he can.
Ontop of that he is the wife's brother so I
have to keep the sucker employed.
Section One, I
Who really cares?
It's all the same to me anyway
Section One, I.A
Diddle diddle it's all legal talk,
actually, mumbo jumbo,
and I can do with out the smart
and dull junkie talks
Section One, I.A.1
Henry seems to be the one to
benefit most from all of this
Section One, I.A.1.a
Carp is a fish, and this is not carp'
it is nothing but crap
Section One, I.A.1.a.1}
and if you know
would you say
and if you said
what would I know
Section One, I.A.1.a.1}a}
dreaming again are we
this is not so entertaining and
I do believe: yes, I do believe,
that the more I think, the more I am convinced
that I better shut up and get on with this .
The End
[code]
Create a bas module and put this in it:
Option Explicit
'these need to be public for access in different subs
Public myArr()
Public myIndexNum as integer
'copy and paste this code into the declarations of your standard form
Option Explicit
Private Sub cmdCreateArray_Click()
Dim sFile As String, sSpareCopy As String
sFile = "c:\my documents\contracts.txt"
sSpareCopy = "C:\my documents\sparecopy.txt"
'make a backup copy of your file
'first kill the old version if existing
'does file exist using fso
Dim fs As Object
Set fs = CreateObject("Scripting.FileSystemObject")
If fs.fileexists(sSpareCopy) = True Then
Kill (sSpareCopy)
Else
'do nothing, file does not exitst
End If
Set fs = Nothing
'now make spare copy
Dim SourcePath As String, DestPath As String
SourcePath = sFile
DestPath = "c:\my documents\sparecopy.txt"
FileCopy SourcePath, DestPath
Dim intNum As Integer
intNum = FreeFile
Dim var1 As String
Dim sResult As Variant
Open sFile For Input As intNum
'read the complete file into a string variable
var1 = StrConv(InputB(LOF(intNum), intNum), vbUnicode)
Close intNum
Dim i As Integer
'use the split function to split the string
'into sections using the word section as the split pos
sResult = Split(var1, "Section")
'read the split into the public array and display
'the splits in a list box for future access
'
'here we load the split elements or the new array
'Section one/Section 1:a and on and on
For i = 0 To UBound(sResult)
ReDim Preserve myArr(i)
myArr(i) = RTrim(sResult(i))
lstShowBreakdown.AddItem myArr(i)
Next i
End Sub
Private Sub cmdDeleteReadFile_Click()
'if confidential, once done reading kill the file to avoid clutter
'if you forget to kill it or don't want to, the next time
'you use it, it will overwrite anyway (Output mode)
Kill ("C:\my documents\myfile2.txt")
End Sub
Private Sub cmdQuit_Click()
'make sure you remember to reAssamble your array and save
'the complete file
Dim msg
msg = "If you have made changes you must run ReWrite" & vbCrLf
msg = msg & " If you don't your file will be corrupt" & vbCrLf
msg = msg & vbCrLf
msg = msg & "If in doubt, run it anyway."
Dim Response
Response = MsgBox(msg, vbYesNo, "Yes to quit, No to go back and ReWrite")
If Response = vbYes Then ' User chose Yes.
Unload Me
Else
Exit Sub ' do not unload, give user chance to reAssemble
End If
End Sub
Private Sub cmdReWrite_Click()
Dim i As Integer
Dim intNum As Integer
intNum = FreeFile
Dim yourfile As String, sFile As String
yourfile = "C:\my documents\myfile2.txt"
sFile = "c:\my documents\contracts.txt"
'get the new text for the working array segment
Open yourfile For Input As intNum
'Input #intNum, myArr(myIndexNum)
myArr(myIndexNum) = RTrim(StrConv(InputB(LOF(intNum), intNum), vbUnicode))
Close intNum
'need a variable to store the reassembled string
Dim var3 As String
'reassemble the array with the new information
'and put back the characters removed on split function
var3 = Join(myArr, "Section")
Open sFile For Output As intNum
'save the completed file back to contracts
Print #intNum, var3
Close intNum
'
'for some reason the split/join function creates an
'empty line when it does it's stuff..this function
'gets rid of the line
'
intNum = FreeFile
Dim myvar As String
sFile = "c:\my documents\contracts.txt"
'read file back into array to capture empty line
Open sFile For Input As intNum
'loop the file
Do While Not EOF(intNum)
ReDim Preserve myArr(i)
Line Input #intNum, myvar
'if the line is not an empty line copy it to array
If myvar <> "" Then
myArr(i) = myvar
i = i + 1
End If
Loop
Close intNum
'save the file after getting rid of empty line
'caused by whatever split/join function
Open sFile For Output As intNum
For i = 0 To i - 1
Print #intNum, myArr(i)
Next i
Close intNum
End Sub
Private Sub Form_Activate()
Call ThreeDForm(Form1)
End Sub
Private Sub lstShowBreakdown_Click()
'open tmp text file for reading and read
'the selected item's text into it
Dim i As Integer
Dim intNum As Integer
intNum = FreeFile
Dim yourfile As String
yourfile = "C:\my documents\myfile2.txt"
'open file and write your selection to it
Open yourfile For Output As intNum
Print #intNum, RTrim(myArr(lstShowBreakdown.ListIndex))
myIndexNum = lstShowBreakdown.ListIndex
Close intNum
'
'open the text file for viewing
Dim RetVal
RetVal = Shell("C:\WINDOWS\notepad.exe C:\my documents\myfile2.txt", 1)
End Sub
[code]
[Edited by HeSaidJoe on 09-04-2000 at 02:43 AM]
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
-
Sep 3rd, 2000, 10:26 PM
#16
Thread Starter
Member
HeSaidJoe
Yes. Please email the file to me. I appreciate your Interest and help!
I have sent you an email.
Wendy
[Edited by Wendy Jackson on 09-03-2000 at 11:31 PM]
-
Sep 4th, 2000, 01:17 AM
#17
_______
<?>
Wendy:
Sent the folder with a minor adjustment to it. After I posted the code last night I noticed that for some reason the split\join functin kept leaving a blank line after I re'inserted the array into a file...made a correction for it.
Later
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
-
Sep 4th, 2000, 08:49 AM
#18
Sorry for not replying lately... I just started highschool.
Only the second day and I'm exhausted... 
Can you update me about the progress?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|