Monday, June 18, 2012

[JScript] Scatter redux

The previous version has a problem: when the recordset has zero records, it falls over. The updated version is below:

function Scatter( o ) {
 var result = {};
 var bEmpty = true;
 var vba = {};
 if ( o.RecordCount > 0 ) {
  bEmpty = false;
  vba = new VBArray( o.GetRows() );
 }
 var fldCount = o.Fields.Count;
 for (var i = 0; i < fldCount; i++ ) {
  result[o.Fields(i).Name] = [];
  if ( ! bEmpty ) {
   for ( var j = vba.lbound(2); j <= vba.ubound(2); j++ ) {
    result[o.Fields(i).Name].push( vba.getItem(i,j) );
   }
  }
 }
 return result;
}


© Copyright Bruce M. Axtens, 2012

No comments: