printing a string of text

mtaylor314

Member
Joined
Nov 30, 2006
Messages
19
Location
Cleves, OH
Programming Experience
Beginner
VB.NET:
    Public Sub PrintFormatText(ByVal PrintText As String, ByVal Handle As Long, ByVal cpl As Byte)

        Dim ts As String
        Dim ln As Integer
        Dim vr As Array
        Dim i As Integer

        vr = Split(PrintText, vbCrLf)
        For i = LBound(vr) To UBound(vr)
            ts = vr(i)
            Do
                Print(Handle, Left(ts, cpl))
                ln = Len(ts)
                If ln <= cpl Then
                    Exit Do
                End If
                ts = Right$(ts, ln - cpl)
            Loop
        Next i
    End Sub
This code is supposed to take a string of text, print it to a file, and keep the length to whatever the cpl is set to, 25, 50, etc. It also does not include vbCrLf to go to a new line. This was originally vb6 code that had converted to .net 2005. The vb6 code worked just fine. Please help
 
Last edited:
VB.NET:
  Sub PrintFormatText(toPrint As String, sw as StreamWriter, len As Integer)
    Dim lines() as String = toPrint.Split(Environment.NewLine.ToCharArray())
    ForEach line as String In lines
      If line.Length > len Then
        sw.WriteLine(line.Substring(0, len))
      Else
        sw.WriteLine(line)
      EndIf
   Next line
  End Sub

THis was typed blind, not tested. I dont guarantee it will compile... but then if i did everything for you, that would leave no fun for you! :)
If youre unsure of anything used, Press F2 in Vis Studio, and search it, e.g. StreamWriter
 
Back
Top