program has initial error on start up but runs ok


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
 
Ad

Advertisements

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

I realise that it was in the wrong place now. What I wanted to do was on the form initialise to set it's position and to change the caption as well as the icon.

In VB.net if I click on a control the properties shows the name of the control and other properties. When I click on the form I do not get this. It is still the last control on the form I clicked on.

It's as if the form is not a control in itself. I need an initialise event for the form and code that would acheve all this.

In my main procect I have Form1.cs so should I say Form1.left = 200;

I can't get any of tthis working.

TIA

Paul
 
Ad

Advertisements

J

Jeff Johnson

I realise that it was in the wrong place now. What I wanted to do was on
the
form initialise to set it's position and to change the caption as well as
the icon.

In VB.net if I click on a control the properties shows the name of the
control
and other properties. When I click on the form I do not get this. It is
still the
last control on the form I clicked on.

It's as if the form is not a control in itself. I need an initialise event
for the
form and code that would acheve all this.

In my main procect I have Form1.cs so should I say Form1.left = 200;

I can't get any of tthis working.

Why are you trying to use the events of a CONTROL to set the properties of
the FORM? Just use the Load (or Shown) event of the form and do

this.Top = 0;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top