帮写个函数调用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]);

解决方案 »

  1.   

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

  2.   

    本帖最后由 tjianliang 于 2010-04-10 17:32:52 编辑
      

  3.   

    哈哈,被稻草人占先了,补一个递归版本function CalcSum2(iy: Integer): Double;
    begin
      if iy = 0 then
        Result := 0 
      else
        Result := StrToInt(ListBox2.Items[iy-1]) + CalcSum2(iy-1);
    end;