Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Open Different TXT files then put line for line into script 1

Status
Not open for further replies.

Stanggrn

Technical User
Feb 13, 2003
12
US
Needs some help with text files.

I am having trouble starting a script that will enable the user to choose which txt file for the script to run on.

Then after they choose it, it would TRANSMIT line for line with variables. (ie.. "+" at the end of the line means to continue to transmit the next line to word wrap)

Stanggrn
 
You can use the sdlgfopen command to display a dialog to let users select a file on the local machine. Be aware that there is some "screwiness" with this command on Win2K and XP such that the specified directory to look for files in is not the one used in the dialog.

You can use the strright command to get the last character of the string and see if it is a plus sign. If so, you could use strdelete to remove the plus sign, transmit the string, and then read and check the next string. If not, you would send the current string and I presume a carriage return and/or linefeed.


 
Thank you Knob,

Ok I have the dialog file open window come up where I can choose the file, but
How do I make the script read line by line in the file?
 
You would use code like this to open and read each line from the file:

if fopen 0 "name" TEXT
while not feof 0
fgets 0 sLine

your code goes here...

endwhile
endif

sLine is a string variable you would need to define at the beginning of your script and "name" would be the fully-qualified path to the text file you want opened.

 
Ok I think I have it working sort of. The only thing is is I get the following Error Message after I select the file:

Error 1: Value out of Range

After I click ok on the error message then it asks if I want to stop the script. If I tell it no it continues and stops everytime everytime I put in a wait for (ie.. OK)

I have tested this and it works all the way through, but you have to keep on clicking out of the error and keep the script working.

here is the script:

;Command for Performing Recent Changes in the 5ESS
string RCFile
string FileSpec
string SLine
integer Pos
integer Len




proc main
;transmit "rcd:apptext!,-^M"
;waitfor "OK"

;This allows user to choose the file to be read
FileSpec = "h:\*.*"
if sdlgfopen "Choose File" FileSpec SINGLE RCFile
else
call Error
endif

;The following reads the file that was selected previous
if fopen 0 "RCFile" READ
while not feof 0
fgets 0 sLine
strlen sLine Len
strchr sLine '+' Pos
strdelete sLine Len Pos

termwrites sLine
if waitfor "OK"
elseif waitfor "SET(.*)OK:"
elseif waitfor "FRL=(.*)<"
else
call Error1
endif
endwhile
endif
endproc

proc Error
usermsg "Please choose a valid file"
call main
endproc

proc Error1
usermsg "Please check the output, the switch has returned an error"
exit
endproc
 
Well I tried runnning the script that would have "Plus" symbols at the end of the line and that doesnt work either.

Please help
thanks
 
In your fopen command, remove the double quotes around RCFile and I think you will be OK. The double quotes tell ASPECT that this is a literal value instead of a variable.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top