Format a file created by FSO.CreateTextFile?

K

Karl E. Peterson

Ed said:
Oh, please Mr. Wizard!! Point me to something better!! Then again, I
don't know if I could use it - this is for work and I'm stuck with
what I have: Office and VBA, and VB6 (I can probably find someone with
dot Fred). Then, too, I'm also stuck with what I know - which
obviously isn't much!!

Well, for this task, I'm having trouble seeing the utility of Word. I'll grant it's
convenient. I mean, there it is. But why drag the object model into it? VBA alone
can do it. (I'd personally use VB6, myself.)
Well, I did try
myText = Replace(myText, Chr(13), Chr(13) & Chr(10), 1, ,
vbBinaryCompare)
but it didn't seem to work. Bad syntax? Bad breath?

Dunno. <g> I'd have to see a sample of the raw data, but I suspect you're probably
getting hosed by the object model, not your breath. I mentioned a hex editor
before, eh? That's a way to look at your actual data. I use Cygnus (from
Softcircuits). Not sure if they offer an evaluation period. You can also dump your
strings to the Immediate window using my HexDump sample
(http://vb.mvps.org/samples/HexDump), though I'd use rather short ones - no
multimegabyte unless you're really bored.
It sure seems harder than I thought it would be! But when you're
using a screwdriver to pound nails, it's _all_ hard! <G>

Okay, *now* you're starting to hear me! <g>

So, to recap... You have:

strMsg = docIE.Body.InnerText

Now, do this:

strMsg = Replace(strMsg, vbCr, vbCrLf)
Call WriteFile(MyFilename, strMsg)

That's it! If that doesn't look right in Notepad, look at it in a Hex editor. Make
sure you're not doubling put the LFs (no 13/10/10 triplets). Or, add my HexDump.bas
module to your project, and do this:

Call HexDump(StrPtr(strMsg), 800) 'about 10 lines?

And show us the results here.
 
E

Ed from AZ

Karl:
add my HexDump.bas
module to your project, and do this:

Call HexDump(StrPtr(strMsg), 800) 'about 10 lines?

And show us the results here.

I did, using this:
strMsg = docIE.Body.InnerText
Call HexDump(StrPtr(strMsg), 800)
Unfortunately, nothing showed up in the Immediate window??

I also did this:
For x = 1 To 90
Debug.Print x & ": " & Mid(strMsg, x, 1) & " / Chr(" & Asc(Mid
(strMsg, x, 1)) & ")"
Next x

I find that the string straight from the web page has 79 characters,
then a 13 and a 10!

So I think I agree with you:
I suspect you're probably
getting hosed by the object model

I think I can use Left, Right, and Mid to capture the strings I need
and then FreeFile them out. Since my strings already contain the
13/10, they should format okay when saved as txt files. And it will
probably run much faster too!! I'll check that out and get back to
you.

Ed
 
E

Ed from AZ

Just to let y'all know:
I think I can use Left, Right, and Mid to capture the strings I need
and then FreeFile them out.  Since my strings already contain the
13/10, they should format okay when saved as txt files.  And it will
probably run much faster too!!  I'll check that out and get back to
you.

Yep!! I did it all as string manipulation. Ran like champ! text
files looked good when opened, too.

I need to clean it up greatly and modify it to work with a few other
issues, but that's just in how I place my loops.

I've got VB6, but it's the Learning Edition, so I can't compile an
exe. I can still run it from my desktop, though.

*whew!*
Thanks for all the help!!

Ed
 
K

Karl E. Peterson

Ed said:
Karl:


I did, using this:
strMsg = docIE.Body.InnerText
Call HexDump(StrPtr(strMsg), 800)
Unfortunately, nothing showed up in the Immediate window??

Nothing at all? That makes no sense. If I just add that module to a brand new Word
project, jump to the Immediate window and type:

s="abc" & vbcrlf & "cde":?hexdump(strptr(s), 16);s


I see:

=================================================================================
lpBuffer = &h2F57C64 nBytes = 16
02F57C64 0000 61 00 62 00 63 00 0D 00-0A 00 63 00 64 00 65 00 a.b.c.....c.d.e.
=================================================================================
abc
cde

Nothing showing up is *not* an option! <g>

(That "0D 00 0A 00" is the unicode equivalent of 13/10, btw.)
I also did this:
For x = 1 To 90
Debug.Print x & ": " & Mid(strMsg, x, 1) & " / Chr(" & Asc(Mid
(strMsg, x, 1)) & ")"
Next x

I find that the string straight from the web page has 79 characters,
then a 13 and a 10!

Then you're all set.
So I think I agree with you:

I think I can use Left, Right, and Mid to capture the strings I need
and then FreeFile them out.

I hope you don't mind me asking, but what's the fuss with those? Could be (lots)
more needless overhead.
Since my strings already contain the
13/10, they should format okay when saved as txt files. And it will
probably run much faster too!! I'll check that out and get back to
you.

Yep, saw that it worked. That's great! :)
 
E

Ed from AZ

Nothing at all? That makes no sense. If I just add that module to a brand new Word
project, jump to the Immediate window and type:

s="abc" & vbcrlf & "cde":?hexdump(strptr(s), 16);s

I see:

I got the same thing in the Immediate window, so the module is
working. Don't know what I had wrong.
I hope you don't mind me asking, but what's the fuss with those? Could be (lots)
more needless overhead.

I currently use InStr to find the character position I need, then Left
to get the report I want and Right to reset the big string to
everything except the one I just saved out. Are you saying there's a
better way than Left, Right, and Mid?

Ed
 
K

Karl E. Peterson

Ed said:
I got the same thing in the Immediate window, so the module is
working. Don't know what I had wrong.
Hmmm.


I currently use InStr to find the character position I need, then Left
to get the report I want and Right to reset the big string to
everything except the one I just saved out. Are you saying there's a
better way than Left, Right, and Mid?

Maybe not. I was worried you were breaking up the lines, and outputing them one by
one. <g> Sorry 'bout that... (You're not, right? <g>)
 
E

Ed from AZ

I currently use InStr to find the character position I need, then Left
Maybe not.  I was worried you were breaking up the lines, and outputingthem one by
one. <g>  Sorry 'bout that...  (You're not, right? <g>)

Nope. Although I have read a bit about some string functions eating
up lots of memory because they make copies of the strings and don't
always release the copies - or something like that.

But it is working and quite well. Thank you for staying with me on
this!!

Ed
 
K

Karl E. Peterson

Ed said:
Nope. Although I have read a bit about some string functions eating
up lots of memory because they make copies of the strings and don't
always release the copies - or something like that.

Yeah, ya gotta be smart with strings. Especially if you're putting them together,
rather than busting them apart.
But it is working and quite well. Thank you for staying with me on
this!!

You're welcome. This is the kind of stuff I seem to (perversely?) enjoy most. :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top