IonicWind Software

Creative Basic => General Questions => Topic started by: Egil on March 16, 2011, 06:45:26 AM

Title: UDT array
Post by: Egil on March 16, 2011, 06:45:26 AM
I have defined an UDT containing five members.

When trying to make an array with this UDT, CB says variable not defined and specifying the linenumber of the array definition.

The code I used is:DEF ports[maxports]:MY_PORT

Is this definition a valid one?

Egil
Title: Re: UDT array
Post by: aurelCB on March 16, 2011, 07:36:02 AM
What is maxports?
If is pointer i think that not work becose Cbasic dont support array of pointers.
Title: Re: UDT array
Post by: Brian on March 16, 2011, 08:24:17 AM
Egil,

May be wrong, but I don't think you can initialise an array with a variable - it has to
be an integer. At least, that was the case with IB Pro, and probably EBA, if I checked it

Maybe you could use NEW ? I don't know if that is available with CBA

Brian
Title: Re: UDT array
Post by: Egil on March 16, 2011, 08:29:12 AM
maxport is defined as a CONST.

I will try to redifene it later tonight. Right now I have to pick up one of my grandsons at the airport.... :D

Thanks guys!
Egil
Title: Re: UDT array
Post by: LarryMc on March 16, 2011, 10:11:37 AM
Egil
This works - maybe it will help
type MY_PORT
   DEF Name:STRING
   DEF Age:INT
   DEF Phone[20]:ISTRING
endtype
const maxports = 8
DEF ports[maxports]:MY_PORT

ports[5].name="testing"
for x=0 to maxports-1
  print "["+ports[x].name+"]"
next x


LarryMc
Title: Re: UDT array
Post by: GWS on March 16, 2011, 11:12:20 AM
Hey Larry, you're getting really good with CBasic ..  ;D ;D

Been busy, so late getting to this question ..

So here's another example ..


openconsole
cls

def tabs:string
def num:int

type NAPP
def name :string
def address :string
def postcode :string
def phone :string
endtype

num = 10
def rec[num] : NAPP

rec[1].name = "Fred"
rec[1].address = "2 Smith Square, Bexley"
rec[1].postcode = "CH3 5TG"
rec[1].phone = "0121 478574"

rec[2].name = "Alyson"
rec[2].address = "43 Berkley Road, Tipton"
rec[2].postcode = "TY2 H23"
rec[2].phone = "0155 687235"

tabs = string$(5,str$(9))

for i = 1 to 2
' note the closing comma to ensure printing continues on the same line
print rec[i].name,tabs,rec[i].address,tabs,
print rec[i].postcode,tabs,rec[i].phone
next i

do:until inkey$<>""
closeconsole
end



You just know Creative can do most things .. small it may be, but it's got a great heart ..  ;D ;D

best wishes, :)

Graham
Title: Re: UDT array
Post by: Egil on March 16, 2011, 12:07:42 PM
Quote from: GWS on March 16, 2011, 11:12:20 AM
Hey Larry, you're getting really good with CBasic ..  ;D ;D
.....

You just know Creative can do most things .. small it may be, but it's got a great heart ..  ;D ;D

best wishes, :)

Graham

Hi Graham,

I quite agree. I have always liked CB, as you know, and converting that code to EB/IWB-1.8 is really done in minutes, whitout the "S2P" program mentioned elsewhere on the forum.
And I think if we only supply enough examples of CB's versatility, we will be able to make LarryMc start working seriously with it. At least this package is well proven.... hehe. :D :D

Just came back from the airport. My grandson just had time for a cup of cofee, and left immediately to sea to see if he can catch some fish. He was in such a hurry that he had to come back for the keys to get the boat started...

When I inspect my code again, after a couple of hours break, the first thing i notice is a tiny typo. My code is almost identical to LarryMc's, exept for one of the array brackets were a curly bracket instead of square one. Why did I do that??

Now I am trying to expand my UDP program a little, so users will be able to talk to each other on "private channels"...
But at the same time I try to figure out how to make a remote control program for my FT-817 QRP rig. Plan is to put it in the loft with an old 286 running Win98. And control it from here via UDP, and a serial port for the CAT connection to the rig. There are several very good programs doing the same job on the internet, but since I have the tools, why not try to "roll my own"??;)

Thanks again guys!
Egil