TIP: Click on subject to list as thread! ANSI
echo: power_bas
to: TIM HUTZLER
from: BOB SEWELL
date: 1996-06-17 22:22:00
subject: Passing a field

 While translating the works of Dr. Suess into latin, Tim Hutzler said:
 TH> TYPE xs
 TH>     str AS STRING * 15
 TH> END TYPE
 TH> DIM t AS xs
 TH> t.str = "This is a test."
 TH> SUB pout (x%, x$, y AS xs)
 TH>     PRINT x%, x$, y
 TH>     y = "vxvxvxv."
 TH> END SUB
 TH> DO
 TH>  INCR x%
 TH>     y$ = MID$(t.str, x%, 1)
 TH>     POUT x%, y$, t.str
 TH> LOOP UNTIL y$ = "."
 TH> ==================================================================
 TH> I get a 481 error. What do you get?
    I also get that error.  And yes, QB won't give an error.
 But it can lead to sloppy programming.  What if your 'xs'
 structure contained more elements than the fixed-length
 string?  If xs (and also t) was of the following TYPE:
  TYPE xs
     i AS INTEGER
     str AS STRING * 15
  END TYPE
  DIM t AS xs
    ...you can't very well pass t.str to your y variable
 then, because the SUB will be expecting a user-defined
 variable consisting of an integer and a fixed-length
 string.  PB is forcing you to follow the rules of proper
 and consistent programming by requiring you to tell your
 SUBs *exactly* what you will be passing it, which may save
 you a few hours of debugging hell in the future when you
 decide to add that integer to the TYPEd variable and wonder
 why your program is suddenly giving you the wrong results.
 Maybe you should be thanking Bob Zale for that... ;-)
    Anyway, change the SUB declaration to match what you
 are really sending it, i.e.,
    SUB pout (x%, x$, y AS STRING * 15)
    ...then call it as in your example, or declare it as in
 your example, i.e.,
     SUB pout (x%, x$, y AS xs)
    ...and call it with the structure's name, i.e.,
     pout x%, y$, t
    Either way works, and in my mind, makes much more sense.
 TH> Frankly, I'm not into Rube Goldburgs.
    Yes, you are, you just didn't know it.  PB just saved
 you from Rube... (grin)
... Recursion (re kur' shun):  n. See recursion.
--- PPoint 1.96
---------------
* Origin: Seven Wells On-Line * Nashville, TN (1:116/3000.12)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.