Text Wrap in a simple text box??!!!??? (Yes, again) 
Author Message
 Text Wrap in a simple text box??!!!??? (Yes, again)

I posted here a week or so ago and got some replies which I
was sure had solved my dilemna, until I tried them.  For
some reason they still don't work.  For those who missed my
first post, I am trying to import CNC files into VB.  They
are simple text files, nothing fancy.  Multiline.  I am
merely trying to load them and display the file in a simple
text box.

Using VB5, multiline enabled.  The text box was displaying
characters for the carriage return rather than actually
inserting a new line.  Here's the real original code I had:

Private Sub Form_Load()
Text1 = " "
If cncfile$ = "" Then
Open cncfile$ For Input As #1
Do While Not EOF(1)
    Line Input #1, a$
    Text1 = Text1 & a$
Loop
Else: Text1.Text = "No CNC File Loaded"
End If

End Sub

Here's some other things I tried, replacing line 6 as per
suggestions of this discussion group (by the way, thanks
guys.  The help and education is appreciated):

Text1 = Text1 & a$ & vbCrLf

Text1 = Text1 & a$ & Chr$(13) & Chr$(10)

Text1 = Text1 & a$ & Chr$(13)

Text1 = Text1 & a$ & vbCr

Text1 = Text1 & a$ & vbLf

Text1 = Text1 & a$ & Chr$(10)

None of these worked either.  The text box finds the file
and loads it alright, but will not recognize a carriage
return, only displays characters in their place.
What up with that???

Thanks,
Ian

* Sent from AltaVista http://www.*-*-*.com/ Where you can also find related Web Pages, Images, Audios, Videos, News, and Shopping.  Smart is Beautiful



Fri, 06 Sep 2002 03:00:00 GMT  
 Text Wrap in a simple text box??!!!??? (Yes, again)

Quote:

> I posted here a week or so ago and got some replies which I
> was sure had solved my dilemna, until I tried them.  For
> some reason they still don't work.  For those who missed my
> first post, I am trying to import CNC files into VB.  They
> are simple text files, nothing fancy.  Multiline.  I am
> merely trying to load them and display the file in a simple
> text box.
> Using VB5, multiline enabled.  The text box was displaying
> characters for the carriage return rather than actually
> inserting a new line.  Here's the real original code I had:
> Private Sub Form_Load()
> Text1 = " "
> If cncfile$ = "" Then
> Open cncfile$ For Input As #1
> Do While Not EOF(1)
>     Line Input #1, a$
>     Text1 = Text1 & a$
> Loop
> Else: Text1.Text = "No CNC File Loaded"
> End If
> End Sub

What are CNC files? If they use only carriage returns to separate lines,
with no linefeed characters, VB's Line Input might read the entire file
into one very long line. To see if this is the case, use this:

Private Sub Form_Load()
    Text1 = " "
    If cncfile$ = "" Then
        Open cncfile$ For Input As #1
        Dim LineCount As Long: LineCount = 0
        Do While Not EOF(1)
            Line Input #1, a$
            Text1 = Text1 & a$
            LineCount = LineCount + 1
        Loop
        MsgBox LineCount
    Else
        Text1.Text = "No CNC File Loaded"
    End If
End Sub

If there's only one "line", you'll need VB6's Replace or the StrReplaceAll
function from <http://members.ricochet.net/~jfoster/> to convert whatever
CNC files use to separate lines to vbCrLf, perhaps like this:

Private Sub Form_Load()
    Text1 = " "
    If cncfile$ = "" Then
        Open cncfile$ For Input As #1
        Dim LineBuf As String: LineBuf = vbNullString
        Dim TextBuf As String: TextBuf = vbNullString
        Do While Not EOF(1)
            Line Input #1, LineBuf
            TextBuf = TextBuf & vbCrLf & StrReplaceAll(LineBuf, vbCr, vbCrLf, 0)
            LineCount = LineCount + 1
        Loop
        Text1.Text = Mid$(TextBuf, 3) ' snip off the leading vbCrLf
    Else
        Text1.Text = "No CNC File Loaded"
    End If
End Sub

Oh yeah, it's usually considered better to use Dim X As String rather
than Dim X$. Also, always make sure your modules have Option Explicit
at the top of the Declarations section. Many Delphites apparently never
found the "Require Variable Declaration" checkbox in the Tools Options
dialog, spawning all the "VB SUX DELPHI ROX" flamewars as well as too
much buggy VB code to contemplate.

--

WARNING: I cannot be held responsible for the above        They're   coming  to
because  my cats have  apparently  learned to type.        take me away, ha ha!



Fri, 06 Sep 2002 03:00:00 GMT  
 Text Wrap in a simple text box??!!!??? (Yes, again)
Here is a snippet of code from my text-editor application, it may help:

Private Sub mnuFileOpen_Click()
    Dim sFile As String
    Dim tmpLine$

    With dlgCommonDialog
        .DialogTitle = "Open"
        .CancelError = False
        'ToDo: set the flags and attributes of the common dialog control
        .Filter = "All Files (*.*)|*.*"
        .ShowOpen
        If Len(.FileName) = 0 Then
            Exit Sub
        End If
        sFile = .FileName
    End With

    fMainForm.Caption = sFile
    txtDoc1.Text = ""

    Open sFile For Input As #1
    Do While Not EOF(1)
        Line Input #1, tmpLine
        txtDoc1.Text = txtDoc1.Text + tmpLine + Chr(13) + Chr(10)
    Loop
    Close #1
End Sub



Sat, 07 Sep 2002 03:00:00 GMT  
 Text Wrap in a simple text box??!!!??? (Yes, again)
Thanks guys, will try that now.
By the way, FYI, a CNC file is a text file, Computer Numeric
Control for controlling computer controlled equipment such
as a milling machine, metal lathe, stuff like that.

Thanks,
Ian

* Sent from AltaVista http://www.altavista.com Where you can also find related Web Pages, Images, Audios, Videos, News, and Shopping.  Smart is Beautiful



Sat, 07 Sep 2002 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Yes - Rich Text Box assistance needed again ..

2. Text Wrapping in Rich Text Box

3. Wrapping Text in a Text Box

4. Text box text on new page text box

5. Filter A Report From a Pop-Up Box for Text, Numbers, and Yes/No Field Types

6. Text field size, or text wrapping

7. Multiple Text lines with text wrap to fit the textbox size

8. Wrapping text around a bmp image in the rich text editor

9. DBGrid text wrap - won't stay wrapped!

10. Word Wrapping at standard text box control

11. Rich Edit Box text wrapping

12. RICH TEXT BOX WORD WRAP

 

 
Powered by phpBB® Forum Software