delphi寫萬年暦的問題~~拜託感謝喔! |
尚未結案
|
cleverman319
一般會員 發表:5 回覆:1 積分:1 註冊:2005-10-10 發送簡訊給我 |
這是一個萬年暦的程式,要透過使用者自己在edit1中輸入年份和edit2中輸入月份,而後再按下button1來計算出當年的當月的日暦,button2是結束,button3按下後是重新再來一次 但是因為這是我在網路上找的,之前他的宣告我都看的懂,但是那"-------"是我自己加上去的,也就是我用"--------''框起來的那一段我看不懂這樣 ,希望會delphi程式的人能夠幫幫我忙,如果可以就盡量回答完整,不然就是在旁邊加個註解也好,謝謝! 圖片的連結如下:
http://photo.pchome.com.tw/cleverman319/023/32-->執行前
http://photo.pchome.com.tw/cleverman319/023/33-->執行後 unit Unit1; interface uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls; type
TForm1 = class(TForm)
Panel1: TPanel;
Label1: TLabel;
Label2: TLabel;
Edit1: TEdit;
Edit2: TEdit;
Button1: TButton;
Button2: TButton;
Label3: TLabel;
Button3: TButton;
procedure Button2Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure FormActivate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end; var
Form1: TForm1; implementation {$R *.dfm} procedure TForm1.Button2Click(Sender: TObject);
begin
close;
end;
----------------------------------------------------------------------------------------------------------------
procedure TForm1.Button1Click(Sender: TObject);
var
a:array [1..12] of integer;
year,month,dayofweek,i,j,k : integer;
s:String;
begin
panel1.Visible:=false;button3.Visible := true;
year:=strtoint(Edit1.Text);month:=strtoint(Edit2.Text); a[1]:=31;a[2]:=28;a[3]:=31;a[4]:=30;a[5]:=31;a[6]:=30;
a[7]:=31;a[8]:=31;a[9]:=30;a[10]:=31;a[11]:=30;a[12]:=31; DayOfWeek := ((Year-1)+((Year-1)div 4)-((Year-1)div 100)+((Year-1)div 400)+1) mod 7; if (((Year mod 4)= 0) and ( not(((Year mod 100)= 0) and (not((Year mod 400)= 0)) ) ) ) then
begin a[2] := 29; end
else
begin a[2] := 28; end;
//print month
s := inttostr(year) + '/'+ inttostr(month) + #13#10#13#10;
s := s + '日 一 二 三 四 五 六 ' + #13#10; if month >1 then
begin
for i:=1 to month-1 do
begin dayofweek:=dayofweek+a[i]; end;
end;
dayofweek := dayofweek mod 7; for j:=1 to dayofweek do
begin s := s+ ' ' end; for k:=1 to a[month] do
begin
if k<10 then
begin s:= s ' ' inttostr(k) ' '; end
else
begin s:= s inttostr(k) ' '; end;
if dayofweek = 6 then
begin s:=s #13#10; end;
dayofweek := dayofweek 1;
dayofweek := dayofweek mod 7;
end; label3.Caption :=s ;
end;
----------------------------------------------------------------------------------------------------------------
procedure TForm1.Button3Click(Sender: TObject);
begin
panel1.Visible := true;
button3.Visible := false;
end; procedure TForm1.FormActivate(Sender: TObject);
begin
button3.Visible := false;
end; end.
|
kgt
高階會員 發表:17 回覆:308 積分:165 註冊:2002-03-13 發送簡訊給我 |
Hi,cleverman319:
我的解讀如下,請參考
ps.程式碼在回覆貼上時,有些+號會不見,故請對照您的原始程式
另外您的附圖,我已看不到
圖片的連結如下:
http://photo.pchome.com.tw/cleverman319/023/32-->執行前
http://photo.pchome.com.tw/cleverman319/023/33-->執行後
----------------------------------------------------------------- procedure TForm1.Button1Click(Sender: TObject);
var
a:array [1..12] of integer; /////一維陣列計12個,用途放每月有幾天
year,month,dayofweek,i,j,k : integer;
s:String;
begin
panel1.Visible:=false;button3.Visible := true;
year:=strtoint(Edit1.Text); /////取得<年>的變數值, 例2005
month:=strtoint(Edit2.Text); /////取得<月>的變數值, 例2月
/////一維陣列計12個,用途放每月有幾天,將預設值放入一維陣列中
a[1]:=31;a[2]:=28;a[3]:=31;a[4]:=30;a[5]:=31;a[6]:=30;
a[7]:=31;a[8]:=31;a[9]:=30;a[10]:=31;a[11]:=30;a[12]:=31;
/////計算當年的一月一日是星期幾,例6
DayOfWeek := ((Year-1)+((Year-1)div 4)-((Year-1)div 100)+((Year-1)div 400)+1) mod 7;
/////計算閏年的部分 ,二月共有幾天,例28
if (((Year mod 4)= 0) and ( not(((Year mod 100)= 0) and (not((Year mod 400)= 0)) ) ) ) then begin
a[2] := 29;
end
else
begin
a[2] := 28;
end;
/////將年月及星期放至變數s
///// 2004/10
/////
/////日 一 二 三 四 五 六
/////
s := inttostr(year) + '/'+ inttostr(month) + #13#10#13#10;
s := s + '日 一 二 三 四 五 六 ' #13#10;
/////算出使用者輸入月份的1號是星期幾,例2
if month >1 then
begin
for i:=1 to month-1 do
begin
dayofweek:=dayofweek+a[i];
end;
end;
dayofweek := dayofweek mod 7;
/////因印當月1號若為星期二,需先印空二格
for j:=1 to dayofweek do
begin
s := s+ ' '
end;
/////開始印出日期1-28,每個日期前後一個空格
for k:=1 to a[month] do
begin
if k<10 then
begin
s:= s ' ' inttostr(k) ' ';
end
else
begin
s:= s inttostr(k) ' ';
end;
/////遇星期六準備換列至下一列
if dayofweek = 6 then
begin
s:=s #13#10; end;
end;
dayofweek := dayofweek 1;
dayofweek := dayofweek mod 7;
end;
label3.Caption :=s ;
end;
|
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |