TN Appsvr116 Reading a CSV file into AppServer UDA's
Last updated: March 6th, 2025Description
- Author: Brian Schneider
- Published: March 6th, 2025
Details:
Description
This is a simple scripting example to demonstrate how to read a CSV file into UDA arrays. The scripting uses QuickScript .NET functions and is intended for Application Server.
Before you Begin
Create the required UDA array for each column in the CSV file, if not already existing.
Detailed Steps
There are many options in .NET for reading CSV files. The scripting example given here uses
the System.IO.StreamReader class. It is built for a three column CSV file as shown below.
Each line of the CSV file is read in using the ReadLine method. The columns are parsed out
using the various String methods. A while loop looks for the end of the file using the Peek
method. Below is a screen capture from the IDE.
The following is the example scripting used.
dim s as string;
dim sr as System.IO.StreamReader;
dim stringlength as integer;
dim firststring as string;
dim secondstring as string;
dim thirdstring as string;
dim remainderstring as string;
dim index as integer;
sr = System.IO.File.OpenText("c:\csvtest2.txt");
while sr.Peek() > -1
index = index + 1;
s = sr.ReadLine();
LogMessage(s);
stringlength = StringInString(s, ",", 1, 0);
firststring = StringMid(s,1,stringlength-1);
me.FirstUDA[index] = firststring;
remainderstring = StringRight(s, StringLen(s) - stringlength);
stringlength = StringInString(remainderstring, ",", 1, 0);
secondstring = StringMid(remainderstring,1,stringlength-1);
me.SecondUDA[index] = secondstring;
thirdstring = StringRight(remainderstring, StringLen(remainderstring) -
stringlength);
me.ThirdUDA[index] = thirdstring;
endwhile;
me.ParseIT = 0;
The object hosting the script was deployed from the IDE and tested out from the Object Viewer.
Each column has been parsed out to their respective UDA.