J
JB
Hello
Is it possible and if so how, to call a method in a class that
is not called from a control on a form? When you create a button on a form
if you
create a button click event and type someproc(); and there is a method in
the form code module that looks like this:
public void someproc()
{
MessageBox.Show("hello world");
}
the method will execute and show "hello world"
But if a module that does not have a button control calls another module,
that called module will exeute but its method won't call any other methods
that
it contains within itself.
For example: lets call below "mod1" and I marked a ***line 16 in it which
calls
"mod2" in a module below it. When mod2 executes it has a method named
RangeProc.
But when RangProc tries to get executed it says "an object Reference is
required for the nonstatic field, method, or property ...RangeProc()
****** mod1:
using System;
using System.Data;
using System.Drawing;
using System.Windows.Forms;
using Microsoft.VisualStudio.Tools.Applications.Runtime;
using Word = Microsoft.Office.Interop.Word;
using Office = Microsoft.Office.Core;
using System.Data.SqlClient;
using System.Collections;
using System.Collections.Generic;
using System.Threading;
namespace mDivisionsProj
{
public partial class ThisDocument
{
private void ThisDocument_Startup(object sender, System.EventArgs e)
{
List<object> DivisionTbl = new List<object>();
***line 16: DivisionTbl = DivData.DivisionList();
}
private void ThisDocument_Shutdown(object sender, System.EventArgs e)
{
}
#region VSTO Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InternalStartup()
{
this.button1.Click += new System.EventHandler(this.button1_Click);
this.Shutdown += new
System.EventHandler(this.ThisDocument_Shutdown);
this.Startup += new
System.EventHandler(this.ThisDocument_Startup);
}
#endregion
}
}
******* mod2
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using System.Data;
using System.Data.SqlClient;
using System.Windows.Forms;
using System.Text.RegularExpressions;
using System.Threading;
namespace mDivisionsProj
{
public class DivData
{
private string PDist;
private int ADDist;
private int EDD;
public DivData(string PD, int AD, int ED)
{
PD = PDist;
AD = ADDist;
ED = EDDist;
}
public static List<object> DivisionList()
{
List<object> GetDivList = new List<object>();
GetDivList = GetDivData.rdDivData();
if ((holdDiv == currDiv) & (holdAD < currAD))
{
if (isRange == "Y")
{
nuRange = FromED.ToString() + " To " + ToED;
}
else
{
FromED = holdED;
nuRange = FromED.ToString();
}
RangeProc();
isRange = "N";
}
ToED = " ";
holdDiv = currDiv;
holdAD = currAD;
holdED = currED;
compHold = Convert.ToInt32(holdED);
}
return GetDivList;
}
public void RangeProc()
{
GetDivList.Add(holdAD.ToString());
GetDivList.Add(nuRange);
}
}
}
Is it possible and if so how, to call a method in a class that
is not called from a control on a form? When you create a button on a form
if you
create a button click event and type someproc(); and there is a method in
the form code module that looks like this:
public void someproc()
{
MessageBox.Show("hello world");
}
the method will execute and show "hello world"
But if a module that does not have a button control calls another module,
that called module will exeute but its method won't call any other methods
that
it contains within itself.
For example: lets call below "mod1" and I marked a ***line 16 in it which
calls
"mod2" in a module below it. When mod2 executes it has a method named
RangeProc.
But when RangProc tries to get executed it says "an object Reference is
required for the nonstatic field, method, or property ...RangeProc()
****** mod1:
using System;
using System.Data;
using System.Drawing;
using System.Windows.Forms;
using Microsoft.VisualStudio.Tools.Applications.Runtime;
using Word = Microsoft.Office.Interop.Word;
using Office = Microsoft.Office.Core;
using System.Data.SqlClient;
using System.Collections;
using System.Collections.Generic;
using System.Threading;
namespace mDivisionsProj
{
public partial class ThisDocument
{
private void ThisDocument_Startup(object sender, System.EventArgs e)
{
List<object> DivisionTbl = new List<object>();
***line 16: DivisionTbl = DivData.DivisionList();
}
private void ThisDocument_Shutdown(object sender, System.EventArgs e)
{
}
#region VSTO Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InternalStartup()
{
this.button1.Click += new System.EventHandler(this.button1_Click);
this.Shutdown += new
System.EventHandler(this.ThisDocument_Shutdown);
this.Startup += new
System.EventHandler(this.ThisDocument_Startup);
}
#endregion
}
}
******* mod2
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using System.Data;
using System.Data.SqlClient;
using System.Windows.Forms;
using System.Text.RegularExpressions;
using System.Threading;
namespace mDivisionsProj
{
public class DivData
{
private string PDist;
private int ADDist;
private int EDD;
public DivData(string PD, int AD, int ED)
{
PD = PDist;
AD = ADDist;
ED = EDDist;
}
public static List<object> DivisionList()
{
List<object> GetDivList = new List<object>();
GetDivList = GetDivData.rdDivData();
if ((holdDiv == currDiv) & (holdAD < currAD))
{
if (isRange == "Y")
{
nuRange = FromED.ToString() + " To " + ToED;
}
else
{
FromED = holdED;
nuRange = FromED.ToString();
}
RangeProc();
isRange = "N";
}
ToED = " ";
holdDiv = currDiv;
holdAD = currAD;
holdED = currED;
compHold = Convert.ToInt32(holdED);
}
return GetDivList;
}
public void RangeProc()
{
GetDivList.Add(holdAD.ToString());
GetDivList.Add(nuRange);
}
}
}