txt file

how can i create a txt file with code in VB 5.0 ?
Who is Participating?
kianweiConnect With a Mentor Commented:
Try this,

On error Goto ErrorHandler
Open Filename .....
exit sub
  Select case err.number
  case [file not found err number]
      create file
  end select
end sub
Open filename For Output As #1
Print #1, Text
Print #1, Some more text
Close #1

Check ya helpfile on the Open statement
Hello there,
Example code

Create on your form 1 button with Caption "Create"
1 text box where the file name will be specificated
and another one where you will write the file's contents

and past the code below in your form

Private Sub Command1_Click()
    Open Text1.Text For Output As #1
    Print #1, Text2.Text
    Close #1
End Sub

That's all
enryoAuthor Commented:
the first time that i run my program i get this error "file not found" so how do i detect the error to create the file?
All Courses

From novice to tech pro — start learning today.