Results 1 to 2 of 2

Thread: Problem while outputting to a textfile

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2004
    Posts
    13

    Problem while outputting to a textfile

    I am trying to write the contents of a listbox into a text file, but I am having difficulty. The code executes error free, however at the end of it I cannot find the created text file (if it even is being created).

    VB Code:
    1. Private Sub cmdTextfile_Click()
    2. Dim strFilename As String
    3. Dim intMessage As Integer
    4. Dim i As Integer
    5.  
    6.  
    7.     If lstResults.List(0) <> "" Then
    8.             strFilename = InputBox("Input filename for new output textfile", "Input Filename")
    9.             strFilename = strFilename & ".txt"
    10.             Open strFilename For Output As #1
    11.             i = 0
    12.                 Do
    13.                     Print #1, lstResults.List(i)
    14.                     i = i + 1
    15.                 Loop Until i = lstResults.ListCount + 1
    16.                
    17.             Close #1
    18.             MsgBox ("Textfile has been created")
    19.            
    20.     Else
    21.         MsgBox ("There are no output values to output to file")
    22.     End If
    23. End Sub

  2. #2
    Hyperactive Member
    Join Date
    Nov 2003
    Location
    In Front of my computer...
    Posts
    367
    Lil fixes

    VB Code:
    1. Dim strFilename As String
    2.     Dim intMessage As Integer
    3.     Dim i As Integer
    4.    
    5.    
    6.         If lst.List(0) <> "" Then
    7.                 strFilename = InputBox("Input filename for new output textfile", "Input Filename")
    8.                 strFilename = strFilename & ".txt"
    9.                 Open "C:\" & strFilename For Output As #1 '- Change path to whatever you want
    10.                 For i = 0 To lst.ListCount - 1 '- Get all listbox contents...
    11.                     Print #1, lst.List(i)
    12.                 Next i
    13.                 Close #1
    14.                 MsgBox ("Textfile has been created")
    15.                
    16.         Else
    17.             MsgBox ("There are no output values to output to file")
    18.         End If
    Born to help others
    (If I've been helpful then please rate my post. Thanks)

    call me EJ or be slapped!

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