Opentextfile Error 52
Contents |
Bad file name or number" when i open associated text file If this is your first visit, be sure to check out the FAQ by clicking the link above. runtime error 52 bad filename or number in vb6 You may have to register before you can post: click the register link
Runtime Error 52 Bad Filename Or Number Fix
above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.
Runtime Error 52 Fix
Results 1 to 10 of 10 Thread: [RESOLVED] "Run time error '52': Bad file name or number" when i open associated text file Tweet Thread Tools Show Printable Version Subscribe to this Thread…
Runtime Error 52 Excel Macro
Display Linear Mode Switch to Hybrid Mode Switch to Threaded Mode Mar 2nd, 2010,10:26 AM #1 daveinarmstrong View Profile View Forum Posts Visit Homepage Thread Starter Addicted Member Join Date Dec 2009 Location B.C. Canada Posts 206 [RESOLVED] "Run time error '52': Bad file name or number" when i open associated text file i am getting error "Run time error '52': Bad file name or number" visual basic 6.0 setup toolkit runtime error 52 when i use this code to open a text file that is accociated with my app. File association is set up using inno. when i replace Command$ with "C:\Users\Dave\Documents\dave.cppl" and run it in design mode there is no error. Code: Private Sub Form_Load() Dim DoubleClickedFile As String Dim sFileText As String Dim iFileNo As Integer DoubleClickedFile = Command$ If DoubleClickedFile <> "" Then DoubleClickedFile = Mid(DoubleClickedFile, 4, Len(DoubleClickedFile) - 3) Text1.Text = DoubleClickedFile 'to check if the file and path is good iFileNo = FreeFile Open DoubleClickedFile For Input As #iFileNo Input #iFileNo, sFileText Text1.Text = sFileText Close #iFileNo End If End Sub Reply With Quote Mar 2nd, 2010,10:33 AM #2 RhinoBull View Profile View Forum Posts PowerPoster Join Date Mar 2004 Location New Amsterdam Posts 24,135 Re: "Run time error '52': Bad file name or number" when i open associated text file What does Command$ return? Place break pointer right on that line and you will see the actual value. Or you can at least print value to debug (Debug.Print DoubleClickedFile). Microsoft MVP - Visual Basic 2006-2013 Why VB clears the clipboard on startup and how to avoid it? . Filtering Arrays .
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or error 52 driver posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss bad filename or number access import Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only runtime error 52 bad file name or number vba takes a minute: Sign up VBA write to text file: Run-time error 52 'bad file name or number' up vote 2 down vote favorite Public Sub EdgeColor_Click() Dim intInFile As Integer intInFile = FreeFile Open "c:\picturename.csv" For Output As #intFileNo Print http://www.vbforums.com/showthread.php?605576-RESOLVED-quot-Run-time-error-52-Bad-file-name-or-number-quot-when-i-open-associated-text-file #intFileNo, "test" Close #intFileNo End Sub This is my code, and I get Run-time error 52 'bad file name or number'. I've tried doing as Input and making the file exist but I get the same error. This is VBA inside of a Proficy iFix graphic, and can't for the life of me figure out what I am doing wrong. vba share|improve this question edited Mar 11 '12 at 19:48 Joel Coehoorn 249k92440662 asked Jun 10 '11 at 2:53 rolls 3582725 http://stackoverflow.com/questions/6301495/vba-write-to-text-file-run-time-error-52-bad-file-name-or-number add a comment| 1 Answer 1 active oldest votes up vote 10 down vote accepted You're mixing up intInFile and intFileNo. It's possible that intFileNo is simply set to zero if you're not using the option explicit command, which may explain the invalid number. That little command goes at the top of every one of my VB/VBA files because I've been burnt by this so many time before. share|improve this answer edited Jun 10 '11 at 13:17 answered Jun 10 '11 at 2:58 paxdiablo 491k1189731422 1 Wow I am completely retarded, I have no idea how I didn't realise that. Also I didn't know you could use option explicit in VBA, thank you so much. :) –rolls Jun 10 '11 at 3:02 1 @rolls, you can also go to Tools - Options... - Editor tab - then check Require Variable Declaration to have Option Explicit turned on by default for all new modules. –Cheran Shunmugavel Jun 10 '11 at 4:41 add a comment| Your Answer draft saved draft discarded Sign up or log in Sign up using Google Sign up using Facebook Sign up using Email and Password Post as a guest Name Email Post as a guest Name Email discard By posting your answer, you agree to the privacy policy and terms of service. Not the answer you're looking for? Browse other questions tagged vba or ask your own question. asked 5 years ago viewed 10528
213 Scores: 0 Reward points : 0 Joined: 3/10/2009Location: Seattle, WA Status: offline VBscript error caused by http://www.visualbasicscript.com/VBscript-error-caused-by-open-file-m88294.aspx open file Tuesday, January 04, 2011 5:04 AM (permalink) 0 Hi, I wrote a script that does an application installation and outputs messages to a log file http://www.tek-tips.com/viewthread.cfm?qid=1013685 as the script progresses. If I run the script and it fails due to a runtime issue, the line that closes the log file never runs which error 52 leaves the file open and locked. How would I capture the error when the script fails at the open log file step and perform any additional steps? I'm thinking I should capture the error, if an error condition exists, close the open file and then reattempt opening the file again so the script can continue runtime error 52 normally. The failure I am trying to address occurred at "Set objFile = objFSO.CreateTextFile(strDirectory & strFile)". Here is a code snippet: Dim objFSO, objFolder, objShell, objLogFile, objFile Dim strDirectory, strFile 'Variables used for storing current date and time to enter in the log Dim dateStamp, timeStamp dateStamp = Date() timeStamp = Time() 'Declare and initialize variables needed for log file output strDirectory = "c:\Windows\Temp\" strFile = "Microsoft_Lync.log" 'Create the File System Object Set objFSO = CreateObject("Scripting.FileSystemObject") 'Create log file (replaces existing log file) Set objFile = objFSO.CreateTextFile(strDirectory & strFile) 'Open log file for writing Set objFile = Nothing Set objFolder = Nothing Set objLogFile = objFSO.OpenTextFile (strDirectory & strFile, 2, True) 'Output time and date stamps to log file objLogFile.WriteLine(timeStamp & " " & dateStamp) objLogFile.WriteLine 'Close log file objLogFile.Close Thanks for your help! Rob
FORUMSFOR COMPUTER PROFESSIONALS Log In Come Join Us! Are you aComputer / IT professional?Join Tek-Tips Forums! Talk With Other Members Be Notified Of ResponsesTo Your Posts Keyword Search One-Click Access To YourFavorite Forums Automated SignaturesOn Your Posts Best Of All, It's Free! Join Us! *Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail. Posting Guidelines Promoting, selling, recruiting, coursework and thesis posting is forbidden.Tek-Tips Posting Policies Jobs Jobs from Indeed What: Where: jobs by Link To This Forum! Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.Just copy and paste the BBCode HTML Markdown MediaWiki reStructuredText code below into your site. Visual Basic(Microsoft): Version 5 & 6 Forum at Tek-Tips HomeForumsProgrammersLanguagesVisual Basic(Microsoft): Version 5 & 6 Forum Runtime error '52' thread222-1013685 Forum Search FAQs Links MVPs Runtime error '52' Runtime error '52' JohnKIT05 (TechnicalUser) (OP) 25 Feb 05 13:34 I am new to VB and I am enjoying learning this new programming. Anyway I am getting a runtime error '52' message on my screen which it says "Runtime error '52' Bad file name or number". I am not sure what it the problem is. I copied and paste my program which is shown below.Sub Openfile()Const ForReading = 1, ForWriting = 2Dim fs, f, r, fread, Maxsize, Nextchar, MycharSet fs = CreateObject("Scripting.FileSystemObject")Set r = fs.OpenTextFile("c:\850whsetest.tmp", ForReading)'Set w = fs.OpenTextFile("c:\850whsetest.tmp", ForWriting)fread = r.readlineInput #1, fread'Maxsize = LOF(1)Do While i < 14Seek #1, iMychar = Input(1, #1)Select Case iCase 8If Mychar >= 0 Thenr.Write ("A")End IfCase 9If Mychar >= 0 Thenr.Write ("M")End IfCase 10If Mychar >= 0 Thenr.Write ("P")End IfCase 11If Mychar >= 0 Thenr.Write ("H")End IfEnd SelectLoopr.CloseEnd Sub RE: Runtime error '52' ArtieChoke (Programmer) 25 Feb 05 13:37 You're mixing different methods for reading the file. You can't use Input #1, fread with the file scripting object. "I t