Page 1 of 1

Closing text file

Posted: Fri Feb 03, 2006 7:37 am
by Treoxx
Hello again,

I'm using the "Read from text file" action to read the magic out of the first line from the licensefile.
(I want to check if the licensefile is really a good one, after that the license file will be copied to the installationdir.)

So I only have to read the first line into a variable.

The file has to be closed after this.

Then I ((think I)) have 2 options to close the file.

1. Loop to read the whole file waiting at end of file:

label
Read Line
if not eof
goto label

(Not really nice when having a very big text file to read, but workable for me.)

2. Open a textfile what does not exist before opening the textfile. (again)

Number 2 is'nt a really nice option too.

Is there any better option to close the file?

Thanks!

Posted: Fri Feb 03, 2006 8:13 am
by MichaelNesmith
There should be no need to explicitly close a file...but I would recommend the reading from invalid file option as the quickest and easiest (and safest method, too!)

Posted: Fri Feb 03, 2006 9:06 am
by Treoxx
Michael,

I really!! need to close that file.
Here is the situation:

The user selects the licensefile.

I check the first row for the magic key to check if it is a good licensefile.

The first row is put in a variable, the variable will be checked if it has the right number etc.

the user goes forward and then back because he thinks he selected the wrong licensefile. But that wasn't true so he selects the same file as before

Because the file is still open, the command "read from text file" reads the SECOND line of the file. And there is no magic key.
So the variable will filled with wrong information and the test fails.

The invalid file works perfectly but it's not a really clean and nice option so I thought lets ask.

Posted: Fri Feb 03, 2006 10:19 am
by MichaelNesmith
Yeah, I understand! Don't worry invalid file is actually clean. No harm is done when file open fails - the setup engine checks for error conditions and handles them correctly.

Read From Text File - Label issue

Posted: Fri Dec 08, 2006 2:00 pm
by andrereg
Can you clarify what you are referring to by "reading from invalid file option"?

Is this a built-in command or a plugin i can download from somewhere?

I also have a problem with the "Read From Text File" command--I use it as follows to "Refresh" the list of databases available on a particular SQL database server:

<pseudocode>
Get Temporary File to TMP_DATABASES
Run Program OSQL -Q "SELECT name FROM master.dbo.sysdatabases" -o $TMP_DATABASES$
label: Read Database Names
Read from Text File $TMP_DATABASES$ into Variable READ (get EOF into EOF)
if Variable EOF Equals FALSE
// Do processing work, line-by-line
GoTo label: Read Database Names
end

<problem>
I want this block to be reusable inside and "Include script" because i need to do this more than once. Because the only way to read from a text file all the way is to use a "Label", my project won't compile with the following error:

---------------------------
Compile Error
---------------------------
LABEL re-defined: Read Database Names from server
---------------------------
OK
---------------------------

I see there is a "Wizard Loop" command, but it can only be used with "Show Dialog".
Is there *any* possibility that reading through a (non-.ini) text file can be done without using the label statement? (perhaps a "Loop" and "LoopExit" command?)

thanks!

Posted: Fri Dec 08, 2006 4:50 pm
by MichaelNesmith
Can you clarify what you are referring to by "reading from invalid file option"?
Just call Read from Text File, and specify an invalid file name that doesn't exist. This will close the currently open file and will not raise an error when it fails to open the new file.
LABEL re-defined: Read Database Names from server
Not clear on this one here...are you including the same script multiple times? I don't see why using this from an include script would be a problem.

Posted: Fri Dec 08, 2006 5:09 pm
by andrereg
Not clear on this one here...are you including the same script multiple times? I don't see why using this from an include script would be a problem.
Yes, i was wanting to use "Include Script" multiple times -- that is specifically what causes the problem. For now, I can workaround the issue by just repasting the necessary code multiple times in my main script and renaming the label to be unique each time i need to perform this task.

Example:
Load a list of databases,
User installs a clean database,
I need to refresh the database list to make sure the new database now shows up in the list.

sorry about the confusion,
thanks so much for your prompt reply![/quote]

Posted: Fri Dec 08, 2006 8:26 pm
by MichaelNesmith
I would keep the label and the goto statement outside of the include script. That way you can process the bulk of the task within the include script, and loop the actual task outside of it. Might that help?

Posted: Tue Dec 12, 2006 12:24 pm
by andrereg
MichaelNesmith wrote:I would keep the label and the goto statement outside of the include script. That way you can process the bulk of the task within the include script, and loop the actual task outside of it. Might that help?
No -- The *whole* of my task *is* the reading and parsing of the file. (which necessitates the label and the goto). There's no "bulk" of the work that can be moved out.

Fwiw, I'm needing to get part of a WiseScript package rewritten:
It uses something like an "Include Script" from Wise in order to repeat running a SQL query and parsing the output from the query out of a temp file many times; However, it relies on their "While loop" statement when reading from a file, so it doesn't have a problem with duplicate labels.

Are there any plans for a control statement besides IF/ELSE that would make tasks like this much easier to complete without using labels?

The only workaround i have at this point is to paste in the same code over and over again, and additionally go edit each label to be unique so that i can compile. Unfortunately, the parsing and reading of the file is more than a few lines so it quickly becomes a problem to manage in my main installation script.

If there are any other workarounds you can think of, let me know.
Thanks again for your help

Posted: Tue Dec 12, 2006 12:55 pm
by MichaelNesmith
Hey there Drew,

Yes I have added this as a feature request into our wish list. Hopefully we'll be seeing the new while/repeat constructs soon!