Results 1 to 3 of 3

Thread: Printing variable strings

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2000
    Location
    Ontario, Canada
    Posts
    1

    Question

    Please help...I'm new to VB. I'm reading a text file that contains a variable sized string. When I try to print this string it gets truncated at the end of the page. Is there a simple way to continue the string on the next line? I've tried using the Mid function, but it didn't work very well.
    Dim stra As String 'first string in file
    Dim strb As String 'second string in file
    Dim strA1 As String
    Dim strA2 As String
    Dim strA3 As String
    Dim strA4 As String
    Dim strB1 As String
    Dim strB2 As String
    Dim strB3 As String
    Dim strB4 As String
    strA1 = Mid$(stra, 1, 100)
    strA2 = Mid$(stra, 101, 100)
    strA3 = Mid$(stra, 201, 100)
    strA4 = Mid$(stra, 301, 100)
    strB1 = Mid$(strb, 1, 100)
    strB2 = Mid$(strb, 101, 100)
    strB3 = Mid$(strb, 201, 100)
    strB4 = Mid$(strb, 301, 100)

    Printer.Print Tab(5); strA1
    Printer.Print Tab(5); strA2
    Printer.Print Tab(5); strA3
    Printer.Print Tab(5); strA4
    Printer.Print Tab(5); strB1
    Printer.Print Tab(5); strB2
    Printer.Print Tab(5); strB3
    Printer.Print Tab(5); strB4

    This is done as I loop thru the file, but all I get are blank output lines.

    I'd appreciate any help (please remember that this is a new language for me).

  2. #2
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Your code above worked for my except that you don't assign any values to stra and strb so they are blank hence printing out nada. Also are these fixed length variables because right now your code would print blank lines if the stra or b are under 300 characters. Why are you breaking it out by hundreds? Maybe there is a better way of doing it.

    [Edited by Edneeis on 11-13-2000 at 11:32 AM]

  3. #3
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    Code:
    'here is how I would code your situtation
    'hardcoding is not a good way of doing things.
    'I am only using one string and a characeter 
    'return of 20 , but you can change it to suit your needs.
    
    Private Sub Command1_Click()
        Dim x As String
        x = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz4"
        
        Dim i As Integer, y As Integer
    'give i the value of the length of your string
    'oc course this will vary with different strings.
    
        i = Len(x)
    'do until the length of the string is diminished
        Do Until i <= 1
     'I am using 20, you were using 100, you can use what
     'you deem sufficient...however many (w) will fit on your page line
     'or you can set the font to courier and all letters take the same space
     
          If i >= 20 Then
    'if the length of the string is greater than your desired number (20)
    
            Printer.Print (Tab5); Left(x, 20)
    'take what is left in the string as your new string
            x = Right(x, i - 20)
    'your length is the length of the new string
            i = Len(x)
               
     'if the new string is under your number (20) then
          Else
          Printer.Print (Tab5); Right(x, i)
     'there is nothing left in the string so it is set to ""
           x = ""
    'the len of the string is now 0
           i = Len(x)
            
        End If
        
            Loop
    'tell the printer to print now or add this to your
    'form unload event to print when you quit
        Printer.EndDoc
    
    End Sub
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width