How to pass an element of an array to a function?

Started by ale870, September 30, 2006, 10:08:36 AM

Previous topic - Next topic

ale870

Hello,

I created a custom type:
type TVehicle
speed#
posX
posY
endtype


Then I created an array to contain the data about vehicles:

dim vehicles(10) as TVehicle

The problem I need to pass to a function only one of elements:


createVehicle(vehicles(3).TVehicle)

psub createVehicle(argVehicle.TVehicle)
   // Operations to create a vehicle
endpsub


The problem is such code does not work (I get errors during compilation).

I found only this workaround (but I don't like it):


createVehicle(vehicles().TVehicle, 3)

psub createVehicle(argVehicles().TVehicle, argIndex)
   // Operations to create a vehicle
   argVehicles(argIndex).speed# = .....
endpsub



Is there any better way?

Thank you!


--Alessandro

stef

I would it make like this:


type TVehicle
speed#
posX
posY
endtype

dim vehicles(10) as TVehicle

createVehicle(3)

psub createVehicle(vehiclenumber)
vehicles(vehiclenumber).speed#=10.0
   // Operations to create a vehicle
endpsub




ale870

yes, it could be a feasible solution!

Good alternative, thank you!
--Alessandro