home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / sys / mac / hypercar / 4614 < prev    next >
Encoding:
Internet Message Format  |  1992-12-21  |  1.9 KB

  1. Path: sparky!uunet!olivea!spool.mu.edu!agate!apple!mumbo.apple.com!gallant.apple.com!kip2-42.apple.com!user
  2. From: jpugh@apple.com (Jon Pugh)
  3. Newsgroups: comp.sys.mac.hypercard
  4. Subject: Re: Initializing HC variables
  5. Message-ID: <jpugh-191292115205@kip2-42.apple.com>
  6. Date: 19 Dec 92 20:03:29 GMT
  7. References: <7183@ucsbcsl.ucsb.edu>
  8. Sender: news@gallant.apple.com
  9. Followup-To: comp.sys.mac.hypercard
  10. Organization: Apple Computer, Inc.
  11. Lines: 51
  12.  
  13. In article <7183@ucsbcsl.ucsb.edu>, sekey@engrhub.ucsb.edu (Andrew Sekey)
  14. wrote:
  15. >     Suppose we have an array of variables x1, x2, x3, etc, and we want to
  16. > initialize them to zero, i.e. to set:
  17. >     x1 = 0;  x2 = 0, ........xN = 0.
  18. >     Can this be done in a "repeat" structure?
  19. > (What would be obvious in e.g. Fortran, does not work:
  20. >     repeat with j = 0 to N
  21. >         put 0 into x & j
  22. >         end repeat
  23. > since even including a line  'put x & j into dummy', when followed by 
  24. > 'put 0 into dummy', will only change 'dummy', not xj.)
  25.  
  26. This is an ideal use of the DO command.
  27.  
  28. repeat with i = 0 to n
  29.   do "put 0 into x" & i
  30. end repeat
  31.  
  32. This allows you to execute any string you can build as a Hypertalk command.
  33. The only drawback is that it can't be compiled, but that's not much of a
  34. penalty given the effeciency of Hypertalk's compiler.  ;)
  35.  
  36. Here's a help script I wrote to place the name of a field into the field
  37. while saving its contents in a global.  This assumes the field names are
  38. single words which are legal variable names.
  39.  
  40. repeat with i = 1 to number of flds
  41.   do "global" && short name of fld i
  42.   do "put fld" && i && "into" && short name of fld i
  43. end repeat
  44.  
  45. -- and then to restore
  46.  
  47. repeat with i = 1 to number of flds
  48.   do "global" && short name of fld i
  49.   do "put" && short name of fld i && "into fld" && i
  50.   do "put" && quote & quote && "into fld" && i
  51. end repeat
  52.  
  53. Mind you, balloon help is better than this technique, but I think this
  54. shows how to use the do command quite nicely.
  55.  
  56. Jon
  57.