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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

New to Rexx Scripting

Status
Not open for further replies.

gmeikle

Technical User
Nov 6, 2013
10
GB
Hi,

I have been using Rexx scripting for a little while for very basic scripts for "copying & pssting" information from a text file into a third party application.

I tried using the ZocGetFilename commannd, i.e. file= ZocGetFilename(Select file to Upload: ", "*.txt"), but I cannot see to get it to work correctly.

I am trying to amend the script below so that when I run the script it will do the following:

1) Open a window to select the filename to use
2) Get the window to open in a specific default location, i.e. the "ZOC6 Files" folder where the scripts are located
3) Exit the script if a file is not selected, i.e. open command is cancelled.
4) Ignore the first two records within a file if it is selected are these are the header information from the Excel document the text file was generated from.

Any help would be much appreciated

/* REXX */

file = "C:\Users\Name\Documents\ZOC6 Files\User Names.txt"
tabchar = '09'x
do while( lines(file) )

data=LINEIN(file)

Parse Var data v1 (tabchar) v2

CALL ZocSend v1
CALL ZocSend "^M"
CALL ZocSend "f"
CALL ZocSend "^M"
CALL ZocDelay 1

CALL ZocSend "^Z"
CALL ZocDelay 1

CALL ZocSend v1
CALL ZocSend "^I"
CALL ZocDelay 1

CALL ZocSend v2
IF LENGTH(v2) < 20 THEN DO
CALL ZocSend "^I"
END
CALL ZocDelay 1

CALL ZocSend "^M"
CALL ZocSend "a"
CALL ZocSend "^M"
CALL ZocDelay 1

CALL ZocSend "^Z"
CALL ZocDelay 1

END
 
I tend to use excel and save as CSV and pull info from that for scripts also sections rather than DO. If you want to skip a couple of lines you could use a variable an example would be this

/*REXX*/

new= ZocGetFilename("Select file to upload", "c:\csv\*.csv")
IF new="##CANCEL##" THEN CALL LEAVE
x = 0
LOOP:
x = x + 1
fileid = linein(new)
PARSE VALUE fileid WITH v1","v2","v3","v4 /*example for a 4 column excel*/
IF x > 2 THEN CALL LOOP
IF v1 = "" THEN CALL finish

stuff you want to do inside the loop

CALL LOOP

finish:
EXIT
 
I don't kmow what flavour of rexx you use but rexx does not have sections - it has sub-routines. Your LOOP: is jsut a label - if it was after the EXIT statement then it would be a sub-routine.
LEAVE is a keyword not a function so you cannot call it. You shouldn't call finish but SIGNAL finish. Wjhy are you calling LOOP recursively and not gracefully returning through its calls clearing the stack as you go?

You probably need a DO loop - maybe FOREVER and ITERATE if x>2 or LEAVE if v1 = ""
So, probably:
[pre]/* rexx */
x = 0
new= ZocGetFilename("Select file to upload", "c:\csv\*.csv")
IF new <> "##CANCEL##"
THEN DO FOREVER
x = x + 1
fileid = linein(new)
PARSE VALUE fileid WITH v1","v2","v3","v4 /*example for a 4 column excel*/
IF x > 2 THEN ITERATE
IF v1 = "" THEN LEAVE

stuff you want to do inside the loop

END

EXIT[/pre]


Nic
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top