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
at vb.net.

  Any help would be appreciated.

Augie0216
Sunday, November 07, 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 08, 2004

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

EM
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
  else
    return me.trucks(truckid)
  endif
end function

Then use this client code;

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

Steve Cooper
Friday, November 19, 2004

*  Recent Topics

*  Fog Creek Home