TIP: Click on subject to list as thread! ANSI
echo: power_bas
to: ANTON MONROE
from: TIM HUTZLER
date: 1996-06-16 09:19:00
subject: Re: Passing a field

AM>> You need to tell the sub what kind of string to expect. Try
  >> changing it to
 
AM>> SUB pout (x%, x$, t as string * 15)
 
TH> That does not work.
 
TH> I also tried (t as xs) as 'xs' is a user defined type.
AM> It works here. And PowerBasic does not have an error that says
  > 'does not work'.
Don't be silly. I didn't say PB listed that error. I *do* get an
error - 481. Here is a short prog I'd like you to try.
=============================== NONAME.BAS ============================
TYPE xs
    str AS STRING * 15
END TYPE
DIM t AS xs
t.str = "This is a test."
SUB pout (x%, x$, y AS xs)
    PRINT x%, x$, y
    y = "vxvxvxv."
END SUB
DO
 INCR x%
    y$ = MID$(t.str, x%, 1)
    POUT x%, y$, t.str
LOOP UNTIL y$ = "."
==================================================================
I get a 481 error. What do you get?
If I replace the POUT with below it works fine.
    z$ = t.str
    POUT x%, y$, z$
    t.str = z$
Frankly, I'm not into Rube Goldburgs.
AM> In the example you gave, t is a 15-byte fixed-length string, so
  > why in the world would you tell the SUB it is a user-defined
  > type?
Perhaps you jumped in this thread late. I only used "t as STRING*15"
in the SUB, because someone suggested that I try it. I have a user
defined record, and I want to pass a few of the elements to modify
them.
AM> The SUB statement is where you tell the subroutine what kind of
  > variable you will pass it. The error 481 you got is telling you
  > that you are trying to pass a different kind of variable than you
  > said you would.
Well that is in the docs, but as you can see - "t.str" IS a string,
and the SUB knows that. It's a fixed length string, and the SUB
doesn't like that unless I pass BYVAL. For some reason it doesn't like
it being passed by reference.
AM> You gave two variations, A and B. in B, you tell the sub to
  > expect a variable-length string but try to pass it a fixed-length
  > string.
Yes. That works in QuickBasic just fine. Obviously it does not work
the same with PB32. I want to pass a fixed-length string.
AM> That causes an error 481/parameter mismatch. In A, you convert
  > the fixed-length string to a variable-length string, call the
  > sub, and convert the value it returns back to fixed length. That,
  > naturally, works. (And if you want to use that subroutine for
  > strings with a length of other than 15 bytes, might be a better
  > way to do it anyway).
Yes, it seems that is what I need to do. I am suprised that I have to
do this, I'll have to get used to it, and raise hell with the folks at
PowerBASIC. There is no reason that they couldn't accomodate this in
their code, except that someone flubbed up.
--- Maximus/2 3.01
---------------
* Origin: Madman BBS * Chico, California * 916-893-8079 * (1:119/88)

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™.