cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

how to store data in a file using ACL

SOLVED
Highlighted
Newbie

how to store data in a file using ACL

HI,

     Can any one please help on how to store values in an external file using ACL, I have developed a dialog box window which contains combo box,drop down list, check boxes and other list variable and I want to store the assigned values to some file so that I can get and set same values when I load the document.

Thanks,

Prashant

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted

Re: how to store data in a file using ACL

Hi Prashant--

If you are getting duplicates, the first thing I would check would be to make sure you are not appending to an existing file when you should be creating a new file. If that checks out, then make sure you don't have a bug that causes your write code to get called more than once.

If you can have multiple copies in the data source, but only want to write each value once, then you'll have to do your own tracking in the ACL code to check each value before writing it. If it's just individual values you want to keep unique, you could create an associative array to track which ones have been written so you don't write them again. It would look something like this:

function write_unique(values[]) {

# open file, etc. omitted for brevity

# array for tracking used values

local used_values[];

local v;

for (v in values) {

   if (values[v] in used_values) {

     continue;

   }

   else {

     # this is a new one, write it to the file

     put(myfile, values[v]);

     # add it to the used values list

     used_values[values[v]] = 1;

  }

}

--Clay

View solution in original post

17 REPLIES 17
Highlighted

Re: how to store data in a file using ACL

Hi Prashant--

You can use the open(), put(), and close() functions to write information to external files in ACL. Or, if you prefer to save in XML format, you can use doc_open() and insert_tag() to create a new XML document in memory, which you can then save using either doc_save() or the write command. The online help should give you what you need to make these functions work.

--Clay

Highlighted

Re: how to store data in a file using ACL

Thanks Clay, I will go through that. Thank you very much.

Regards,

Prashnt

Highlighted

Re: how to store data in a file using ACL

HI Clay,

            I got the details how to write to the external file on Help Center, your valuable suggestion helped me a lot, thanks, with this I able to write to the .txt file if I want to write to the same to *.csv or excel file is there any way to do that by calling any function. I have gone mean while for the same in help center I couldn't able to find,

Thanks,

Prashant

Highlighted

Re: how to store data in a file using ACL

Clay,

        One more thing I missed in my previous mail is , when I write to the file it is taking long time to update the file,  its not getting content updated in the file after immediate action I performed. I there any thing I need to check to validate ? , please suggest.

This is the code written to update.

local path;

  path = open("D:/Testfile.txt","r+");

  #path = open("/test.csv","r+");

  put(path,item ." ". value . "\n");

Thanks,

Prashant

Highlighted

Re: how to store data in a file using ACL

Hi Prashant--

The put() command buffers output, so if you are writing small chunks of data each time, Arbortext may save it up in memory until it gets enough writes queued up to make it worth actually accessing the disk.

If you are just debugging, and wondering why the output file isn't updated when you call your function, I'd say don't worry about it. The buffering is usually a good thing, as it minimizes disk access and keeps things working efficiently. Just check the output file after the entire activity is done (i.e. you call close() on the output file you are creating) and you should find all the content you expect there (assuming there are no bugs, of course :-)).

If you really need to make sure the output file is updated in real time with each call to put(), you can use the flush() command to commit buffered writes. Doing this will increase frequency of disk access, so only do it if you really need it to work this way.

--Clay

Highlighted

Re: how to store data in a file using ACL

HI Clay,

              Due to not updating the values in the file, I am not able to validate with new modified value which is changed, because the changed value is not updated in the file immediate when I closed the dialog window. Is there any way to handle this ?. I am getting the value only when I close the Editor.

Thanks,

prashant

Highlighted

Re: how to store data in a file using ACL

Did you try using the flush() function as I recommended? You would need to add it after each put() that you want to immediately validate, something like this:

local path;

  path = open("D:/Testfile.txt","r+");

  #path = open("/test.csv","r+");

  put(path,item ." ". value . "\n");

flush(path);

Highlighted

Re: how to store data in a file using ACL

Clay,

        I Used the same as you said too, I mean flush(path) , after put() even I am facing same thing.

Thanks,

Prashant

Highlighted

Re: how to store data in a file using ACL

Hi Prashant--

Flush works for me. If I put() a string to a file, call flush(), and then examine the file, I see what I just wrote in the file. Is it possible that your code is not actually writing to the file, at least in some cases (or is writing an empty string)?

You might try adding some response() calls to debug your code, to make sure it is executing as you expect. Try checking the return value from put(), which will be -1 if the write failed.

--Clay

Highlighted

Re: how to store data in a file using ACL

Hi Prashant--

There's nothing particularly special about a CSV file--it's just a text file with strategically placed commas. So, if you want to write an Excel sheet something like this:

Header 1Header 2Header 3Header 4Header 5
OneABCD
TwoEFGH
ThreeIJKL

All you have to do is create the file with a .CSV extension, and write the following to it:

Header 1,Header 2,Header 3,Header 4,Header 5\n
One,A,B,C,D\n
Two,E,F,G,H\n
Three,I,J,K,L\n

Once you close the file, you should be able to open it in Excel and get what you expect. You can also embed formulas by preceding the value of an entry with an equal sign, e.g. "=SUM(A1:A25)", just as you would enter the formula in Excel.

One more thing, if the data in your table cells can contain commas, you will need to quote the cell contents, e.g.:

One,A,B,C,D,"Here is a comment, and it contains a comma."\n

--Clay

Highlighted

Re: how to store data in a file using ACL

Thanks Clay, its a gr8 explanation, thanks a lot ,I hope this works for me.

Prashant

Highlighted

Re: how to store data in a file using ACL

HI Clay,

            I am facing one issue on reading data from the file and assign the value in the dialog box, I have one text.csv file which have data like

  

Start when host application startson
Show splash screenoff
CurrentProfile1

I am not able to read the data line by line , I have written just like below

     local path,line;

     path = open("D:/Test/test.csv","r+");

     response(getline(path, line))  // getting null even though file contain three rows.

     while (getline(path, line) ) {

     // doing some thing.

}

could you please suggest on this.

Thanks,

Prashant

Highlighted

Re: how to store data in a file using ACL

Hi Prashant--

It's hard to say what's going wrong there. I don't see any obvious problems with your code. A few things to try:

1) Check the return value of open(), i.e. the value of $path to make sure it isn't -1, which would indicate that Arbortext can't open the specified file

2) Try opening the file in read only mode ("r" instead of "r+")

3) Make sure your CSV file is not open in any other program like Excel.

4) Check the contents of $main::ERRORS after you run this. It's possible some error is happening during the process; in that case you should see an entry in this array. (You can use join() to see all the entries, e.g. response(join($main::ERRORS)).)

The $line variable retains the line terminator (newline), so sometimes this can cause problems depending on how you use the variable. If you are getting an error about "unterminated string constant", that is likely to be the problem. To fix that, use chop($line) before you try to do anything else with it.

--Clay

Highlighted

Re: how to store data in a file using ACL

Thanks Clay, my issue is resolved now I able to read and write from the cvs file and I able to view the updated changes in the dialog box, but when I going on updating the values its creating duplicate for each value in the cvs file, is there any function to avoid to right duplicate values by using ACL.

Thanks.

Prashant

Highlighted

Re: how to store data in a file using ACL

Hi Prashant--

If you are getting duplicates, the first thing I would check would be to make sure you are not appending to an existing file when you should be creating a new file. If that checks out, then make sure you don't have a bug that causes your write code to get called more than once.

If you can have multiple copies in the data source, but only want to write each value once, then you'll have to do your own tracking in the ACL code to check each value before writing it. If it's just individual values you want to keep unique, you could create an associative array to track which ones have been written so you don't write them again. It would look something like this:

function write_unique(values[]) {

# open file, etc. omitted for brevity

# array for tracking used values

local used_values[];

local v;

for (v in values) {

   if (values[v] in used_values) {

     continue;

   }

   else {

     # this is a new one, write it to the file

     put(myfile, values[v]);

     # add it to the used values list

     used_values[values[v]] = 1;

  }

}

--Clay

View solution in original post

Highlighted

Re: how to store data in a file using ACL

Hi Prashant,

Can you confirm is Clay's input was able to get you through this issue?

If so, feel free to mark his answer as "Correct".  Thanks!

Highlighted

Re: how to store data in a file using ACL

Hi Rafael,

              The syntax and explanation given by Clay helped me a lot, in addition to that I have done some extra according my requirement , Thanks to Clay for giving gr8 explanation to follow the syntax for my logic to implement. Thanks Rafael,

With Regards,

Prashant Rao

Announcements