home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / rio111.zip / guru.doc < prev    next >
Text File  |  1996-08-28  |  4KB  |  142 lines

  1. T h e   G u r u ' s   C o r n e r !   (V 1.0)
  2.  
  3. This file has been thought as a "drag'n'drop" container
  4. for examples and working code in general.
  5.  
  6.             * *  Adopt a newbie!  * *
  7. Do you have some bits of code created with NetREXX that you
  8. want to share with other NetRexx or Java programmers?
  9. E-mail them at the RXFile author! Credits will be given to whom
  10. will contribute. See RXFile.doc for details.
  11.  
  12.  
  13.  
  14. Index of the Guru's answers to Frequently Asked Questions.
  15.  
  16. The name of the contributor is just under the question. If there is no
  17. name, it is assumed that the RXFile author provided that Guru's answer.
  18.  
  19. Once you've targetted the topic of interest, just search with your
  20. favorite editor's SEARCH function the question number you're
  21. interested in (i.e. Q1, Q2, etc).
  22.  
  23. How can I..
  24.  
  25. Q1. ..Get the user input in a text mode environment, showing text before the prompt? 
  26. Q2. ..Read an entire binary or ASCII file, byte by byte?
  27. Q3. ..Read an entire ASCII file line by line?
  28. Q4. ..Open a file with separate Read/Write cursors and position these cursors?
  29. Q5. ..Get a directory listing, and print it in a text mode environment?
  30.  
  31.  
  32.  
  33. The Guru's answers to Frequently Asked Questions:
  34.  
  35. How can I..
  36.  
  37.  
  38. Q1. ..Get the user input in a text mode environment, showing text before the prompt? 
  39. A1.
  40.  
  41. -----------CUT HERE---------8<--------------------8<--------CUT HERE-----------
  42.  rxConsole = RXFile()
  43.  rName = Rexx null
  44.  
  45.  loop until rName.length() \= 0
  46.    say 'Please enter your name..'
  47.    ok = rxConsole.charout("Name>")
  48.    rName = rxConsole.linein()
  49.  end
  50. -----------CUT HERE---------8<--------------------8<--------CUT HERE-----------
  51.  
  52. Note: this little chunk of code won't exit until the user writes something (ie it loops if the
  53. user simply hits 'ENTER', 'RETURN' or whatever you call it).
  54. The user input is stored in the rName variable.
  55.  
  56.  
  57. Q2. ..Read an entire binary or ASCII file, byte by byte?
  58. A2.
  59.  
  60. -----------CUT HERE---------8<--------------------8<--------CUT HERE-----------
  61.  rxInputFile = RXFile()
  62.  rChar = Rexx null
  63.  
  64.  ok = rxInputFile.stream("foo.txt", "c","open read")
  65.  
  66.  loop while rxInputFile.chars() > 0
  67.   rChar = rxInputFile.charin()
  68.   /*
  69.      Insert here the code to handle the
  70.      character we've just read, 'rChar'.
  71.   */
  72.  end
  73. -----------CUT HERE---------8<--------------------8<--------CUT HERE-----------
  74.  
  75. Note: Obviously you'll have to change "foo.txt" with the file name you're interested in.
  76.  
  77.  
  78. Q3. ..Read an entire ASCII file line by line?
  79. A3.
  80.  
  81. -----------CUT HERE---------8<--------------------8<--------CUT HERE-----------
  82.  rxInputFile = RXFile()
  83.  rLine = Rexx null
  84.  
  85.  ok = rxInputFile.stream("foo.txt", "c","open read")
  86.  
  87.  loop while rxInputFile.lines() > 0
  88.   rLine = rxInputFile.linein()
  89.   /*
  90.      Insert here the code to handle the
  91.      line we've just read, 'rLine'.
  92.   */
  93.  end
  94. -----------CUT HERE---------8<--------------------8<--------CUT HERE-----------
  95.  
  96. Note: Obviously you'll have to change "foo.txt" with the file name you're interested in.
  97.  
  98.  
  99. Q4. ..Open a file with separate Read/Write cursors and position these cursors?
  100. A4.
  101.  
  102. -----------CUT HERE---------8<--------------------8<--------CUT HERE-----------
  103. RXIt = RXFile()
  104. bSepCurs = boolean 1
  105. bRN = boolean 1
  106.  
  107. say RXIt.setparms(bSepCurs, bRN)
  108.  
  109. say 'Opening: ' RXIt.stream('foo.txt','c','open')
  110.  
  111. say 'R-seeking at =1 returns: 'RXIt.stream('c','rseek =1')
  112. say 'W-seeking at <0 brings: 'RXIt.stream('c','wseek <0')
  113. -----------CUT HERE---------8<--------------------8<--------CUT HERE-----------
  114.  
  115. Note: as ever, change "foo.txt" with the file name you're going to work with,
  116. and "=1", "<0" with the appropriate offsets.
  117. Note2: For more details on the R-seeking and W-seeking options of the
  118. STREAM command, refer to the RXFile documentation (RXFile.doc).
  119.  
  120.  
  121.  
  122. Q5. ..Get a directory listing, and print it in a text mode environment?
  123. A5.
  124.  
  125. -----------CUT HERE---------8<--------------------8<--------CUT HERE-----------
  126. rArray = Rexx[] null
  127. RXIt = RXFile()
  128. bExit = boolean 0
  129. iCount = int 0
  130.  
  131. rArray = RXIt.filetree("c:\os2")
  132. loop until bExit = 1
  133.  say rArray[iCount]
  134.  iCount = iCount + 1
  135. catch AIOOBE=ArrayIndexOutOfBoundsException
  136.  bExit = 1
  137. end
  138. -----------CUT HERE---------8<--------------------8<--------CUT HERE-----------
  139.  
  140.  
  141. EOF
  142.