April 29, 2024, 01:24:05 AM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


UDT array

Started by Egil, March 16, 2011, 06:45:26 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Egil

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
Support Amateur Radio  -  Have a ham  for dinner!

aurelCB

What is maxports?
If is pointer i think that not work becose Cbasic dont support array of pointers.

Brian

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

Egil

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
Support Amateur Radio  -  Have a ham  for dinner!

LarryMc

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
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

GWS

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
Tomorrow may be too late ..

Egil

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

Support Amateur Radio  -  Have a ham  for dinner!