473,395 Members | 1,797 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Class methods loading with a form

Good day.

I am a student working on one of my last programs for class and have come up
with an interesting problem. I have created a custom class method to handle
some calculations for my program. Usually, the created constructor is called
and used in only one method. Now I am trying to use objectName in more than
one instance. Unfortunately, every time the program compiles the error "Type
or namespace name 'x' could not be found..." appears for every subsequent
instance after the first.

The piece of code reads:

private void Form1_Load(object sender, System.EventArgs e)
{
Order newOrder = new Order( );

for (int i = 0; i < newOrder.menuBags.Length; i++)
{
this.lstBoxBagType.Items.Add(newOrder.menuBags[i]);
}
}

private void lstBoxBagType_SelectedIndexChanged(object sender,
System.EventArgs e)
{
newOrder.Bags = this.lstBoxBagType.Text;
}

More instances are referenced throughout the remainder of the program.

I have tried moving the statement into the Main( ) and into other locations.
I have tried commenting out my loop. Nothing seems to get the constructor
passed down correctly. I am out of ideas to try to repair this process.

A point in the right direction would be greatly appreciated.

Thanks,
J
Nov 16 '05 #1
2 903
Hi, J!
private void Form1_Load(object sender, System.EventArgs e)
{
Order newOrder = new Order( );

for (int i = 0; i < newOrder.menuBags.Length; i++)
{
this.lstBoxBagType.Items.Add(newOrder.menuBags[i]);
}
}

private void lstBoxBagType_SelectedIndexChanged(object sender,
System.EventArgs e)
{
newOrder.Bags = this.lstBoxBagType.Text;
}


newOrder should be a field instead of a local variable to be shared between
methods.

Make it like:

Order newOrder = new Order( );
private void Form1_Load(object sender, System.EventArgs e)
{
for (int i = 0; i < newOrder.menuBags.Length; i++)
{
this.lstBoxBagType.Items.Add(newOrder.menuBags[i]);
}
}

It will work.

Sam
Nov 16 '05 #2
That worked like a champ. I guess I assumed that all the references had to
be packaged inside other methods.

Thanks for the help,
J

"Sam Kong" wrote:
Hi, J!
private void Form1_Load(object sender, System.EventArgs e)
{
Order newOrder = new Order( );

for (int i = 0; i < newOrder.menuBags.Length; i++)
{
this.lstBoxBagType.Items.Add(newOrder.menuBags[i]);
}
}

private void lstBoxBagType_SelectedIndexChanged(object sender,
System.EventArgs e)
{
newOrder.Bags = this.lstBoxBagType.Text;
}


newOrder should be a field instead of a local variable to be shared between
methods.

Make it like:

Order newOrder = new Order( );
private void Form1_Load(object sender, System.EventArgs e)
{
for (int i = 0; i < newOrder.menuBags.Length; i++)
{
this.lstBoxBagType.Items.Add(newOrder.menuBags[i]);
}
}

It will work.

Sam

Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Joseph J. Egan | last post by:
I am extending an existing Access/VBA app and need to update a subform displayed in continuous view within a containing form. The existing form and subform have worked fine to date with the...
0
by: Parag Joshi | last post by:
hi, I am facing a wierd problem with dyanamic class loading. I have a namespace called ETS.DAO which contains my Data Access Object classes. All these classes implement a common interface which...
9
by: keith | last post by:
I created a class libery which has name space Assembly and class Assembly and compiled it. Then created a C# project and called a method in the external class e.g. Assembly dll;...
2
by: Mountain Bikn' Guy | last post by:
It is known that one cannot pass arguments as ref or out in a marshal-by-reference class. My problem is that I have a C DLL (and C# wrapper) that I need to isolate in an AppDomain and then I need...
5
by: Felix I. Wyss | last post by:
Good Afternoon, I recently noticed that some very simple methods of a template declared and used in a DLL library get inlined when used by the DLL itself, but not by other DLLs and EXEs. After...
8
by: kevin | last post by:
I have a form and in the form I have a sub that uses a class I instantiate using visual basic code: Public oCP As New Rs232 'instantiate the comm port I need to share this sub with...
2
by: Macca | last post by:
Hi, I have a windows form project. The form class has a number of methods in it that i want to call from another class I have just created. This class is a finite state machine and is created...
4
by: vze1r2ht | last post by:
I have many types of classes and I'm deciding whether to use a single class or multiple classes for EACH type of class. For an example: User class has 3 classes associated with it: User...
1
by: MikeCS | last post by:
Problem: I wanted to implement what I did in VB6 where I would use a global structure and dimension an array of structures then the program could load data into it at start up. Global routines would...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.