Project

General

Profile

Help with $read reading a file in a subfolder

Added by mario salasar over 4 years ago

alias sinn {
var %file = $insert(files\.txt, $1 , 6)
var %lines = $lines(%file)
var %line 0

echo -a %line
while (%line < %lines) {
inc %line
echo -a $read(%file, %line)  <--line 19
pause 1
}
}

I'm having problems running this script "parameters not found in line 19".
Calling it like this "/sinn one".
%file = files\one.txt for some reason $read doesn't like like it.
Can anyone help?


Replies (2)

RE: Help with $read reading a file in a subfolder - Added by Per Amundsen over 4 years ago

Where is the $insert() identifier? Have you tried to /echo what the %file and %line variables looks like?

RE: Help with $read reading a file in a subfolder - Added by Paul Janson over 4 years ago

First step in debugging a script is to include debugging messages which tell you things like whether a particular line is being executed or not, and tells you the values of key variables or identifiers.

For example, if you have an error on line 19, insert a line above that with a command which creates a debugging message. Something like:

echo -a line $scriptline says % $+ file is %file

sometimes a message like this isn't enough to identify the problem, in case the problem is caused by leading, trailing, or double spaces, or even caused by control codes. In those cases, you might need something to give the ASCII value of each char in the string:

decimal: $regsubex(foo,%file,/(.)/g,$asc(\t) $+ $chr(32) )
hex: $regsubex(foo,%file,/(.)/g,$base($asc(\t),10,16,2) $+ $chr(32) )

Once you identify a variable having the wrong value, then you need to triangulate until you find where it's being set incorrectly or not being set at all.

    (1-2/2)