Text File with Group (Section) Tags

  • Follow


I want to create a text file format for a series of text files where "each" 
file will be divided into sections.   An example of a how the file might be 
sectioned is:

[Name]

[Address]

[Key Info]

[Remarks]

I plan to write VB code to find and then read /write each section contents. 
Each section contents will ultimately be displayed in its own textbox.

I have never used XML so not sure whether using it is a "better option" 
since I want to keep the files as  *.txt files?

Any feedback appreciated.






0
Reply David 12/18/2009 3:42:58 PM

"David" <dw85745NOT@earthlink.net> wrote in message
news:OMSXHj$fKHA.1652@TK2MSFTNGP05.phx.gbl...
> I want to create a text file format for a series of text files where
"each"
> file will be divided into sections.   An example of a how the file might
be
> sectioned is:
>
> [Name]
>
> [Address]
>
> [Key Info]
>
> [Remarks]
>
> I plan to write VB code to find and then read /write each section
contents.
> Each section contents will ultimately be displayed in its own textbox.
>
> I have never used XML so not sure whether using it is a "better option"
> since I want to keep the files as  *.txt files?
>

You can do pretty much anything you want to.
You could store the information as a comma-delimited file
   Name, Address, Key Info, Remarks
You could store it as fixed-lengths blocks, something along the lines of an
xBase file.
And you could use XML, but unless you have some particular need to share
this data with other applications, or need the extra extensions (in
datatypes, presentations, ...) XML can provide, XML is likely over-kill.

Then you need to address how and when you plan to accesss this information.

There are a myriad of opportunities, each with its own advantages and
disadvantages - all determined purely by YOUR problem domain.

-ralph



0
Reply Ralph 12/18/2009 4:17:39 PM


>I want to create a text file format for a series of text files where "each" 
>file will be divided into sections.   An example of a how the file might be 
>sectioned is:
>
> [Name]
>
> [Address]
>
> [Key Info]
>
> [Remarks]
>
> I plan to write VB code to find and then read /write each section 
> contents. Each section contents will ultimately be displayed in its own 
> textbox.
>
> I have never used XML so not sure whether using it is a "better option" 
> since I want to keep the files as  *.txt files?
>
> Any feedback appreciated.

If you go with the file structure you showed, and if your TextBoxes are in a 
Control Array starting at an Index value of 1, not zero, then this could 
could be used to distribute the sections of your file into the individual 
TextBoxes...

Sub SplitFile()
  Dim X As Long, FileNum As Long
  Dim TotalFile As String, Sections() As String
  FileNum = FreeFile
  Open "C:\Temp\NewText.txt" For Binary As #FileNum
    TotalFile = Space(LOF(FileNum))
    Get #FileNum, , TotalFile
  Close #FileNum
  Do While InStr(TotalFile, vbCrLf & vbCrLf & "[")
    TotalFile = Replace(TotalFile, vbCrLf & vbCrLf & "[", vbCrLf & "[")
  Loop
  Sections = Split(TotalFile, "]" & vbCrLf)
  For X = 1 To UBound(Sections)
    Form1.Text1(X) = Trim(Split(Sections(X), vbCrLf & "[")(0))
  Next
End Sub

-- 
Rick (MVP - Excel) 

0
Reply Rick 12/18/2009 4:38:32 PM

Thanks for response Ralph.

I want to keep the data in a *.txt file for easy editing (Notepad, etc.).
However the group of files will be brought into a VB program for ease
of displaying each file.  What I had in mind was a VB program something 
similiar to "AllAPI" for displaying the information.


"Ralph" <nt_consulting64@yahoo.com> wrote in message 
news:O4A9D4$fKHA.2184@TK2MSFTNGP04.phx.gbl...
>
> "David" <dw85745NOT@earthlink.net> wrote in message
> news:OMSXHj$fKHA.1652@TK2MSFTNGP05.phx.gbl...
>> I want to create a text file format for a series of text files where
> "each"
>> file will be divided into sections.   An example of a how the file might
> be
>> sectioned is:
>>
>> [Name]
>>
>> [Address]
>>
>> [Key Info]
>>
>> [Remarks]
>>
>> I plan to write VB code to find and then read /write each section
> contents.
>> Each section contents will ultimately be displayed in its own textbox.
>>
>> I have never used XML so not sure whether using it is a "better option"
>> since I want to keep the files as  *.txt files?
>>
>
> You can do pretty much anything you want to.
> You could store the information as a comma-delimited file
>   Name, Address, Key Info, Remarks
> You could store it as fixed-lengths blocks, something along the lines of 
> an
> xBase file.
> And you could use XML, but unless you have some particular need to share
> this data with other applications, or need the extra extensions (in
> datatypes, presentations, ...) XML can provide, XML is likely over-kill.
>
> Then you need to address how and when you plan to accesss this 
> information.
>
> There are a myriad of opportunities, each with its own advantages and
> disadvantages - all determined purely by YOUR problem domain.
>
> -ralph
>
>
> 


0
Reply David 12/18/2009 4:42:21 PM

Thanks Rick for the "heads up" on the control array usage.
Also appreciate the code, will say me a little work.

David


"Rick Rothstein" <rick.newsNO.SPAM@NO.SPAMverizon.net> wrote in message 
news:efylDCAgKHA.2596@TK2MSFTNGP04.phx.gbl...
> >I want to create a text file format for a series of text files where 
> >"each" file will be divided into sections.   An example of a how the file 
> >might be sectioned is:
>>
>> [Name]
>>
>> [Address]
>>
>> [Key Info]
>>
>> [Remarks]
>>
>> I plan to write VB code to find and then read /write each section 
>> contents. Each section contents will ultimately be displayed in its own 
>> textbox.
>>
>> I have never used XML so not sure whether using it is a "better option" 
>> since I want to keep the files as  *.txt files?
>>
>> Any feedback appreciated.
>
> If you go with the file structure you showed, and if your TextBoxes are in 
> a Control Array starting at an Index value of 1, not zero, then this could 
> could be used to distribute the sections of your file into the individual 
> TextBoxes...
>
> Sub SplitFile()
>  Dim X As Long, FileNum As Long
>  Dim TotalFile As String, Sections() As String
>  FileNum = FreeFile
>  Open "C:\Temp\NewText.txt" For Binary As #FileNum
>    TotalFile = Space(LOF(FileNum))
>    Get #FileNum, , TotalFile
>  Close #FileNum
>  Do While InStr(TotalFile, vbCrLf & vbCrLf & "[")
>    TotalFile = Replace(TotalFile, vbCrLf & vbCrLf & "[", vbCrLf & "[")
>  Loop
>  Sections = Split(TotalFile, "]" & vbCrLf)
>  For X = 1 To UBound(Sections)
>    Form1.Text1(X) = Trim(Split(Sections(X), vbCrLf & "[")(0))
>  Next
> End Sub
>
> -- 
> Rick (MVP - Excel) 


0
Reply David 12/18/2009 5:19:11 PM

"David" <dw85745NOT@earthlink.net> wrote:
>I want to create a text file format for a series of text files where "each" 
>file will be divided into sections.   An example of a how the file might be 
>sectioned is:
>[Name]
>[Address]

Separate the fields within a record with a delimiter such as a tab and then 
separate the records with a return/line feed character (vbCRLF).  A simple 
statement such as this will do the trick:

print #1, nayme$ & vbtab & address$ & vbtab & phone$

Easy, no?

0
Reply sfdavidkaye2 12/18/2009 6:08:15 PM

"David" <dw85745NOT@earthlink.net> wrote:

>I want to keep the data in a *.txt file for easy editing (Notepad, etc.).
>However the group of files will be brought into a VB program for ease
>of displaying each file.  What I had in mind was a VB program something 
>similiar to "AllAPI" for displaying the information.

Huh?  For a flat text file you can do this:

open "myfile" for input as #1
line input #1, a$
b=split(a$,vbtab)

So then you have b(1) = the name, b(2) is the address, b(3) is the phone, and 
so forth.  

Supersimple.
0
Reply sfdavidkaye2 12/18/2009 6:10:40 PM

David explained on 12/18/2009 :
> I want to create a text file format for a series of text files where "each" 
> file will be divided into sections.   An example of a how the file might be 
> sectioned is:
>
> [Name]
>
> [Address]
>
> [Key Info]
>
> [Remarks]
>
> I plan to write VB code to find and then read /write each section contents. 
> Each section contents will ultimately be displayed in its own textbox.
>
> I have never used XML so not sure whether using it is a "better option" since 
> I want to keep the files as  *.txt files?
>
> Any feedback appreciated.

Sounds suspiciously like an INI file?  You might consider that, given 
the extensive support for those.  See http://vb.mvps.org/samples/kpIni 
for a full-featured wrapper.

-- 
..NET: It's About Trust!
http://vfred.mvps.org


0
Reply Karl 12/18/2009 6:25:42 PM

"David" <dw85745NOT@earthlink.net> wrote:

>I want to keep the data in a *.txt file for easy editing (Notepad, etc.).

Who is going to be doing the editing?   If end users then you'll
likely want a GUI giving them structured fields, etc.

Tony
-- 
Tony Toews, Microsoft Access MVP
Tony's Main MS Access pages - http://www.granite.ab.ca/accsmstr.htm
Tony's Microsoft Access Blog - http://msmvps.com/blogs/access/
For a convenient utility to keep your users FEs and other files 
  updated see http://www.autofeupdater.com/
Granite Fleet Manager http://www.granitefleet.com/
0
Reply Tony 12/18/2009 9:21:31 PM

8 Replies
240 Views

(page loaded in 0.228 seconds)

8/2/2012 2:20:21 PM


Reply: