|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Problem with syntaxFor years I haven't any problems with this code: Dim FileNum As Long FileNum = FreeFile lname = lpDataFolderName & pUser.Handle & ".txt" Open lname For Append As FileNum Print #FileNum, pUser.FullName & "," & AdjustedDate --------------------- Suddenly, I started receiving error message: "Run time error '52': Bad file name or number" and Print #FileNum, pUser.FullName & "," & AdjustedDate is highlighted The code is just copied and pasted. I do not understand that problem. Thanks, Kathy And what is the filename?
Debug.Print ">" & lname & "<" and show us "Kathy" <Kathy@kathy> wrote in message Debug.Print ">" & lname & "<"news:%23Tp%23oZTnJHA.5228@TK2MSFTNGP02.phx.gbl... > Hello, > For years I haven't any problems with this code: > Dim FileNum As Long > FileNum = FreeFile > lname = lpDataFolderName & pUser.Handle & ".txt" Show quoteHide quote > Open lname For Append As FileNum > Print #FileNum, pUser.FullName & "," & > AdjustedDate > --------------------- > > Suddenly, I started receiving error message: > "Run time error '52': > Bad file name or number" > and > Print #FileNum, pUser.FullName & "," & AdjustedDate > is highlighted > > The code is just copied and pasted. > I do not understand that problem. > Thanks, > Kathy > Hi Kathy,
Are you also closing the file handle ? Also check to see if lpDataFolderName includes a path separator, eg "\" Show quoteHide quote "Kathy" <Kathy@kathy> wrote in message news:%23Tp%23oZTnJHA.5228@TK2MSFTNGP02.phx.gbl... > Hello, > For years I haven't any problems with this code: > Dim FileNum As Long > FileNum = FreeFile > lname = lpDataFolderName & pUser.Handle & ".txt" > Open lname For Append As FileNum > Print #FileNum, pUser.FullName & "," & > AdjustedDate > --------------------- > > Suddenly, I started receiving error message: > "Run time error '52': > Bad file name or number" > and > Print #FileNum, pUser.FullName & "," & AdjustedDate > is highlighted > > The code is just copied and pasted. > I do not understand that problem. > Thanks, > Kathy > Please.
If it was the problem with the file name the error would happen a line of code earlier, wouldn't it? Kathy Show quoteHide quote "Kathy" <Kathy@kathy> wrote in message news:%23Tp%23oZTnJHA.5228@TK2MSFTNGP02.phx.gbl... > Hello, > For years I haven't any problems with this code: > Dim FileNum As Long > FileNum = FreeFile > lname = lpDataFolderName & pUser.Handle & ".txt" > Open lname For Append As FileNum > Print #FileNum, pUser.FullName & "," & > AdjustedDate > --------------------- > > Suddenly, I started receiving error message: > "Run time error '52': > Bad file name or number" > and > Print #FileNum, pUser.FullName & "," & AdjustedDate > is highlighted > > The code is just copied and pasted. > I do not understand that problem. > Thanks, > Kathy > Kathy wrote:
Show quoteHide quote > Please. So what has changed, Kathy, if the code has worked for years?> If it was the problem with the file name the error would happen a line of > code earlier, wouldn't it? > Kathy > > "Kathy" <Kathy@kathy> wrote in message > news:%23Tp%23oZTnJHA.5228@TK2MSFTNGP02.phx.gbl... >> Hello, >> For years I haven't any problems with this code: >> Dim FileNum As Long >> FileNum = FreeFile >> lname = lpDataFolderName & pUser.Handle & ".txt" >> Open lname For Append As FileNum >> Print #FileNum, pUser.FullName & "," & >> AdjustedDate >> --------------------- >> >> Suddenly, I started receiving error message: >> "Run time error '52': >> Bad file name or number" >> and >> Print #FileNum, pUser.FullName & "," & AdjustedDate >> is highlighted >> >> The code is just copied and pasted. >> I do not understand that problem. >> Thanks, >> Kathy >> Would pUser.FullName having an apostrophe in it (e.g. "O'Briens") affect it or has AdjustedDate had its format changed? That's what you have to look at Argusy "argusy" <arg***@slmember.on.net> wrote in message No, she's writing to a file, not SQL Server. An apostrophe isn't going to news:01bfc302$0$19421$c3e8da3@news.astraweb.com... >>> Print #FileNum, pUser.FullName & "," & AdjustedDate >>> is highlighted > Would pUser.FullName having an apostrophe in it (e.g. "O'Briens") affect > it affect anything. > or has AdjustedDate had its format changed? Again, that's just data going to the file. That won't be the issue.The problem is related strictly to #FileNum
in Print #FileNum, pUser.FullName & "," & AdjustedDate BTW, FilNum = 3 which by itself is not correct I think. Normally I have always FileNum = 1. When I remove # from #FileNum the error is gone but file of course not written. I understand if there were some other events between FileNum = FreeFile and Print #FileNum, pUser.FullName & "," & then there is a room for error. One more note. It is not regular error. I had IDE running for half a day, that code executed every few minutes, and after few hours the error hit. I cannot repeat it so far today. Thanks, Kathy Show quoteHide quote "Kathy" <Kathy@kathy> wrote in message news:%23Tp%23oZTnJHA.5228@TK2MSFTNGP02.phx.gbl... > Hello, > For years I haven't any problems with this code: > Dim FileNum As Long > FileNum = FreeFile > lname = lpDataFolderName & pUser.Handle & ".txt" > Open lname For Append As FileNum > Print #FileNum, pUser.FullName & "," & > AdjustedDate > --------------------- > > Suddenly, I started receiving error message: > "Run time error '52': > Bad file name or number" > and > Print #FileNum, pUser.FullName & "," & AdjustedDate > is highlighted > > The code is just copied and pasted. > I do not understand that problem. > Thanks, > Kathy > Kathy wrote:
> The problem is related strictly to #FileNum That indicates there are open files that haven't been closed previously. > in Print #FileNum, pUser.FullName & "," & AdjustedDate > BTW, FilNum = 3 which by itself is not correct I think. > Normally I have always FileNum = 1. If you expect this is the only file open by your app then you definitely have missed a Close somewhere either by a logic branch or an error branch. .... Show quoteHide quote > I understand if there were some other events between > FileNum = FreeFile and Print #FileNum, pUser.FullName & "," & > then there is a room for error. .... >> Dim FileNum As Long >> FileNum = FreeFile >> lname = lpDataFolderName & pUser.Handle & ".txt" >> Open lname For Append As FileNum >> Print #FileNum, pUser.FullName & "," & AdjustedDate .... Thank you.
I checked that yesterday and I could not find any missing Close statement somewhere else. Interestingly, when the error happened yesterday, I tried to do that: in the debug state I moved code away from the offending line and I did this: Close 1 Close 2 and then proceeded to the offending line. The error was still there. Thanks, Kathy Show quoteHide quote "dpb" <n***@non.net> wrote in message news:gop6ig$g82$1@aioe.org... > Kathy wrote: >> The problem is related strictly to #FileNum >> in Print #FileNum, pUser.FullName & "," & AdjustedDate >> BTW, FilNum = 3 which by itself is not correct I think. >> Normally I have always FileNum = 1. > > That indicates there are open files that haven't been closed previously. > If you expect this is the only file open by your app then you definitely > have missed a Close somewhere either by a logic branch or an error branch. > > ... > >> I understand if there were some other events between >> FileNum = FreeFile and Print #FileNum, pUser.FullName & "," & >> then there is a room for error. > ... > >>> Dim FileNum As Long >>> FileNum = FreeFile >>> lname = lpDataFolderName & pUser.Handle & ".txt" >>> Open lname For Append As FileNum >>> Print #FileNum, pUser.FullName & "," & AdjustedDate > ... Kathy wrote:
....top posting repaired. Please don't do that... Show quoteHide quote > "dpb" <n***@non.net> wrote in message news:gop6ig$g82$1@aioe.org... Once it occurred I'm not surprised.>> Kathy wrote: >>> The problem is related strictly to #FileNum >>> in Print #FileNum, pUser.FullName & "," & AdjustedDate >>> BTW, FilNum = 3 which by itself is not correct I think. >>> Normally I have always FileNum = 1. >> That indicates there are open files that haven't been closed previously. >> If you expect this is the only file open by your app then you definitely >> have missed a Close somewhere either by a logic branch or an error branch. .... > I checked that yesterday and I could not find any missing Close > statement somewhere else. > Interestingly, when the error happened yesterday, I tried to do that: > in the debug state I moved code away from the offending line and I > did this: > Close 1 > Close 2 > and then proceeded to the offending line. > The error was still there. .... Freefile returning "3" indicates that "1" and "2" were in use for some reason. Whether by error in logic or an unhandled exception or whatever the reason. Otherwise, VB assigns free file ID handles beginning w/ 1. An error or other interruption could cause a problem as well. Using any 3rd part controls or other processes? -- If you are sure that no other files are supposed to be open, then just do a
Close (without any parameters) before the FreeFile statement and that will close all open files. The FreeFile statement should then assign 1 for FileNum every time. Daryl Show quoteHide quote "Kathy" <Kathy@kathy> wrote in message news:e7Q3tYcnJHA.996@TK2MSFTNGP03.phx.gbl... > Thank you. > I checked that yesterday and I could not find any missing Close statement > somewhere else. > Interestingly, when the error happened yesterday, I tried to do that: > in the debug state I moved code away from the offending line and I did > this: > Close 1 > Close 2 > and then proceeded to the offending line. > The error was still there. > Thanks, > Kathy > > "dpb" <n***@non.net> wrote in message news:gop6ig$g82$1@aioe.org... >> Kathy wrote: >>> The problem is related strictly to #FileNum >>> in Print #FileNum, pUser.FullName & "," & AdjustedDate >>> BTW, FilNum = 3 which by itself is not correct I think. >>> Normally I have always FileNum = 1. >> >> That indicates there are open files that haven't been closed previously. >> If you expect this is the only file open by your app then you definitely >> have missed a Close somewhere either by a logic branch or an error >> branch. >> >> ... >> >>> I understand if there were some other events between >>> FileNum = FreeFile and Print #FileNum, pUser.FullName & "," & >>> then there is a room for error. >> ... >> >>>> Dim FileNum As Long >>>> FileNum = FreeFile >>>> lname = lpDataFolderName & pUser.Handle & ".txt" >>>> Open lname For Append As FileNum >>>> Print #FileNum, pUser.FullName & "," & AdjustedDate >> ... > > Daryl Muellenberg wrote:
> If you are sure that no other files are supposed to be open, then just do a But the point is that if it isn't unity and there's no intent for other > Close (without any parameters) before the FreeFile statement and that will > close all open files. The FreeFile statement should then assign 1 for > FileNum every time. .... files to be open, that's indicative that there's a bug somewhere that needs to be tracked down and is probably at least related to the symptoms if not the absolute cause. -- On Thu, 5 Mar 2009 14:11:22 -0500, "Kathy" <Kathy@kathy> wrote: Did you Shift-F9 to the line that caused the error? If not, the Err>Thank you. >I checked that yesterday and I could not find any missing Close statement >somewhere else. >Interestingly, when the error happened yesterday, I tried to do that: >in the debug state I moved code away from the offending line and I did this: >Close 1 >Close 2 >and then proceeded to the offending line. >The error was still there. object would retain the *previous* error, as opposed to a "no error" condition if the closing worked. FYI, the Reset command should close all open files, but I would only recommend that as a band-aid(tm). >Thanks, HTH,>Kathy J. Jeremiah D. Seitz Omega Techware http://www.omegatechware.net
Show quote
Hide quote
"Kathy" <Kathy@kathy> wrote in message When Print# or Put through that error, it means that file size has just news:%23Tp%23oZTnJHA.5228@TK2MSFTNGP02.phx.gbl... > Hello, > For years I haven't any problems with this code: > Dim FileNum As Long > FileNum = FreeFile > lname = lpDataFolderName & pUser.Handle & ".txt" > Open lname For Append As FileNum > Print #FileNum, pUser.FullName & "," & > AdjustedDate > --------------------- > > Suddenly, I started receiving error message: > "Run time error '52': > Bad file name or number" > and > Print #FileNum, pUser.FullName & "," & AdjustedDate > is highlighted exceeded 2 GB.
Scrollbars on Textbox -- how can I hide them?
The Myth of Visual Basic Migration / Upgrade Please help to translate this short Delphi code close excel from VB6 How difficult is to add my menu to Windows Explorer? Error Message Help Write in C global On Error Goto ? How to add new rows to Listview Get My Pictures Back |
|||||||||||||||||||||||