Computing.Net > Forums > Programming > public static void methods?? (C#)

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

public static void methods?? (C#)

Reply to Message Icon

Name: El-Trucha
Date: March 19, 2005 at 14:42:50 Pacific
OS: Windows XP SP2
CPU/Ram: 2.8 GHz/448 MB
Comment:

Hello every1!! :D
And ANOTHER C# problem...GOSH!! :|
OK...I got this:

public static void AddToItems(string itemName, double itemPrice)
{
EditCart.nameList.Items.Add(itemName);
EditCart.priceList.Items.Add(itemPrice);
}

That doesn't work...it tells me that I need an object reference for nameList and priceList, which both are CheckedListBoxes...
I tried replacing "EditCart" with "this", not putting it at all, making the method nonstatic, and various combinations of those...
Is there a way to make nameList and priceList accessible from other classes?? or making this method work?? how??
Thanx!! ;)

El-Trucha
http://www.truchasoft.tk
ftp://tsfc.homeftp.net
hotline://tsfc.ath.cx



Sponsored Link
Ads by Google

Response Number 1
Name: jlyon
Date: March 20, 2005 at 14:50:32 Pacific
Reply:

I'll give this a shot, though I've never programmed in C#. But it sounds like you might be trying to reference an object that hasn't been instantiated yet. I.E., just declaring nameList and priceList in your EditCart class is not enough. You probably need to use a new operator, in a constructor or something, like nameList = new CheckedListBoxes. Then it would be an Object, and you can reference it. Like I said this is stab in the dark, but it sounds like c# draws from java in that everything is referenced...


0

Response Number 2
Name: El-Trucha
Date: March 22, 2005 at 13:35:31 Pacific
Reply:

Ooooohhh....ok, I'll try that!! thanx!! ;)
Another thing about C# now...do u know how to compile a C# program from within another C# program?? the program I'm making will generate the C# code, and then compile it...but how do I conmpile?? does it have something to do with the
"System.Runtime.CompilerServices" namespace??
Thanx!! ;)

El-Trucha
http://www.truchasoft.tk
ftp://tsfc.homeftp.net
hotline://tsfc.ath.cx


0

Response Number 3
Name: El-Trucha
Date: March 22, 2005 at 13:43:15 Pacific
Reply:

And for the first thing...I went to my code and it was already new'ed to be a CheckedListBox()... :(
What now?? :P
Thanx!! ;)

El-Trucha
http://www.truchasoft.tk
ftp://tsfc.homeftp.net
hotline://tsfc.ath.cx


0

Response Number 4
Name: El-Trucha
Date: March 22, 2005 at 16:55:14 Pacific
Reply:

And...if I'm not bothering u already, why do I get a Win32Exception on the last statement??:


this.text.Text = "C:\\testfile.txt";
if ((File.Exists(this.text.Text)) && (File.Exists(Application.StartupPath + "\\asciimid.exe")))
{
MessageBox.Show("\"" + Application.StartupPath + "\\asciimid.exe\" \"" + this.text.Text + "\" \"" + Application.StartupPath + "\\midi.mid\"");
asciimidRun.StartInfo.FileName = Application.StartupPath + "\\asciimid.exe";
asciimidRun.StartInfo.Arguments = " \"" + this.text.Text + "\" \"" + Application.StartupPath + "\\midi.mid\"";
asciimidRun.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
asciimidRun.Start();
}

I included a MessageBox for you to see that the parameters are all correct...
Thanx!! ;)

El-Trucha
http://www.truchasoft.tk
ftp://tsfc.homeftp.net
hotline://tsfc.ath.cx


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: public static void methods?? (C#)

please... help me out..... www.computing.net/answers/programming/please-help-me-out/3373.html

About C# programming www.computing.net/answers/programming/about-c-programming/17170.html

multiple methods www.computing.net/answers/programming/multiple-methods/12473.html