How to create a txt file in VB6

sylvie -  
 MISOUI4 -
Hello forum

I need to create a txt file in VB6

Does anyone have an idea?

Thanks in advance

12 answers

  1. mophi Posted messages 4 Status Member 8
     
    Here is a simple code to place in the code associated with the button

    To be adapted according to your needs. The VB help provides all the additional information on the open and print commands.

    dim f as integer

    f = freefile
    open "c:\monfichier.txt" for output as #f
    print #f, "small text"
    close #f
    6
    1. MISOUI4
       
      How to create multiple files to save SQL scripts
      Thank you
      0
  2. elrin Posted messages 37 Status Member 4
     
    dac
    but how do you want to create your text file from what?
    1
  3. elrin Posted messages 37 Status Member 4
     
    This is what I used to save text displayed in a textbox with selected file representing the file path

    Dim SelectedFile As String
    Dim vari As Integer
    Dim contenu As String
    Dim chemin As String

    Private Sub save_Click()
    vari = FreeFile
    contenu = Form1.visualisation.Text
    ' file path to save
    chemin = SelectedFile
    ' opening the file
    Open chemin For Output As #vari
    ' saving the text
    Print #vari, contenu
    ' closing the file
    Close vari

    End Sub
    1
    1. Djé-Djé
       
      It doesn't work. It gives an error:

      'Open' is not declared. The file I/O functionality is available in the 'Microsoft.VisualBasic' namespace
      0
  4. inyocha Posted messages 12 Status Member 1
     
    Hello
    to create a txt file in vb6, simply write the following code:
    Open "C:\monfichier.txt" For Input As #1
    return = Chr$(13) + Chr$(10)
    Line Input #1, text
    all = text
    If Len(all) <> 0 Then
    While Not EOF(1)
    Line Input #1, text
    all = all + return + text
    Wend
    End If
    Text1.Text = all
    Close #1
    hoping that I get at least some help
    1
  5. elrin Posted messages 37 Status Member 4
     
    Have you tried using a textbox?
    Then you save it.
    0
  6. Sylvie
     
    No, I didn't try from a textbox

    I want to create the file from a command button.
    0
  7. elrin Posted messages 37 Status Member 4
     
    You can type your text in a textbox and then create it from a save button, otherwise I will look at the codes to guide you to do it with some code.
    Still, check the forums and the internet to see if you can find a source code that would help you.

    +++
    0
  8. elrin Posted messages 37 Status Member 4
     
    Do you want to do it from the keyboard input?
    0
  9. Sylvie
     
    Hi Mophi and Elrin

    Both programs work wonderfully.

    But when I wanted to copy the content from another text file to paste it into the created file, it gives me errors.

    But still, thank you.
    0
  10. dadz
     
    Super mini - tutorial, works wonderfully indeed :-)

    But! .. quick question, how can I extract the content of the entire FlexGrid and copy it into a text file?? .. regardless of the text formatting afterwards ..
    0