PDA

Click to See Complete Forum and Search --> : [RESOLVED] Checking Dialog result


Pasvorto
Jul 25th, 2007, 09:51 AM
Continuing with my project:

I have this code:

DialogResult result6;
Boolean result7;
result6 = MessageBox.Show("Do you want to do an amortization schedule?", "TVAL", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (result6 = DialogResult.Yes)
result7 = true;
else
result7 = false;

if (result7 = true)
{
txtLoanAmount.Text = PVal.ToString("N2");
txtTerm.Text = TotPmts.ToString("N2");
txtRate.Text = APR.ToString("N5");
txtPayment.Text = Payment.ToString("N2");

MessageBox.Show("Fill in dates, select the base, and press [Compute Amortization Schedule] button", "TVAL", MessageBoxButtons.OK, MessageBoxIcon.Information);
this.Refresh();
}


I am getting this error (on the result6 = Dialogresult.Yes)

Error 1 Cannot implicitly convert type 'System.Windows.Forms.DialogResult' to 'bool' I:\VB NET Source Code\C#\TVAL\TVAL\TVAL\Form1.cs 1257 17 TVAL


I am getting this error on the result7 = true line:

Warning 2 Assignment in conditional expression is always constant; did you mean to use == instead of = ? I:\VB NET Source Code\C#\TVAL\TVAL\TVAL\Form1.cs 1262 17 TVAL

The VB6 code was much easier (I am probably doing this wrong):

amort = MsgBox("Your payment will be $" & Format(Payment, Fmt) & " per month." & vbCrLf & vbCrLf & "Do you want to do an amortization schedule?", vbYesNo)
If amort = vbYes Then
txtLoanAmount.Text = PVal
txtTerm.Text = TotPmts
txtRate.Text = APR * 100
txtPayment.Text = Format(Payment, Fmt)
MainMenu.Refresh
End If

Pasvorto
Jul 25th, 2007, 09:56 AM
Got it to work:

if (MessageBox.Show("Do you want to do an amortization schedule?", "TVAL", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
txtLoanAmount.Text = PVal.ToString("N2");
txtTerm.Text = TotPmts.ToString("N2");
txtRate.Text = APR.ToString("N5");
txtPayment.Text = Payment.ToString("N2");

MessageBox.Show("Fill in dates, select the base, and press [Compute Amortization Schedule] button", "TVAL", MessageBoxButtons.OK, MessageBoxIcon.Information);
this.Refresh();
}

nmadd
Jul 25th, 2007, 10:10 AM
"=" is both the assignment operator and the equality operator in VB, however, as you found out they are two different things in C#. How's the project coming along? :)

Pasvorto
Jul 25th, 2007, 11:12 AM
It is coming along. I have 5 buttons and a listview on one form. With each control, I learn something new.

The whole reason for this 'exercise' is that we are getting new barcode scanners. The programs (which I will have to write) will be in C#. My background is in VB (only moved a couple apps to VB2005). I chose this app to learn C# on because it is small, straight forward, and encompasses most things that I will run into (except database accessing).

Thanks for all the help.