Results 1 to 11 of 11

Thread: code to create a file?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2001
    Posts
    302
    What is the code to create a file in a given folder? (ex: c:\myfiles\)

    Thank you :::

  2. #2
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986
    Code:
    Open FILENAME for Output As #1
    Close #1
    Or use the CreateFile (or OpenFile) api.
    Jop - validweb.nl

    Alcohol doesn't solve any problems, but then again, neither does milk.

  3. #3
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238

    Thumbs up

    Other tahn Output, you also can open the as Append, Binary and Random. Juz depand on what and how you want to save the data into it.

    Cheers!

  4. #4
    Hyperactive Member PJB's Avatar
    Join Date
    Aug 2000
    Location
    dunno at the moment
    Posts
    302
    here's the code to write a txt if it helps, someone posted it here for me at one point, forget who but thanks:

    Code:
    'writing or reading data to or from a text file
    'open for append adds the data to the end of file
    'open for input opens the file for read only
    'open for output opens the file and overwrites the file
    '
    '
    Private Sub Command1_Click()
    
    'this is the number of your file
    Dim intFilenum As Integer
    
    'set it to the next available free number
    intFilenum = FreeFile
    
    'this is your filename
    Dim strFile As String
    strFile = "A:\myfile.txt"
    
    'this is the text you want to save (textbox)
    Dim strText As String
    strText = Text1.Text
    
    'open the file for writing to as next freefile number
    
    Open strFile For Append As intFilenum  'see above options
    'write to the file
        Write #intFilenum, strText  'to read use  [input #filenum,strtext]
    
    'close the file
    Close intFilenum
        
    End Sub
    VB6.0 SP4
    Windows 2000
    I'm thinking of a number between

  5. #5
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238
    PJB, You can do it without the FreeFile.

    Code:
    Open strFile For Append As #1
       Print #1, strText
    Close #1

  6. #6
    Junior Member
    Join Date
    Dec 2000
    Posts
    28
    Chris, you have a quarrel with FreeFile?

  7. #7
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238
    Noop! Knut, Juz wish to let others know that it can be done with it. So we can declare less and make the code more efficient and a smaller EXE filesize.

    Cheers!

    Originally posted by Knut
    Chris, you have a quarrel with FreeFile?

  8. #8
    Junior Member
    Join Date
    Dec 2000
    Posts
    28
    Just been asking since I believe yesterday or so you seemed to stress that as well...

    I'm sort of in the habit of using FreeFile even though i rarely work with more than 6 or 7 files at the same time in my apps...

    The older you get, the more you stick to habits even if there's no obvious need...

    While becoming philosophical: Just because MS creates a function, that doesen't mean it has to be used!

    (Now, there's a 180 degree turn...)

  9. #9
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238
    Perhaps is no. 'coz we must always think that we can't
    learn all the think in the world and we always learning new stuff from day to day.

    Yet new things always improve the old things, else I don't
    see there is a need to create a new thing without improving as compare to the old version.

    Is there is a good things why we not give a try and why should it stick to the old and unefficient way? Hah...

  10. #10
    Junior Member
    Join Date
    Dec 2000
    Posts
    28
    Is there is a good things why we not give a try and why should it stick to the old and unefficient way? Hah...
    That's the point!

  11. #11
    Hyperactive Member PJB's Avatar
    Join Date
    Aug 2000
    Location
    dunno at the moment
    Posts
    302
    don't recall exactly saying it was the best, most efficient or only way of doing it, so whatever
    VB6.0 SP4
    Windows 2000
    I'm thinking of a number between

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