首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

帮写个函数调用解决办法

2012-03-24 
帮写个函数调用帮写个函数调用IY 可能等于1 - NNNNlistbox2.Items[N]行 每行都是数字if iy0 then ww:0i

帮写个函数调用
 
帮写个函数调用

IY 可能等于1 - NNNN
listbox2.Items[N]行 每行都是数字
if iy=0 then ww:=0;
 if iy=1 then ww:=StrToInt(listbox2.Items[0]);
 if iy=2 then ww:=StrToInt(listbox2.Items[0])+StrToInt(listbox2.Items[1]);
 if iy=3 then ww:=StrToInt(listbox2.Items[0])+StrToInt(listbox2.Items[1])+StrToInt(listbox2.Items[2]);
 if iy=4 then ww:=StrToInt(listbox2.Items[0])+StrToInt(listbox2.Items[1])+StrToInt(listbox2.Items[2])+StrToInt(listbox2.Items[3]);
 if iy=5 then ww:=StrToInt(listbox2.Items[0])+StrToInt(listbox2.Items[1])+StrToInt(listbox2.Items[2])+StrToInt(listbox2.Items[3])+StrToInt(listbox2.Items[4]);
 if iy=6 then ww:=StrToInt(listbox2.Items[0])+StrToInt(listbox2.Items[1])+StrToInt(listbox2.Items[2])+StrToInt(listbox2.Items[3])+StrToInt(listbox2.Items[4])+StrToInt(listbox2.Items[5]);
  if iy=7 then ww:=StrToInt(listbox2.Items[0])+StrToInt(listbox2.Items[1])+StrToInt(listbox2.Items[2])+StrToInt(listbox2.Items[3])+StrToInt(listbox2.Items[4])+StrToInt(listbox2.Items[5])+StrToInt(listbox2.Items[6]);

[解决办法]
var i : inetger;
begin
Result := 0;
for i := 0 to iy - 1 do
begin
Result := Result + strtoint(listbox2.items[i]);
end;
end;
[解决办法]

Delphi(Pascal) code
function CalcSum(iy: Integer): Double;var  i: Integer;begin  Result := 0;  if iy > 0 then    for i := 0 to iy - 1 do      Result := Result + StrToInt(ListBox2.Items[i]);end;
[解决办法]
哈哈,被稻草人占先了,补一个递归版本
Delphi(Pascal) code
function CalcSum2(iy: Integer): Double;begin  if iy = 0 then    Result := 0   else    Result := StrToInt(ListBox2.Items[iy-1]) + CalcSum2(iy-1);end; 

热点排行