如果语句不起作用.请帮我帮我 [英] If statement is not working. plz help me with htis
本文介绍了如果语句不起作用.请帮我帮我的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
private void button4_Click(object sender, EventArgs e)
{
if (txttenure.Text == "1")
{
b = Convert.ToInt32(txtijarahamount.Text);
for (int j = 1; j <= 12; j++)
{
int newRowIndex = dataGridView1.Rows.Add();
int z = 12;
markup = double.Parse(txtmarkup.Text);
Double a = (b / 100) * 80;
prfrate = (markup + 3.00) / 100.00;
bnkprf = (a * prfrate * 31.00) / 365.00;
rental = (a + bnkprf + 30000) / z;
z--;
string r = Convert.ToString(rental);
dataGridView1.Rows[newRowIndex].Cells["Amount"].Value = r.ToString();
a = a - Convert.ToDouble(dataGridView1.Rows[newRowIndex].Cells["Amount"].Value);
r = Convert.ToString(rental);
dataGridView1.Rows[newRowIndex].Cells["Date"].Value = dateTimePicker1.Value.Date.AddMonths(j).ToString();
dataGridView1.Rows[newRowIndex].Cells["ijarah_id"].Value = txtijarahid.Text;
}
推荐答案
更改此行
if (txttenure.Text == "1")
对此
to this
if (int.TryParse(txttenure.Text, out b))
1.比较时可能会出现错误,因此请使用字符串比较功能来比较值和位置.
2.使用try catch块查看是否有任何错误(您正在转换很多字符串以使其倍增和浮动,可能是其中一些/任何不正确的顺序).
试试这个
试试{
if(string.Compare(txttenure.Text,"1",true)== 0)
{
}
}//尝试结束
捕获(除例外)
{MessageBox.Show(ex.Message); }
1. there might be error in your comparing so use string compare function, to compare values and locations.
2. use a try catch block to see if there is any error, (you are casting a lot of strings to double and float, may be some/any of them not correct order).
try this
try{
if(string.Compare (txttenure.Text, "1", true)==0)
{
}
}//end of try
catch(Excetion ex)
{ MessageBox.Show(ex.Message); }
这篇关于如果语句不起作用.请帮我帮我的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文