Hi,
i'm importing fields from a csv file like this:
Robert White,Naples,0001
Eric Red,Washington,0002
Peter Green,Paris,0003
I can't understand why I need to put a carriage return on the first line to have all three rows imported.
And I can't understand why it also reads an "extra row" filled with zeros in the end.
So my output is basically:
Robert White,Naples,0001
Eric Red,Washington,0002
Peter Green,Paris,0003
0,0,0
Is there a particular behaviour for this object? Documentation from Microsoft is quite poor about it...
This is my code:
static void CommaIO(Args _args)
{
FileName fileName = 'C:\\Users\\note98\\Desktop\\testdata.csv';
CommaIo csvFile;
container readCon;
str column1,column2,column3;
;
csvFile = new CommaIo(filename, 'r');
csvFile.inFieldDelimiter(','); // Delimiter...
if (csvFile)
{
readCon = csvFile.read();
while (csvFile.status() == IO_Status::OK)
{
readCon = csvFile.read();
column1 = conPeek(readCon, 1);
column2 = conPeek(readCon, 2);
column3 = conPeek(readCon, 3);
info(strFmt("%1 - %2 - %3", column1, column2, column3));
}
}
}
*This post is locked for comments
CommaIO class is still working, but the FileIO class is totally replaced.
I am practicing with Microsoft DevIII-02 course and I found this example.
Error: FileIO class Missing
FileIoPermission permission;
FileIO fileIO;
str outputText;
#File
;
permission= new FileIoPermission(filename,#io_write);
permission.assert();
fileIO= new FileIO(filename, #io_write);
if (fileIO)
{
outputText = "text that will go into the text file.";
fileIO.write(outputText); //write the text to the
file.
fileIO.finalize(); //finish the file.
}
I faced the same problem.
Here is how I solved this issue. I think it is not the proper way to use while statement
readCon=commaIO.read();
while (readCon)
{
column1=conPeek(readCon,1);
column2=conPeek(readCon,2);
column3= conPeek(readCon,3);
info(strFmt('%1-%2-%3',column1,column2,column3));
readCon = commaIO.read();
}
Thank you for your help.
I finally fixed it!
Think about what your code does. It:
By the way, CommaIo class was replaced by CommaTextIo.
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,219 Super User 2024 Season 2
Martin Dráb 230,056 Most Valuable Professional
nmaenpaa 101,156