From: Jennifer Ward on 15 Jan 2010 10:17 Hi, I'm having a problem when writing text to a text file. My program opens the file and then periodically from different routines a line will be written to it. I close the file before ending the program. The problem is that some of the lines are not getting to the file. Could it be that the program is ending too quickly after Close statement ? Sample code: fname = "\Event_Log.txt" Err_Log_Filenum = FreeFile() Open App.Path & fname For Append As Err_Log_Filenum Then periodically: Print #Err_Log_Filenum, Format$(Now, "mm-dd-yy hh:mm:ss") & "Error text" Finally: Close #Err_Log_Filenum I'd really appreciate any suggestions. I prefer not to work through the API if possible. Thanks, Jen
From: dpb on 15 Jan 2010 10:45 Jennifer Ward wrote: > Hi, > > I'm having a problem when writing text to a text file. > My program opens the file and then periodically from different routines a > line will be written to it. > I close the file before ending the program. The problem is that some of the > lines are not getting to the file. > Could it be that the program is ending too quickly after Close statement ? .... More likely the line isn't actually being written when you think it is. Possibilities include error handling passing out of routine w/ an On Error still in effect or conversely no error handler in effect. --
From: MikeD on 15 Jan 2010 11:01 "Jennifer Ward" <jward(a)comcast.net> wrote in message news:Oro7cXflKHA.2184(a)TK2MSFTNGP04.phx.gbl... > Hi, > > I'm having a problem when writing text to a text file. > My program opens the file and then periodically from different routines a > line will be written to it. > I close the file before ending the program. The problem is that some of > the lines are not getting to the file. > Could it be that the program is ending too quickly after Close statement ? > > Sample code: > > fname = "\Event_Log.txt" > Err_Log_Filenum = FreeFile() > Open App.Path & fname For Append As Err_Log_Filenum > > Then periodically: > > Print #Err_Log_Filenum, Format$(Now, "mm-dd-yy hh:mm:ss") & "Error > text" > > Finally: > Close #Err_Log_Filenum > > It appears you're opening the file once, perhaps when your program first runs, write to it periodically, and then close the file when your program closes. I would not recommend this. Instead open and close the file EACH time you need to write to it. This may or may not solve your actual problem, but it's a better and safer method. -- Mike
From: Jennifer Ward on 15 Jan 2010 11:07 Thanks, My error handling is good and most of the missing text is the result of my code catching the user doing something they shouldn't be doing. But the most common thing is that the routine exits right away. Perhaps I should do my text file writing before the msgbox appears. "dpb" <none(a)non.net> wrote in message news:hiq2jk$tv2$1(a)news.eternal-september.org... > Jennifer Ward wrote: >> Hi, >> >> I'm having a problem when writing text to a text file. >> My program opens the file and then periodically from different routines a >> line will be written to it. >> I close the file before ending the program. The problem is that some of >> the lines are not getting to the file. >> Could it be that the program is ending too quickly after Close statement >> ? > ... > > More likely the line isn't actually being written when you think it is. > Possibilities include error handling passing out of routine w/ an On Error > still in effect or conversely no error handler in effect. > > --
From: DanS on 15 Jan 2010 11:20 "MikeD" <nobody(a)nowhere.edu> wrote in news:ueCOLwflKHA.2316(a)TK2MSFTNGP06.phx.gbl: > > > > "Jennifer Ward" <jward(a)comcast.net> wrote in message > news:Oro7cXflKHA.2184(a)TK2MSFTNGP04.phx.gbl... >> Hi, >> >> I'm having a problem when writing text to a text file. >> My program opens the file and then periodically from different >> routines a line will be written to it. >> I close the file before ending the program. The problem is that some >> of the lines are not getting to the file. >> Could it be that the program is ending too quickly after Close >> statement ? >> >> Sample code: >> >> fname = "\Event_Log.txt" >> Err_Log_Filenum = FreeFile() >> Open App.Path & fname For Append As Err_Log_Filenum >> >> Then periodically: >> >> Print #Err_Log_Filenum, Format$(Now, "mm-dd-yy hh:mm:ss") & "Error >> text" >> >> Finally: >> Close #Err_Log_Filenum >> >> > > > It appears you're opening the file once, perhaps when your program > first runs, write to it periodically, and then close the file when > your program closes. I would not recommend this. Instead open and > close the file EACH time you need to write to it. This may or may not > solve your actual problem, but it's a better and safer method. > Yes Mike, I would agree. The OP should write a sub/function... (Not complete, but the jist (sp?) is there.) Public Function WriteLog(entry as string) as boolean On Error Resume Next Open File for Append Print #, entry Close # If err then err.clear WriteLog = False Else WriteLog = True End if End Function Or something similar. This way not only is it just one line to write to the log, but the OP can place a break or a debug.print in this one function to see if the log is being written when they think it should be.
|
Next
|
Last
Pages: 1 2 3 Prev: Installing MDAC 5 for sp5 Next: Dumb question: Are VB6 DLLs dependient on the rutnime? |