Results 1 to 12 of 12

Thread: Open new text file?

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Sep 2000
    Location
    Manchester, England.
    Posts
    18
    I have a query related to the above.

    I want to do exactly as above to create a log file, but my problem is naming the file using a string made up of "backup" and the date, i.e. backup22.09.2000.txt.

    I've tried:

    strFileName = "backup" & Date & ".txt"

    Open "C:\Temp\strFileName" For Output As #1 and


    Open "C:\Temp\"strFileName"" For Output As #1

    but neither work. Can you help me on the correct syntax please?


  2. #2
    Frenzied Member mlewis's Avatar
    Join Date
    Sep 2000
    Posts
    1,226
    Syntax:

    Open "c:\temp\" & strFileName For Output As #1

    Hope that helps.
    M. Lewis
    Pi-Q Software
    How many mouse clicks does it take to cook breakfast?

    Blargh! I am dead!

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Sep 2000
    Location
    Manchester, England.
    Posts
    18
    Thank you for your reply mlewis. I've just tried that and i'm getting a "path not found" error. I should say i do have a C:\Temp directory... :-)

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

    <?>

    PetergUK ..don't use mm.dd.yyyy
    [code]
    Option Explicit

    Private Sub Form_Load()
    Dim x
    x = Format(Now, "ddmmyyyy")
    x = "C:\my documents\backup\" & x & ".txt"
    Open x For Output As #1
    Write #1, "OK"
    Close

    End Sub
    [code]
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Sep 2000
    Location
    Manchester, England.
    Posts
    18
    That's great HeSaidJoe

    Can you explain why yours works and mine doesn't?

  6. #6
    Hyperactive Member CyberSurfer's Avatar
    Join Date
    Aug 2000
    Location
    Old London Town
    Posts
    425
    Because a filename usually consists of name.extension, whereas your file name would have been day.month.extension or whatever. More than one dot, you see.

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Sep 2000
    Location
    Manchester, England.
    Posts
    18
    Doh!!!!!!!!!!!

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

    PetergUK
    [code]
    'actually it has nothing to do with .
    'it is just bad practice to use characters in filenames

    'the reason was in your writing of the variable
    '
    'your statement should create a file called C:\Temp\strFileName
    'and not what was stored in strFileName
    '
    'Open "C:\Temp\strFileName" For Output As #1 and
    should be
    Open "C:\Temp\" & strFileName For Output As #1
    [\code]
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  9. #9

    Thread Starter
    Junior Member
    Join Date
    Sep 2000
    Location
    Manchester, England.
    Posts
    18
    Thanks HeSaidJoe

    It was the & that got me......

  10. #10
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986
    Because a filename usually consists of name.extension, whereas your file name would have been day.month.extension or whatever. More than one dot, you see.
    I don't think that's because of the dots, I think it displays dd/mm/yyyy

    and you're not allowed to have /\<>~:?"|* in your filename.
    Jop - validweb.nl

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

  11. #11

    Thread Starter
    Junior Member
    Join Date
    Sep 2000
    Location
    Manchester, England.
    Posts
    18
    Thank everyone, i've now got it working nicely:

    -----------------------------------------
    Dim strFileName

    NetUser

    strFileName = Format(Now, "dd.mm.yyyy")
    strFileName = "C:\temp\backup log " & strFileName& ".txt"
    Open strFileName For Output As #1

    Write #1, Time & " Application opened by " & NetUser
    -------------------------------------------

    By the way, when writing to the txt file, what's the difference between Write and Print? The help files don't seem to make a distinction.

  12. #12
    Fanatic Member Dim's Avatar
    Join Date
    Jul 2000
    Posts
    620
    If you Write to the file then it will put whatever you write in quotes (""). But if you use Print then it will print without the quotes ("").

    Hope that explains it for you,
    D!m
    Dim

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