Type & End Types

BlitzPlus Forums/BlitzPlus Programming/Type & End Types

Zooker(Posted 2005) [#1]
How do you use Them in an array. I need to know if you can use the Field statement to specify how long a string can be.?


Grey Alien(Posted 2005) [#2]
Type Man
Field x
Field y
End Type

;an array of men
Dim Men.Man(10)

;can't do this though because you can't use Dim with Field.
Type ArrayOfMen
Field Dim Men.Man(10)
EndType

;can do this though (note square brackets)
Type ArrayOfMen
Field Men.Man[10]
EndType


You can't use Field to limit the size of a string (like in PASCAL) you just have to code it when the string is used.


ozak(Posted 2005) [#3]
Hmm. Isn't that exactly how you use arrays within a type? I'm no expert, but that's how I use'em :)


Zooker(Posted 2005) [#4]
Thanx

Grey Alien do you mean I should use Rset or lset to pad the Fields Like:
Type man
Field Pants$
end type
Dim Men.Man(1000)
V$="Spartan"
Men/Pants$=Rset$(V$,12)


Grey Alien(Posted 2005) [#5]
You would have to type Men(x)\Pants$ = Rset$(V$,12)
where x is the array "slot" you want to set. Also note the backslash not forward slash.

You could use Rset if you want to make the strings all the same length but why? What I meant was, say a user was typing in a string, you could limit it then to a set number of chars, or if reading it from a file you could use Mid$(V$,1,12) to truncate it to 12 chars in the event that it might be longer.

btw with my "array of men" type I would normally have other fields in the type such as Count. Then I can pass that type tospecial functions used to clear it, fill it and manipulate it. Not sure you can pass array's into functions as they are global anyway. Maybe someone will correct me on this.