PDA

View Full Version : Reading a file with colour



Maurice
05-13-2007, 09:01 AM
Help!!
I would like to be able to read a file which has different coloured texts using the methods for a sequential file. When I tried to do this using a rich format file it produces gobbledegook ( not too surprising perhaps).
Is there a way to do this without involving word? Forgive me if it is a daft question. Maurice

mdmackillop
05-13-2007, 09:58 AM
Can you post a sample and show exactly what you're after?

Zephid15
05-15-2007, 07:09 AM
to quote the great Ron Burgundy : "that doesnt make any sense"

Maurice
05-15-2007, 01:30 PM
The coding below works fine when FileName is a *.txt file and the string returned by Line Input (in Longtxt) makes sense. I want to make the file "FileName" easier to interpret by the user by using different coloured texts as required without causing havoc. The only way I could think of was to use a Rich Text File (which supports coloured text) instead of a Plain Text File. In this case, the coding reads the line in the file without complaint, but I can't interpret the result.

Dim FileNum as Byte,FileName As String, Longtxt As String

FileNum=FreeFile
Open FileName For Input As FileNum

Do While Not EOF(FileNum)
Line Input #FileNum, Longtxt

Loop
Close FileNum

I'm sorry I was so vague before, I hope this clarifies the problem.

Thanks Maurice

mdmackillop
05-16-2007, 12:11 PM
I think you'll need to use Word. If you open your rtf from Notepad, you'll see what you're trying to process.

Maurice
05-16-2007, 01:27 PM
I was hoping to avoid Word altogether because I can't see how I would use it within the VBA context. I know the general nature of the file contents but it can vary a little. There is nothing which is not text, the only addition being the colour. Is there no conversion routine which will change the line of text from the .rtf file to plain text? Could I not do it one character at a time? I'm desperate here! Thanks anyway.

mdmackillop
05-16-2007, 01:31 PM
There are some third party conversion tools, but I'm not sure that would be easier.
Can you post a sample file and explain what you're looking to extract?

Maurice
05-16-2007, 01:31 PM
I think I may have cottened on to what you mean about opening from notepad, I have been known to be a bit slow on occasions! I will try that and see if it helps. Thanks again.

Maurice
05-19-2007, 02:38 PM
Thanks for the suggestion of reading the file with Notepad which has been a revelation to me. It is composed mainly of Font and Language descriptors & others that I don't recognise, with my text interspersed. The one page (with Plain text) becomes eight pages with Rich Text. One bright spot is that the text is readable and often (but not always), preceded by \par. Another helpful feature is that any changes to format or colouring are preceded by }{ followed by the new descriptors. Unfortunately there doesn't seem to be a fixed indicator to show that the descriptors are finished and text is restarted. If I had one I could isolate the descriptors and reject them. \Charrsid is the nearest, possibly, but this is followed by 7 or 8 digits.
In the small sample below, the Texts I want to keep are:
-UsrNames;Mode=22#>>Dawn:Maurice<<
-Passwrds;Mode=23#>>dfs:moss<<
+RHS Headings-Inc;Mode=1#Sht=1,Row=1,Col=7>>Donations: Donations:Papers:Folders<<
In the above lines Dawn:Maurice is in Red
dfs:moss is in Blue
Donations: Donations is in Red and Papers:Folders is in green

\f31506\fs22\lang2057\langfe1033\cgrid\langnp2057\langfenp1033 {\rtlch\fcs1 \af31507 \ltrch\fcs0 \insrsid16139198 -UsrNames;Mode=22#}{\rtlch\fcs1 \af31507 \ltrch\fcs0 \cf6\insrsid16139198\charrsid16139198 >>Dawn:Maurice<<}{\rtlch\fcs1 \af31507
\ltrch\fcs0 \insrsid16139198
\par -Passwrds;Mode=23#}{\rtlch\fcs1 \af31507 \ltrch\fcs0 \cf17\insrsid16139198\charrsid16139198 >>dfs,moss<<}{\rtlch\fcs1 \af31507 \ltrch\fcs0 \cf17\insrsid16139198
\par }{\rtlch\fcs1 \af31507 \ltrch\fcs0 \insrsid1719723\charrsid1719723 +RHS Headings-Inc;Mode=1#Sht=1,Row=1,Col=7}{\rtlch\fcs1 \af31507 \ltrch\fcs0 \cf6\insrsid1719723\charrsid1719723 ;>>Donations: Donations:}{\rtlch\fcs1 \af31507 \ltrch\fcs0
\cf18\insrsid14623980\charrsid14623980 Papers:Folders}{\rtlch\fcs1 \af31507 \ltrch\fcs0 \cf6\insrsid1719723\charrsid1719723 <<}{\rtlch\fcs1 \af31507 \ltrch\fcs0 \cf6\insrsid16139198
\par }{\rtlch\fcs1 \af31507 \ltrch\fcs0 \cf6\insrsid14623980\charrsid1719723
\par }{\*\themedata 504b030414000600080000002100828abc13fa0000001c020000130000005b436f6e74656e7 45f54797065735d2e786d6cac91cb6ac3301045f785fe83d0b6d8
Any ideas?

Maurice
05-19-2007, 02:45 PM
Humble apologies but in several places : D became Smilie. I don't know why because I Pasted the file in. When I tried to edit it out it did not work. I am not trying to make it harder Honest! Even in this reply the colon and D WITHOUT the space became a smilie. The original was colon, no space D

lucas
05-19-2007, 02:47 PM
I was hoping to avoid Word altogether because I can't see how I would use it within the VBA context.
??

Why not open it in Word and save it as a text file.....I probably don't understand the question but....that would get rid of the formatting.

lucas
05-19-2007, 02:48 PM
attach the file to the post...go to post reply at the bottom left of the last post and when the page loads scroll down till you find manage attachments.

Maurice
05-20-2007, 12:42 PM
Thanks Lucas, I will give the Word idea a go & see. I am confusing everybody because my grasp is a bit tenuous - or did you guess.
I will report back.

lucas
05-20-2007, 12:52 PM
No problem Mauice..it's just hard to help you the way things are going.

fumei
05-20-2007, 01:15 PM
Is there a way to do this without involving word?Why are you asking this in a Word forum??

Further, one would assume you were planning to do this with VBA. If so...what application were you going to use VBA from??? Excel? Access? if so...why are you asking in a Word forum??

If you were going to use VBA from Word...then...hard to avoid using Word.

Maurice
05-21-2007, 11:33 AM
It was a file to be read by VBA but the Text - Rich Text thing seemed to be more word oriented to me and I was trying to get close to the nitty gritty of that subject. I originally thought that I could use a single file & edit out the formats but having tried Lucas's suggestion, I will keep two copies of the file - one in Word format for the colour and one derived from it in Plain Text for the VBA application. Thanks again everyone, I am thinking of changing my user name to Bad Penny in future! :thumb

lucas
05-21-2007, 11:39 AM
Maurice, If you've gone as far as you wish on this please mark your thread solved using the thread tools at the top of the page. You can always post followup questions here even if it's marked solved.

fumei
05-21-2007, 10:03 PM
It was a file to be read by VBA

Hmmm. VBA. Well, guess what? VBA is used by a VBA-compliant application...like Word. There is no VBA as stand-alone. You must use a VBA application (like Word) to use VBA.

So the question is again...what application are you trying to do this in? Word? It would seem so, since you posted in the Word forum. So I still do not understand that you wish to avoid Word. Ok, then - again - what ARE you using to run thhe VBA?