我现在有八个数值  工龄        年休
tNX1  1年       tYX1  5天tNX2  10年        10天  15年        15天
  20年        20天。
我现在想要的结果是。当我edit1.text 为1-10之间时。年休为5天。当10-15为10天。15-20为15天。以此类推我用if (strtoint(edit1.Text)>Form_user.Tnx1) and (strtoint(edit1.Text)<Form_user.Tnx2) then begin
 edit2.Text:=inttostr(Form_user.Tyx1);
 end else begin
 if (strtoint(edit1.Text)>Form_user.Tnx2) and (strtoint(edit1.Text)<Form_user.Tnx3) then begin
 edit2.Text:=inttostr(Form_user.Tyx2);
 end else begin
 if (strtoint(edit1.Text)>Form_user.Tnx3) and (strtoint(edit1.Text)<Form_user.Tnx4) then begin
 edit2.Text:=inttostr(Form_user.Tyx3);
 end else begin
edit2.Text:=inttostr(FOrm_user.Tyx4);

解决方案 »

  1.   

    那不是永远是最大年数减5吗?也就是说只要取得输入的数的大一点的5的倍数的那个数然后-5即可,那可以这样
    function GetDays(years:integer):integer;
    begin
      if (years>=1)and(years<=10) then
      begin
        result:=5;
        exit;
      end;
      result:=years;
      while (result mod 5)<>0 do
      begin
        inc(result);
      end;
      result:=result-5;
    end;procedure TForm1.Button1Click(Sender: TObject);
    begin
      showmessage(inttostr(GetDays(strtoint(Edit1.Text))));
    end;
      

  2.   

    if..else
    挺好
    就4个而已