Fog Creek Software
Discussion Board

Welcome! and rules

Joel on Software

Creating methods

I'm creating a class module which simulates trucks departing and arriving from the terminal. I am trying to create a method named FindTruck which accepts one argument the TruckId  and return a Truck structure,but return nothing if a Tthe truck isn't found. I am a newbie

  Any help would be appreciated.

Sunday, November 7, 2004

Structs can't be null (not until .NET 2.0 that is). Either define a constant of type Truck that has recognizable invalid fields, or use a class instead.

Chris Nahr
Monday, November 8, 2004

Return 0 and your code knows that 0 = no trucks found.

Thursday, November 18, 2004

Try it like this;

Function FindTruck(truckid as integer) as TruckStruct
  ' get truck, eg
  if truckid > ubound(me.trucks) or truckid < 0 then
      return nothing
    return me.trucks(truckid)
end function

Then use this client code;

dim truck as TruckStruct = FindTruck(truckid)
if (truck is nothing) = false then
  ' we have a truck
  ' we have no truck

Steve Cooper
Friday, November 19, 2004

*  Recent Topics

*  Fog Creek Home