Thursday, May 27, 2010

create comma seperated file.

Use CommaIO file to create comma separated records or create CSV file.

create an instance of CommaIO and provide the operating mode.

These are the following modes, you can find it in FILE Macro under io_write.
'R' - Read
'W' - Write
'A' - Append
'T' - Translate
'B' - Binary

You need to assign the value of inrecorddelimeter.
and then use write method to write it. Multiple arguments can be passed in the write method of CommaIO.
CommaIO commaIO;
CustTable custTable;

//File name with the operating mode append.
commaIO = new CommaIO(@"C:\Cust.txt", 'A');
commaIO.inRecordDelimiter('\n');


while select CustTable
{
commaIO.write(custTable.AccountNum,custTable.AccountStatement, custTable.CashDisc);
}
Find the sample here.

read text file in axapta

TextBuffer is used to read the whole text file. Load file using textBuffer.fromFile and fetch the whole file string from the .getText

TextBuffer textBuffer;

textBuffer = new TextBuffer();
textBuffer.fromFile(@"C:\sohail.txt");
print textBuffer.getText();
pause;

Find the sample here.

create text file in axapta


Use BinData class to create a simple text file using axapta.
Firstly create an instance of a TextBuffer class and append text using textBuffer.AppendText. Pass it to binData what you want to write using binData.setStrData and then write using binData.saveFile.

Sample

BinData binData;
TextBuffer textBuffer;

textBuffer = new TextBuffer();
textBuffer.setText('This is a demo program');

binData = new BinData();
binData.setStrData(textBuffer.getText());
binData.saveFile(@"c:\sohail.txt");

Demo is attached here.