Categories > TinyButStrong general >

thankful for some help with some code

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: Jim
Date: 2003-09-30
Time: 11:44

thankful for some help with some code

I have a code like this

class TV_361
{
var $weight;
var $quantity;
}
class TV_362
{
var $weight;
var $quantity;
}
etc.....

these are initiated with

$TV361 = new TV_361()
$TV362 = new TV_362()
etc....

#A loop through recordset here

switch ($o->CP_CODE) {
case 361:
  $TV361->weight+=$o->CP_WEIGHT;
  $TV361->quantity++ ;
  break;
case 362:
  $TV362->weight+=$o->CP_WEIGHT;
  $TV362->quantity++ ;
  break;
case # It continues like this with alot of cases
};

Could I do the following?

$TV362 = new TV_362()

#A loop through recordset here

  $TV361("$o->CP_CODE")->weight+=$o->CP_WEIGHT;
  $TV361("$o->CP_CODE")->quantity++ ;
#end loop

regards Jim
By: Skrol29
Date: 2003-09-30
Time: 15:55

Re: thankful for some help with some code

Hello Jim,

This is not specific to TBS but let's go.

I dont 't understand why you create several class definitions if you are using them the same way. Use only one class definition.

class TV
{
  var $weight;
  var $quantity;
}

$TVS_361 = new TV() ;
$TVS_362 = new TV() ;

Then your you create a function that operate on any TV instance and that operate the weight and quantity addition.
This function can be a separate function or a method implemented into the class.