I originally built a desktop application using Real Studio (final version) which works fine.
The application has an option to import a CSV file into a Listbox which works very well when built with Real Studio
When I open the file and then compile the same app with Xojo and try importing the same CSV file I get:
An exception of class IOException was not handled.
The application must shut down. Exception Error Number: 2
The CSV parse function looks ok and works well in Real Studio - I can’t see what it could be…
Any idea what this exception even means?
I’m running Xojo 3.1 on a MAC running Mavericks 10.9.2
OK - this is the breakpoint line:
Textln = TextInputStream.Open(f)
Where f is a FolderItem (the CSV files name and path) and Textln is a TextInputStream
Here’s the CSV parsing code that works fine in Real Studio
Dim f as FolderItem
Dim TextIn As TextInputStream
Dim count,i,r, x As Integer
Dim line,c,s As String
//To strip off any enclosing quotes use this instead
//s = Mid(c,2,(x-2))
// put the data in the cell
List.Cell(r,(i)) = s
Next
Loop Until TextIn.EOF = True
End If
Else
// error message
MsgBox "Error Reading input file: " + FileName
End If
What does “f” point to? Is it a valid file? An IOException like this typically indicates the file cannot be accessed (permissions) or perhaps isn’t available. Or perhaps it is open by another app and is locked?
Difference between Folderitem.exists and folderitem <> nil:
f <> nil means that the path is correct (and there could be a file at the end of the path!)
f.exists should be used to know if the file exists on the volume.
Let say you want to create a file MyFile.
f=getfolder(“pathtomyfile:myfile”)
f is not nil, but f.exists is false (unless myfile soon exists in the folder).
OK figured it out…Heres the import button code
The line that reads
pName = f.AbsolutePath
used to be…
pName = f.NativePath
I changed it to this because Xojo was telling me that it was a depreciated item.
ImportList is a method that contains a parse routine for the CSV file
Dim dlg as OpenDialog
Dim f as FolderItem
Dim fName,pName As String
dlg=New OpenDialog
dlg.InitialDirectory= SpecialFolder.Desktop
dlg.Title = “Select a CSV text file”
dlg.Filter = “Text Documents (*.csv)” // file type defined in File
f=dlg.ShowModal()
If f <> Nil then
fName = f.Name
pName = f.AbsolutePath
ImportList(fName,pName,PasswordGen.ListBox1)
Else
//User Cancelled
exit
End if