Runtime Error 55 trying to create a file
Runtime Error 55 trying to create a file
Runtime Error 55 trying to create a file
Runtime Error 55 trying to create a file
Runtime Error 55 trying to create a file
Runtime Error 55 trying to create a file Runtime Error 55 trying to create a file Runtime Error 55 trying to create a file Runtime Error 55 trying to create a file Runtime Error 55 trying to create a file Runtime Error 55 trying to create a file Runtime Error 55 trying to create a file Runtime Error 55 trying to create a file
Runtime Error 55 trying to create a file Runtime Error 55 trying to create a file
Runtime Error 55 trying to create a file
Go Back  Xtreme Visual Basic Talk > > > Runtime Error 55 trying to create a file


Reply
 
Thread Tools Display Modes
  #1  
Old 10-29-2013, 08:17 PM
fdates fdates is offline
Newcomer
 
Join Date: Jan 2005
Posts: 18
Default Runtime Error 55 trying to create a file


In the following code, I'm use a CommonDialog to locate a CSV file that I wish to parse out just the first column of data into a new file.

However, I get Error 55 "file open" for the line Open sPath + "SN" + .... even though the file does not exist yet.

This is driving me crazy!!!

Please. Someone tell me what I'm doing wrong.

Thanks.

Code:
Private Sub btnLoadData_Click()
Dim iFileNum1 As Integer
Dim iFileNum2 As Integer
Dim a$, o$
Dim sColumns() As String
Dim sFileName As String
Dim sDate As String
Dim sPath As String

    txtStatus.Text = ""
    
    
    CommonDialog1.Filter = "CSV (*.csv)|*.csv|All files (*.*)|*.*"
    CommonDialog1.DefaultExt = "csv"
    CommonDialog1.DialogTitle = "Select File"
    CommonDialog1.ShowOpen
    
    'The FileName property gives you the filename
    sFileName = CommonDialog1.FileName
    sDate = Format(Now(), "mmddyy")
    'sPath = Left$(sFileName, Len(sFileName) - Len(CommonDialog1.FileTitle))
    sPath = "e:\temp\"
    
    iFileNum1 = FreeFile
    iFileNum2 = FreeFile
    
    Open sFileName For Input As #iFileNum1
    Open sPath + "SN" + sDate + ".txt" For Output As #iFileNum2
    
    Line Input #iFileNum1, a$ 'read the column names (first line in file)
    
    While Not EOF(iFileNum1)
        Line Input #iFileNum1, a$
        sColumns = Split(a$, ",")
        Write #iFileNum2, sColumns(0)
    Wend
    
    Close #iFileNum1, #iFileNum2
    
    txtStatus.Text = "DONE!"

End Sub
Reply With Quote
  #2  
Old 10-29-2013, 09:06 PM
passel's Avatar
passelRuntime Error 55 trying to create a file passel is offline
Sinecure Expert

Super Moderator
* Guru *
 
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 8,026
Default

I believe iFileNum1 and iFileNum2 are the same value so you are trrying to use the same file handle for both Input and Output.
FreeFile will return the next available (unopened) file handle.
Since you didn't open a file after the first call to FreeFile, that handle is still available when you call FreeFile the second time.

iFileNum1 = FreeFile
Open sFileName For Input As #iFileNum1

iFileNum2 = FreeFile
Open sPath + "SN" + sDate + ".txt" For Output As #iFileNum2
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.
Reply With Quote
  #3  
Old 10-30-2013, 09:53 AM
fdates fdates is offline
Newcomer
 
Join Date: Jan 2005
Posts: 18
Default

Thank you. That seemed to get rid of the error.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Runtime Error 55 trying to create a file
Runtime Error 55 trying to create a file
Runtime Error 55 trying to create a file Runtime Error 55 trying to create a file
Runtime Error 55 trying to create a file
Runtime Error 55 trying to create a file
Runtime Error 55 trying to create a file Runtime Error 55 trying to create a file Runtime Error 55 trying to create a file Runtime Error 55 trying to create a file Runtime Error 55 trying to create a file Runtime Error 55 trying to create a file Runtime Error 55 trying to create a file
Runtime Error 55 trying to create a file
Runtime Error 55 trying to create a file
 
Runtime Error 55 trying to create a file
Runtime Error 55 trying to create a file
 
-->