Wonderware archestra quickscript problem

joaco1993

Lifetime Supporting Member
Join Date
Sep 2014
Location
newyork
Posts
237
Hi ! im having some trouble with the following code..

------------------------------------------------------------------------
dim sr as System.IO.StreamReader;
dim readtag as string;
dim line as string;
dim line2 as string;
System.IO.File.Delete("C:\Recipe2.txt");
System.IO.File.Copy("C:\Users\joaco\Documents\workorders\Recipe.txt","C:\Recipe2.txt");


sr = System.IO.File.OpenText("C:\Recipe2.txt");
line = "";
ListBox1.Clear();
while line <> null
line=sr.ReadLine();
line=Stringmid(line,2,20);

if line.Equals("") then
else
ListBox1.AddItem(line);
endif;
endwhile;
sr.Close();
------------------------------------------------------------------------

this script is in a button, each time is pressed i want the file recipe2 to be deleted and be copied again from recipe1.

First time i press the button it works fine.. and the file is created and I see the values in the listbox.

But when I press again, the file doesnt get deleted because it says is being use by window viewr.... dont undestand why.. because at the end of the script i put the command sr.close() so the file shouldnt be in use anymore..

any ideas ??

thanks !!
 
It seems to me that the while line <> null is where it would be hanging. When would it be set back to null? I always like to add logging to see where in the code I am getting. Try adding logmessage("something useful"); right before the sr.close() to see if it ever makes it to that line. Check the systemanagment console logging to view the message. If you don't see it then its not getting there.
 
Hi scott, you are right!
I never get out of the while, do you find any other way of doing this?
I want to read from first line to the last one before an empty line..

Supose the txt is the following

Line1-testt1
Line2-hello
Line3-test2
Line4-empty
-
-
-
Line n - empty

I just want to read the first threee lines
 
If you actually have lines that exist in the file that have nothing in them except a CR/LF then I would suggest that you use the line.equals("") to exit your loop.

But, if you're looking to process the file until the end of file, something like this to examine if you've reached EOF:
while ( sr->Peek() >= 0 )
{
Console::WriteLine( sr->ReadLine() );
}
see this as a reference:
https://msdn.microsoft.com/en-us/li...spx?cs-save-lang=1&cs-lang=cpp#code-snippet-2
 

Similar Topics

Hi All I'm a novice starting to work on WW and Archestra, I've been adding repetitive attributes on the front end which has been tedious and was...
Replies
4
Views
2,087
Hey I was needing help with some alarm scripting in Woderware System Platform. What would be the best way to write a script to auto acknowledge...
Replies
2
Views
2,544
I am trying to create a script in an Archestra graphic that will eventually talk to an Omron PLC. I need to access the elements that I create for...
Replies
0
Views
1,618
The application is not getting deployed after a power failure. After the power got restored, I tried to deploy an updated instance but the...
Replies
1
Views
4,037
I have to work on a Wonderware HMI and have very little experience with it. The basic idea is to copy an old project, make a few edits, and load...
Replies
7
Views
4,915
Back
Top Bottom