Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

read line by line from richtextbox, and write in c:\myfile.txt

Status
Not open for further replies.

sal21

Programmer
Apr 26, 2004
425
IT
read line by line from richtextbox, and write in c:\myfile.txt...
 
hi strong, progress... 98%

Code:
Private Sub Command3_Click()

    Me.Text1.SetFocus

    Dim ARR() As String
    Dim ITM As Long
    Dim iFileNo As Integer

    iFileNo = FreeFile
    Close #iFileNo
    Open App.Path & "\SCHEDE_PS\SCHEDEPS.txt" For Output As #iFileNo

    With Me.RichTextBox1
        ARR = Split(.Text, vbCrLf)
        For ITM = 0 To UBound(ARR)
            Print #iFileNo, ARR(ITM)
        Next ITM
    End With
    Close #iFileNo

End Sub

Why have a blank line to the end of txt file??? i dont need!
 
Ok, so your code isn't quite doing what you think it is.

For a start it is stripping out all the CrLfs. Then [tt]Print #[/tt] puts its own CRLF after each line it prints, including the last line. This gives the (false) impression that you are retaining the original CRLFs but somehow getting a magical extra one after the last line

You can suppress [tt]Print #[/tt]'s insertion of a CRLF by using a semi-colon (e.g. [tt]Print #iFileNo, ARR(ITM);[/tt]) - but this will then have the effect of removing all the CRLFs from your output - which I assume you want to retain.

But you don't need to go to all this bother. The richtextbox knows how to save itself: [tt]Me.RichTextBox1.SaveFile App.Path & "\SCHEDE_PS\SCHEDEPS.txt", rtfText[/tt]

 
This is weird...
Looks like you are reading [tt]SCHEDEPS.txt[/tt] file (which is just a simple text file) into a RichTextBox1 (which supports different fonts, bolds, colors, italics, etc.), you probably want to modify what's in RichTextBox1, but then you want to save it into [tt]c:\myfile.txt[/tt] which - again - is just a simple text file...
Why [ponder]

---- Andy

"Hmm...they have the internet on computers now"--Homer Simpson
 
No, Andy, you've misread the code.

They are reading the (non-rich) text contents of the richtextbox, and then writing that to the text file
 
Hello, sal21, did any of this help?

You don't seem to respond much when people try and help out, which means we are less likely to be inclined help in the future.

 
Basing on what was said, If...Then...Else will handle this blank line:

[tt]If ITM = UBound(ARR) Then Print #iFileNo, ARR(ITM); Else Print #iFileNo, ARR(ITM)[/tt]

combo
 
But I ask again - why bother, when the richtextbox can save itself as text in one line of code? This is why it would be useful for sal21 to revisit this thread.

However, I've found they have posted the same (or similar) questions in other forums, e.g (and have done so for may of their other questions). Perhaps they got a suitable fix in one of those other forums, and don't bother coming back to this forum, so we all waste our time .. this is why there is an etiquette about this sort of thing ...
 
Hello… hello…
Nothing but the echo in the few places where you said: “Hello?”[yawn]

---- Andy

"Hmm...they have the internet on computers now"--Homer Simpson
 
I can see sal21 has logged into tek-tips recently, just not posted ... ah well, I think they may have abandoned asking questions here in favour of Eileen's Lounge, where they have asked at least 6 questions in the last week ...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top