function DoBreak = PutCellValue(ActCell,M,AsStr)
% PUTCELLVALUE puts a value in an active cell
% PUTCELLVALUE(ACTCELL,M) puts M in ACTCELL
% PUTCELLVALUE(ACTCELL,M,ASSTR) converts M to a string before putting
% it if ASSTR = 1, leaves it as is if ASSTR = 0 (default)
%
% PUTCELLVALUE handles all classes and is used by FILLGRID.
%
% IT'S NOT FANCY, BUT IT WORKS
%
% See also Graph_and_Table, QuestDlgWithGrid, SearchAndReplaceMany,
% SpreadSheet, DatabaseEditingTool, DuplicateFileFinder,
% PutCellValue, nn2an, FillGrid
%
% Keywords: grid spreadsheet ActiveX Active-X Active X GUI Table
% graph_and_table plot graph table grid object flexgrid
% msflexgrid ocx tabular
% Michael Robbins
% robbins@bloomberg.net
% michaelrobbins1@yahoo.com
if nargin<3 AsStr=0; end;
if AsStr prefix = ''; else prefix = ''''; end;
DoBreak=0;
switch class(M)
case 'cell', % DE-CELLIZE
if prod(size(M)) > 1
errordlg('bad cell');
else
PutCellValue(ActCell,M{:},AsStr);
end;
case 'char', % POST (DATES WILL POST NUMERICLY UNLESS AsStr==1
set(ActCell,'Value',[prefix M]); DoBreak=1;
case 'logical', % LOGICAL -> INT
putcellvalue(ActCell,int32(M),AsStr);
otherwise
if isnumeric(M)
if AsStr % # -> STRING
if isinteger(M) fstr='%d'; else fstr='%f'; end;
putcellvalue(ActCell,sprintf(fstr,M),AsStr);
else % POST
set(ActCell,'Value',M);
end;
else
errordlg('bad class');
end;
end;