作者k07224115 (Captain Espana)
看板C_Sharp
標題[問題] 計算機不會累加
時間Wed Oct 22 01:30:09 2014
double varOperand;
bool ResultComplete ;
private void button16_Click(object sender, EventArgs e)
{
textBox1.Text = "";
textBox2.Text = "";
varOperand = 0;
ResultComplete = true;
}
private void button1_Click(object sender, EventArgs e)
{
if (ResultComplete == true)
{
textBox1.Text = "";
ResultComplete = false;
}
textBox1.Text = textBox1.Text + "1";
}
button16是clear清除
button1就是數字1 以此類推
textBox1是輸入數字與輸出的地方
在button1 click那邊我看得懂如果textBox1是空白的話
ResultComplete的狀態是false
也因此可以得知不是空白的話就是true
但實在是不知道一開始要怎麼宣告ResultComplete阿!!!
要怎麼寫可以讓電腦知道如果textBox非空的話狀態會是true?
實在是困擾很久
拜託各位高手幫小弟解惑!!!!!!!!!
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 140.112.231.227
※ 文章網址: http://www.ptt.cc/bbs/C_Sharp/M.1413912611.A.B7A.html
推 dontblame: 問題看了不是很懂 會是 textBox1.Text != "" 嗎? 10/22 06:15
→ gamer880831: resultcomplete=!string.isnullorempty(textbox1.tex 10/22 06:52
→ gamer880831: t); 10/22 06:52
推 gamer880831: 然後是想在字串後面+字,還是數字累加…數字累加應 10/22 06:54
→ gamer880831: 該用整數或實數運算完再convert 10/22 06:54
推 GoalBased: 還是買一本入門的書來看看吧 10/22 08:20
→ O2000: ResultComplete初始值應該是true,然後按了+-*/= 10/22 09:46
→ O2000: 之類的運算按鈕之後會改成false 10/22 09:46
→ O2000: 打錯了,是按了數字改成false,按+-*/=之後改回true 10/22 09:47
→ lucky1lk: 字串+字串 會等於啥?! 10/22 13:11
→ gamer880831: 等於更長的字串,只要不超過String的大小 10/22 20:24