P
paulotuatail
Hi I have written programs in VB since VB1. I have been writing in vb.net and wanted to move to C# as my first language was 'C'
This program compiles. when run initialy I get a warning message
Unhandeled exception has occured If you click continue the app will ignore the error.
It does and it runs fine. It is only one form and about 50 lines of code. Can anyone tell me where I am going wrong it seems as just an ititialisation problem. the first part of the error description is
***** Error msg *****
See the end of this message for details on invoking
just-in-time (JIT) debugging instead of this dialog box.
************** Exception Text **************
System.NullReferenceException: Object reference not set to an instance of an object.
at InterestCalculator.cmdInterest.cmdInterest_Load(Object sender, EventArgs e)
at System.Windows.Forms.Form.OnLoad(EventArgs e)
at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl()
at System.Windows.Forms.Control.WmShowWindow(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
************** Loaded Assemblies **************
***** Error msg *****
+++++ Code +++++
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace InterestCalculator
{
public partial class cmdInterest : Form
{
public cmdInterest()
{
InitializeComponent();
}
private void cmdCalculate_Click(object sender, EventArgs e)
{
decimal cInitial;
int iMonths;
decimal cInterest;
decimal cCurrent;
decimal val;
int mystart;
cInitial = decimal.Parse(txtInitial.Text);
cCurrent = cInitial;
val = (decimal.Parse(txtMonthly.Text) / 100) + 1;
for (mystart = 0; mystart < int.Parse(txtMonths.Text); mystart++)
{
cCurrent = cCurrent * val;
}
cCurrent = cCurrent - cInitial;
txtResult.Text = cCurrent.ToString("#,###0.00");
}
private void cmdInterest_Load(object sender, EventArgs e)
{
//cmdInterest.ActiveForm.Text = "Des";
cmdInterest.ActiveForm.Top = 0;
}
}
}
+++++ Code +++++
TIA
Paul
This program compiles. when run initialy I get a warning message
Unhandeled exception has occured If you click continue the app will ignore the error.
It does and it runs fine. It is only one form and about 50 lines of code. Can anyone tell me where I am going wrong it seems as just an ititialisation problem. the first part of the error description is
***** Error msg *****
See the end of this message for details on invoking
just-in-time (JIT) debugging instead of this dialog box.
************** Exception Text **************
System.NullReferenceException: Object reference not set to an instance of an object.
at InterestCalculator.cmdInterest.cmdInterest_Load(Object sender, EventArgs e)
at System.Windows.Forms.Form.OnLoad(EventArgs e)
at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl()
at System.Windows.Forms.Control.WmShowWindow(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
************** Loaded Assemblies **************
***** Error msg *****
+++++ Code +++++
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace InterestCalculator
{
public partial class cmdInterest : Form
{
public cmdInterest()
{
InitializeComponent();
}
private void cmdCalculate_Click(object sender, EventArgs e)
{
decimal cInitial;
int iMonths;
decimal cInterest;
decimal cCurrent;
decimal val;
int mystart;
cInitial = decimal.Parse(txtInitial.Text);
cCurrent = cInitial;
val = (decimal.Parse(txtMonthly.Text) / 100) + 1;
for (mystart = 0; mystart < int.Parse(txtMonths.Text); mystart++)
{
cCurrent = cCurrent * val;
}
cCurrent = cCurrent - cInitial;
txtResult.Text = cCurrent.ToString("#,###0.00");
}
private void cmdInterest_Load(object sender, EventArgs e)
{
//cmdInterest.ActiveForm.Text = "Des";
cmdInterest.ActiveForm.Top = 0;
}
}
}
+++++ Code +++++
TIA
Paul