| TIP: Click on subject to list as thread! | ANSI |
| echo: | |
|---|---|
| to: | |
| from: | |
| date: | |
| subject: | Using fixed strings in s |
Hi;
I have defined a TYPE that has fixed length strings like the
following:
TYPE Crec
...
CName AS STRING * 20
...
END TYPE
DIM rec(100) AS SHARED Crec
However, when I attempt to access 'CName' in a sub like the
following...
SUB MySub (x??)
...
foo$ = rec.CName(x??)
...
END SUB
I get compile error 421 (String operand expected)
Well, rec.CName *is* a string - so what's the problem?
I think I encountered this problem before, but I can't remember what
it took to correct it. It seems that the SUB assumes that rec.CName()
is a numeric. How can I get the sub to know better.
Any comments would be appreciated.
tnx
--- Maximus/2 3.01
---------------
** A related thread FOLLOWS this message.
FIDO MESSAGE AREA==> TOPIC: 214 POWER BASIC Ref: DAYI0491 Date: 06/29/96
From: KURT KUZBA Time: 02:08pm
\/To: TIM HUTZLER (Read 6 times)
Subj: R: Using fixed strings in s
TH> I have defined a TYPE that has fixed length strings
TH> like the following:
TH> TYPE Crec
TH> ...
TH> CName AS STRING * 20
TH> ...
TH> END TYPE
TH> DIM rec(100) AS SHARED Crec
TH> However, when I attempt to access 'CName' in a sub
TH> like the following...
TH> SUB MySub (x??)
TH> ...
TH> foo$ = rec.CName(x??)
TH> ...
TH> END SUB
TH> I get compile error 421 (String operand expected)
TH> Well, rec.CName *is* a string - so what's the problem?
th>.........................................................
Pass the entire structure to the SUB. You must also define the
TYPE prior to the DECLARE for the SUB, which must state the type
of variable you want passed. Power Basic does NOT automatically
create a DECLARE statement as does Quick Basic. Test this once:
type txtstruct
length as integer
t as string * 40
end type
declare sub txtprint(t as txtstruct)
dim text as txtstruct
text.t = "hello": text.length = len(rtrim$(text.t))
txtprint text
print text.length; text.t
end
sub txtprint(t as txtstruct)
print t.length; t.t
t.t = "goodbye": t.length = len(rtrim$(t.t))
end sub
---
> ] * Origin: Madman BBS * Chico, California * 916-893-8079 * (1:119/88)* Origin: Toast House Remote (1:100/560.1) |
|
| 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™.