Writing to a log file - Don't tell me I stumped all of you!!
MZ Tools makes life easier for the Excel VBA coder
Thanks Thanks:  0
Likes Likes:  0
Results 1 to 7 of 7

Thread: Writing to a log file - Don't tell me I stumped all of you!!

  1. #1
    Board Regular
    Join Date
    Feb 2002
    Posts
    97
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

     
    My excel app requires a refresh of all data every minute or so. I have that part done. What I would like to do is write to a log file every time a refresh is done, reporting errors and what not. Problem is, I don't want these log files getting to large in size. I have the idea in my head, how I want to do it. I just can't seem to get the code down. Here's an idea of what I'm trying to do:
    I would have 1 log file called mach.log. That would be the primary file being written to all the time. I would then have in code to check the size of that file before writing to it, if it's over 250000 bytes, then rename mach.log to "mach" &Date& ".log". And then start with a clean mach.log all over again. Something like this (this is pretty ruff at this point):

    set f = mach.log 'you get the point....
    if f.size > 250000 then
    f.rename ("mach." & Date & ".log")
    else
    f.write(....)
    end if

    Hopefully you follow...? The problem? Is there an actual method .rename? I can't find anything that would do that...



    [ This Message was edited by: charlie79 on 2002-03-26 08:23 ]

  2. #2
    Board Regular
    Join Date
    Feb 2002
    Posts
    97
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Someone... SVP.....

  3. #3
    New Member
    Join Date
    Mar 2002
    Location
    Trumbull Services
    Posts
    2
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Hey Charlie. Have you tried the FileSystemObject? Check the code below from the excel help file. You can get the size, in bytes, of the file in question.

    Good luck!

    Size Property


    Description

    For files, returns the size, in bytes, of the specified file. For folders, returns the size, in bytes, of all files and subfolders contained in the folder.

    Syntax

    object.Size

    The object is always a File or Folder object.

    Remarks

    The following code illustrates the use of the Size property with a Folder object:

    Sub ShowFolderSize(filespec)
    Dim fs, f, s
    Set fs = CreateObject("Scripting.FileSystemObject")
    Set f = fs.GetFolder(filespec)
    s = UCase(f.Name) & " uses " & f.size & " bytes."
    MsgBox s, 0, "Folder Size Info"
    End Sub


  4. #4
    Board Regular
    Join Date
    Feb 2002
    Posts
    97
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Yes, I realize that part of it. I believe that code came directly from excel help and I've been there already. What I'm asking is if there is a way to rename the file if it is over 250000 bytes... Thanks for the idea though. Anyone else... Please!

  5. #5
    New Member
    Join Date
    Mar 2002
    Location
    Trumbull Services
    Posts
    2
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    You should be able to say ...

    If F.Size > X Then
    F.CopyFile FromFileName, ToFileName
    F.DeleteFile FromFileName
    Set a = f.CreateTextFile(FromFileName, True)

    End If

    This should give you a new (empty) logfile if the size of the file grows bigger than X.

  6. #6
    Board Regular
    Join Date
    Feb 2002
    Posts
    97
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    That looks more like what I was looking for! Great, thanks a bunch!!


  7. #7
    Board Regular
    Join Date
    Feb 2002
    Posts
    97
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

      
    Tested 'er out, works great cbass!!!
    Thanks again...

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

 

 
DMCA.com