|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
[function LOF] Fails after WordPad saving(with tags and so on...) of a .rtf file into a String variable. Like this: myVar = "{\rtf1\ansi\ansicpg1252\deff0\deflang1040\def..." ---------------- When I try to read a .rtf file previously saved by 'MS WordPad' the LOF instruction does fail. Note: 'MS WordPad' adds at the very bottom of the document a " " char that I think it "cheats" the LOF instruction. 'MS Word' adds no " " char instead, and all goes regular. Here my code: Dim mytxt as String Dim fnum As Integer fnum = FreeFile Open "C:\myfolder\mytest.rtf" For Input As fnum mytxt = Input(LOF(CLng(fnum)), #fnum) Close fnum ------------------- Also, I tried with the 'While Not EOF' instruction, but things go worse, bacause it cuts the first 3 chars of each line. Here my code: Dim mytxt as String Dim mytxtTEMP as String Dim fnum As Integer fnum = FreeFile Open "C:\myfolder\mytest.rtf" For Input As fnum While Not EOF(fnum) Line Input #fnum, mytxtTEMP mytxt = mytxt & mytxtTEMP Wend Close fnum --------------------------------- How can I safely read a .rtf file ? (I need to load the content into a String variable) ----------------------------------
Show quote
Hide quote
"andyIT" <and***@inwind.it> wrote in message Take a look at thisnews:43dd73eb.3019184@aioe.cjb.net... > > I need to load the whole textual content > (with tags and so on...) > of a .rtf file into a String variable. > > Like this: > myVar = "{\rtf1\ansi\ansicpg1252\deff0\deflang1040\def..." > > ---------------- > > > When I try to read a .rtf file > previously saved by 'MS WordPad' > the LOF instruction does fail. > http://support.microsoft.com/kb/142246/en-us Dmitriy
Show quote
Hide quote
"andyIT" <and***@inwind.it> wrote in message Why are you using CLng()? It's not breaking your code, but there's no point news:43dd73eb.3019184@aioe.cjb.net... > Dim mytxt as String > Dim fnum As Integer > > fnum = FreeFile > > > Open "C:\myfolder\mytest.rtf" For Input As fnum > > mytxt = Input(LOF(CLng(fnum)), #fnum) > > Close fnum in doing it. You are right, initially I thought it was failing
because fnum could have been a Long variable. I was desperately trying all the solutions... > I need to load the whole textual content This code will do what you want...> (with tags and so on...) > of a .rtf file into a String variable. > > Like this: > myVar = "{\rtf1\ansi\ansicpg1252\deff0\deflang1040\def..." > > When I try to read a .rtf file > previously saved by 'MS WordPad' > the LOF instruction does fail. Dim mytxt As String Dim fnum As Integer fnum = FreeFile Open "C:\myfolder\mytest.rtf" For Binary As fnum mytxt = Space(LOF(fnum)) Get fnum, , mytxt Close fnum I have a question for you though... Why are you doing this? Is the ultimate aim to put the text loaded into the 'mytxt' variable into a RichTextBox? If so, why not simply load the file directly into the RichTextBox like this... RichTextBox1.LoadFile "C:\myfolder\mytest.rtf" If you still need the file stored in a variable, you can load it up from the RichTextBox itself like this... mytxt = RichTextBox1.TextRTF Rick Yes, I've read the previous post and I used the Binary approch,
I did: Open "C:\myfolder\mytest.rtf" For Binary Access Read As fnum txt = Input(LOF(fnum), #fnum) Close fnum 1) Is your Get more suitable then Input? 2) Is Binary faster then Output? 3) To save I go with: Open "C:\myfolder\mytest.rtf" For Output As fnum Print #fnum, txt Close fnum is: Open "C:\myfolder\mytest.rtf" For Binary Access Write As fnum Put #fnum, , txt & stringNewAddition & stringHeaderClosing Close fnum faster? 4) I need to perform some parsing, so I need the tags. I'm trying to write some rtf formatted text into a .rtf file, without using the Richtx32.ocx control, because I know it has W98 and WXP versioning problems. I mix a preexisting .rtf file with some rtf text that my app prepares. I'm using the RTF Specs to prepare the text. Do you know any way (in example by code) to manage .rtf text, without using the Richtx32.ocx control ? I mean like some .bas module available from many VB developers' sites that can fully replace the ComDlg32.ocx file to show the common dialgos windows? Show quoteHide quote >> I need to load the whole textual content >> (with tags and so on...) >> of a .rtf file into a String variable. >> >> Like this: >> myVar = "{\rtf1\ansi\ansicpg1252\deff0\deflang1040\def..." >> >> When I try to read a .rtf file >> previously saved by 'MS WordPad' >> the LOF instruction does fail. > >This code will do what you want... > > Dim mytxt As String > Dim fnum As Integer > fnum = FreeFile > Open "C:\myfolder\mytest.rtf" For Binary As fnum > mytxt = Space(LOF(fnum)) > Get fnum, , mytxt > Close fnum > >I have a question for you though... Why are you doing this? Is the ultimate >aim to put the text loaded into the 'mytxt' variable into a RichTextBox? If >so, why not simply load the file directly into the RichTextBox like this... > > RichTextBox1.LoadFile "C:\myfolder\mytest.rtf" > >If you still need the file stored in a variable, you can load it up from the >RichTextBox itself like this... > > mytxt = RichTextBox1.TextRTF > >Rick > > On Tue, 31 Jan 2006 01:25:27 GMT, And***@inwind.it (AndyIT) wrote:
>Yes, I've read the previous post and I used the Binary approch, Input should fail on Chr$(26)>I did: > >Open "C:\myfolder\mytest.rtf" For Binary Access Read As fnum > txt = Input(LOF(fnum), #fnum) >Close fnum > >1) >Is your Get more suitable then Input? - much safer to use Get >2) They are different things, when you open a file for Output you zap its>Is Binary faster then Output? length which definitely takes time - but if you want to zap its length, then Output is sensible >3) You are adding an extra CrLf>To save I go with: > > Open "C:\myfolder\mytest.rtf" For Output As fnum > Print #fnum, txt > Close fnum - Print# fnum, Txt ; <--- note the semi colon >is: That will be faster, but if the data written is shorter than the> > Open "C:\myfolder\mytest.rtf" For Binary Access Write As fnum > > Put #fnum, , txt & stringNewAddition & stringHeaderClosing > Close fnum > >faster? length of the existing file you will have garbage left over You might want to look at 'Append' Show quoteHide quote > Use the GetOpenFileName API to replace that horrible OCX>4) >I need to perform some parsing, so I need the tags. >I'm trying to write some rtf formatted text into a .rtf file, >without using the Richtx32.ocx control, >because I know it has W98 and WXP versioning problems. >I mix a preexisting .rtf file with some rtf text that my app prepares. >I'm using the RTF Specs to prepare the text. >Do you know any way (in example by code) to manage .rtf text, >without using the Richtx32.ocx control ? >I mean like some .bas module available from many VB developers' sites >that can fully replace the ComDlg32.ocx file to show the >common dialgos windows? For an example get the downloadable API Guide (packed with examples) from http://www.mentalis.org/agnet/ You can also find an example at: http://vbnet.mvps.org/ Look for Randy Birch's stuff "J French" <erew***@nowhere.uk> wrote in message ??? vbnet.mvps.org IS Randy Birch's stuff. Not much "looking" required....news:43df53c6.266103867@news.btopenworld.com... > You can also find an example at: > > http://vbnet.mvps.org/ > > Look for Randy Birch's stuff On Tue, 31 Jan 2006 17:01:51 -0500, "Jeff Johnson [MVP: VB]"
<i.get@enough.spam> wrote: > Oops>"J French" <erew***@nowhere.uk> wrote in message >news:43df53c6.266103867@news.btopenworld.com... > >> You can also find an example at: >> >> http://vbnet.mvps.org/ >> >> Look for Randy Birch's stuff >??? vbnet.mvps.org IS Randy Birch's stuff. Not much "looking" required.... I was thinking about his old site at http://www.mvps.org/
How to best resize a form?
Using Control Array in User Control Why sending email programmatically must be so complicated? VB 2005 Express..NOT OT...really! File Copy Without Win Buffering VB6---.NET Proper way to resize a Form Why Randomize() won't work? Problems with vbCtrlMask Passing data from a dll to the main VB program |
|||||||||||||||||||||||