home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Spezial
/
SPEZIAL2_97.zip
/
SPEZIAL2_97.iso
/
ANWEND
/
DEVELOP
/
RIO111
/
guru.doc
next >
Wrap
Text File
|
1996-08-27
|
4KB
|
142 lines
T h e G u r u ' s C o r n e r ! (V 1.0)
This file has been thought as a "drag'n'drop" container
for examples and working code in general.
* * Adopt a newbie! * *
Do you have some bits of code created with NetREXX that you
want to share with other NetRexx or Java programmers?
E-mail them at the RXFile author! Credits will be given to whom
will contribute. See RXFile.doc for details.
Index of the Guru's answers to Frequently Asked Questions.
The name of the contributor is just under the question. If there is no
name, it is assumed that the RXFile author provided that Guru's answer.
Once you've targetted the topic of interest, just search with your
favorite editor's SEARCH function the question number you're
interested in (i.e. Q1, Q2, etc).
How can I..
Q1. ..Get the user input in a text mode environment, showing text before the prompt?
Q2. ..Read an entire binary or ASCII file, byte by byte?
Q3. ..Read an entire ASCII file line by line?
Q4. ..Open a file with separate Read/Write cursors and position these cursors?
Q5. ..Get a directory listing, and print it in a text mode environment?
The Guru's answers to Frequently Asked Questions:
How can I..
Q1. ..Get the user input in a text mode environment, showing text before the prompt?
A1.
-----------CUT HERE---------8<--------------------8<--------CUT HERE-----------
rxConsole = RXFile()
rName = Rexx null
loop until rName.length() \= 0
say 'Please enter your name..'
ok = rxConsole.charout("Name>")
rName = rxConsole.linein()
end
-----------CUT HERE---------8<--------------------8<--------CUT HERE-----------
Note: this little chunk of code won't exit until the user writes something (ie it loops if the
user simply hits 'ENTER', 'RETURN' or whatever you call it).
The user input is stored in the rName variable.
Q2. ..Read an entire binary or ASCII file, byte by byte?
A2.
-----------CUT HERE---------8<--------------------8<--------CUT HERE-----------
rxInputFile = RXFile()
rChar = Rexx null
ok = rxInputFile.stream("foo.txt", "c","open read")
loop while rxInputFile.chars() > 0
rChar = rxInputFile.charin()
/*
Insert here the code to handle the
character we've just read, 'rChar'.
*/
end
-----------CUT HERE---------8<--------------------8<--------CUT HERE-----------
Note: Obviously you'll have to change "foo.txt" with the file name you're interested in.
Q3. ..Read an entire ASCII file line by line?
A3.
-----------CUT HERE---------8<--------------------8<--------CUT HERE-----------
rxInputFile = RXFile()
rLine = Rexx null
ok = rxInputFile.stream("foo.txt", "c","open read")
loop while rxInputFile.lines() > 0
rLine = rxInputFile.linein()
/*
Insert here the code to handle the
line we've just read, 'rLine'.
*/
end
-----------CUT HERE---------8<--------------------8<--------CUT HERE-----------
Note: Obviously you'll have to change "foo.txt" with the file name you're interested in.
Q4. ..Open a file with separate Read/Write cursors and position these cursors?
A4.
-----------CUT HERE---------8<--------------------8<--------CUT HERE-----------
RXIt = RXFile()
bSepCurs = boolean 1
bRN = boolean 1
say RXIt.setparms(bSepCurs, bRN)
say 'Opening: ' RXIt.stream('foo.txt','c','open')
say 'R-seeking at =1 returns: 'RXIt.stream('c','rseek =1')
say 'W-seeking at <0 brings: 'RXIt.stream('c','wseek <0')
-----------CUT HERE---------8<--------------------8<--------CUT HERE-----------
Note: as ever, change "foo.txt" with the file name you're going to work with,
and "=1", "<0" with the appropriate offsets.
Note2: For more details on the R-seeking and W-seeking options of the
STREAM command, refer to the RXFile documentation (RXFile.doc).
Q5. ..Get a directory listing, and print it in a text mode environment?
A5.
-----------CUT HERE---------8<--------------------8<--------CUT HERE-----------
rArray = Rexx[] null
RXIt = RXFile()
bExit = boolean 0
iCount = int 0
rArray = RXIt.filetree("c:\os2")
loop until bExit = 1
say rArray[iCount]
iCount = iCount + 1
catch AIOOBE=ArrayIndexOutOfBoundsException
bExit = 1
end
-----------CUT HERE---------8<--------------------8<--------CUT HERE-----------
EOF