線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:1222
推到 Plurk!
推到 Facebook!

StringGrid的欄位 B=A-C 問題

答題得分者是:max5020
lovemari
中階會員


發表:134
回覆:224
積分:76
註冊:2005-08-18

發送簡訊給我
#1 引用回覆 回覆 發表時間:2008-04-15 13:42:00 IP:60.248.xxx.xxx 訂閱


各位大大好

小弟在寫StringGrid的欄位 搜尋出 A , B

那C的部分想要 C = A - B

就寫以下SQL , 但是結果跑出來卻是 C = B

能請各位大大幫我看看那裡出錯了嗎??

[code delphi]
for a:=1 to StringGrid1.RowCount-1 do
if StringGrid1.Cells[2,a] = '' then
StringGrid1.Cells[2,a] := FloattoStr(StrToFloat(StringGrid1.Cells[1,a]) - (StrToFloat(StringGrid1.Cells[3,a])));

[/code]
------
Program : Delphi 7
DataBase : Oracle 9i
Client : ClientDataSet
max5020
資深會員


發表:30
回覆:277
積分:321
註冊:2003-06-04

發送簡訊給我
#2 引用回覆 回覆 發表時間:2008-04-15 17:09:45 IP:59.120.xxx.xxx 訂閱
你這樣寫好像是 B(2) = A(1) - C(3)
如果C(3)是空值,
那不就是 B(2) = A(1)
是不是要改成
StringGrid1.Cells[3,a] := FloattoStr(StrToFloat(StringGrid1.Cells[1,a]) - (StrToFloat(StringGrid1.Cells[2,a])));

我猜的啦!!!
===================引 用 lovemari 文 章===================


各位大大好

小弟在寫StringGrid的欄位 搜尋出 A , B

那C的部分想要 C = A - B

就寫以下SQL , 但是結果跑出來卻是 C = B

能請各位大大幫我看看那裡出錯了嗎??

[code delphi]
for a:=1 to StringGrid1.RowCount-1 do
if StringGrid1.Cells[2,a] = '' then
StringGrid1.Cells[2,a] := FloattoStr(StrToFloat(StringGrid1.Cells[1,a]) - (StrToFloat(StringGrid1.Cells[3,a])));

[/code]
lovemari
中階會員


發表:134
回覆:224
積分:76
註冊:2005-08-18

發送簡訊給我
#3 引用回覆 回覆 發表時間:2008-04-15 17:50:45 IP:122.116.xxx.xxx 訂閱
小弟改成這樣 依然跑出 C = B 耶


[code delphi]
for a:=1 to StringGrid1.RowCount-1 do
// if StringGrid1.Cells[2,a] = '' then
StringGrid1.Cells[2,a] := FloattoStr(StrToFloat(StringGrid1.Cells[1,a]) - (StrToFloat(StringGrid1.Cells[3,a])));
[/code]
------
Program : Delphi 7
DataBase : Oracle 9i
Client : ClientDataSet
P.D.
版主


發表:603
回覆:4038
積分:3874
註冊:2006-10-31

發送簡訊給我
#4 引用回覆 回覆 發表時間:2008-04-15 23:51:50 IP:61.67.xxx.xxx 未訂閱
1. max5020 已經說的很明白了, 但我沒有看到你改了那裡, 只是 remark 一行而已
2.這段叫做 CODE, 不叫做 SQL , 上一下YAHOO, GOOGLE 查一下何謂 SQL?
3.看不出來你的程式能跑出 C = B 的結論, 因為永遠是 B = 右列的計算式, 要做到 C = 右列計算式, 想想看如何設定吧!
===================引 用 lovemari 文 章===================
小弟改成這樣 依然跑出 C = B 耶


[code delphi]
for a:=1 to StringGrid1.RowCount-1 do
// if StringGrid1.Cells[2,a] = '' then
StringGrid1.Cells[2,a] := FloattoStr(StrToFloat(StringGrid1.Cells[1,a]) - (StrToFloat(StringGrid1.Cells[3,a])));
[/code]
lovemari
中階會員


發表:134
回覆:224
積分:76
註冊:2005-08-18

發送簡訊給我
#5 引用回覆 回覆 發表時間:2008-04-16 08:35:28 IP:122.116.xxx.xxx 訂閱
抱歉抱歉 我可能敘述上有錯誤
我的 Cells[1,a] = A Cells[2,a] = B Cells[3,a] = C

我想要 B = A - C (一開始敘述不夠清楚讓大家以為我要 C = A - B)


那我把 IF xxxxx = '' 這行code 刪除 在按照 max5020 大大的
改成這樣依然跑出 B = C (而非 A - C )


[code delphi]
for a:=1 to StringGrid1.RowCount-1 do
StringGrid1.Cells[2,a] := FloattoStr(StrToFloat(StringGrid1.Cells[1,a]) - (StrToFloat(StringGrid1.Cells[3,a])));

[/code]



===================引 用 P.D. 文 章===================
1. max5020 已經說的很明白了, 但我沒有看到你改了那裡, 只是 remark 一行而已
2.這段叫做 CODE, 不叫做 SQL , 上一下YAHOO, GOOGLE 查一下何謂 SQL?
3.看不出來你的程式能跑出 C = B 的結論, 因為永遠是 B = 右列的計算式, 要做到 C = 右列計算式, 想想看如何設定吧!


------
Program : Delphi 7
DataBase : Oracle 9i
Client : ClientDataSet
編輯記錄
lovemari 重新編輯於 2008-04-16 08:36:50, 註解 無‧
max5020
資深會員


發表:30
回覆:277
積分:321
註冊:2003-06-04

發送簡訊給我
#6 引用回覆 回覆 發表時間:2008-04-16 10:42:57 IP:59.120.xxx.xxx 訂閱
Use Cells to access the string within a particular cell. ACol is the column coordinate of the cell, and ARow is the row coordinate of the cell. The first row is row zero, and the first column is column zero. 

我終於知道你要問什麼了,
改成下列這樣
[code delphi]
for a:=1 to StringGrid1.RowCount-1 do
StringGrid1.Cells[1,a] := FloattoStr(StrToFloat(StringGrid1.Cells[0,a]) - (StrToFloat(StringGrid1.Cells[2,a])));

[/code]

因為是從0開始, 不是從1開始數!!
===================引 用 lovemari 文 章===================
抱歉抱歉 我可能敘述上有錯誤
我的 Cells[1,a] = A Cells[2,a] = B Cells[3,a] = C

我想要 B = A - C (一開始敘述不夠清楚讓大家以為我要 C = A - B)


那我把 IF xxxxx = '' 這行code 刪除 在按照 max5020 大大的
改成這樣依然跑出 B = C (而非 A - C )


[code delphi]
for a:=1 to StringGrid1.RowCount-1 do
StringGrid1.Cells[2,a] := FloattoStr(StrToFloat(StringGrid1.Cells[1,a]) - (StrToFloat(StringGrid1.Cells[3,a])));

[/code]



===================引 用 P.D. 文 章===================
1. max5020 已經說的很明白了, 但我沒有看到你改了那裡, 只是 remark 一行而已
2.這段叫做 CODE, 不叫做 SQL , 上一下YAHOO, GOOGLE 查一下何謂 SQL?
3.看不出來你的程式能跑出 C = B 的結論, 因為永遠是 B = 右列的計算式, 要做到 C = 右列計算式, 想想看如何設定吧!


lovemari
中階會員


發表:134
回覆:224
積分:76
註冊:2005-08-18

發送簡訊給我
#7 引用回覆 回覆 發表時間:2008-04-16 11:38:09 IP:122.116.xxx.xxx 訂閱
非常感謝 MAX5020 大大 我解出來了

萬分感謝^^
------
Program : Delphi 7
DataBase : Oracle 9i
Client : ClientDataSet
系統時間:2024-05-06 17:46:48
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!