C Board  

Go Back   C Board > General Programming Boards > C# Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 10-15-2006, 04:34 AM   #1
Registered User
 
Join Date: Jun 2003
Posts: 90
Getting an embedded resource

I'm stuck on this one...

I've figured out how to get an embedded picture file to be referenced (and that successfully shows a pic in a control, depending on another item being clicked). That works fine, got loads of pics sorted. What I can't figure out is how to read an embedded text file, process it, and throw the data in to an array.

Code:
public ResourceManager pics128Ships = new ResourceManager("POS_and_Fuel_Calculator.128shipPics", Assembly.GetExecutingAssembly());
        public ResourceManager pics128Pos = new ResourceManager("POS_and_Fuel_Calculator.128posPics", Assembly.GetExecutingAssembly());
        public ResourceManager pics256Pos = new ResourceManager("POS_and_Fuel_Calculator.256Pics", Assembly.GetExecutingAssembly());
        public ResourceManager DataPOSShips = new ResourceManager("POS_and_Fuel_Calculator.POSandShipsData", Assembly.GetExecutingAssembly());
the first three are pictures, no problems with those, so I should expect to do the same with the last one, which calls the *.resx file that has the information about the text files.

However, I'm not sure if I should be using the streamreader method to read through the text files, as building the program is fine, but running/debugging it produces -

Code:
System.ArgumentNullException was unhandled
  Message="Value cannot be null.\r\nParameter name: path"
  Source="mscorlib"
  ParamName="path"
  StackTrace:
       at System.IO.StreamReader..ctor(String path, Encoding encoding, Boolean detectEncodingFromByteOrderMarks, Int32 bufferSize)
       at System.IO.StreamReader..ctor(String path)
       at POS_and_Fuel_Calculator.Form1.Form1_Load(Object sender, EventArgs e) in K:\Programming Projects\POS and Fuel Calculator\POS and Fuel Calculator\Form1.cs:line 43
       at System.Windows.Forms.Form.OnLoad(EventArgs e)
       at System.Windows.Forms.Form.OnCreateControl()
       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.ScrollableControl.WndProc(Message& m)
       at System.Windows.Forms.ContainerControl.WndProc(Message& m)
       at System.Windows.Forms.Form.WmShowWindow(Message& m)
       at System.Windows.Forms.Form.WndProc(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       at System.Windows.Forms.SafeNativeMethods.ShowWindow(HandleRef hWnd, Int32 nCmdShow)
       at System.Windows.Forms.Control.SetVisibleCore(Boolean value)
       at System.Windows.Forms.Form.SetVisibleCore(Boolean value)
       at System.Windows.Forms.Control.set_Visible(Boolean value)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.Run(Form mainForm)
       at POS_and_Fuel_Calculator.Program.Main() in K:\Programming Projects\POS and Fuel Calculator\POS and Fuel Calculator\Program.cs:line 17
       at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
The error originates from the first line here - (which is pretty much the first line of code in the whole program)

Code:
StreamReader sr = new StreamReader(DataPOSShips.GetString("Ships.db"));
            //StreamReader sr = new StreamReader(@"K:\Programming Projects\POS and Fuel Calculator\POS and Fuel Calculator\POS.db");  //the old way of calling a file (it worked...)
            StringBuilder sb = new StringBuilder("");
            int stringCounter = 0;
            while (fuelSize != -1)
            {
                char char1 = (char)sr.Read();
                string string1 = char1.ToString();
                if (string1 == "#")
                {
                    shipsList[stringCounter] += sb.ToString(0, sb.Length);
                    break;
                }
                if (string1 == "@")
                {
                    shipsList[stringCounter] += sb.ToString(0, sb.Length);
                    sb.Remove(0, sb.Length);
                    stringCounter++;
                }
                else
                {
                    sb.Append(string1);
                }
            }
What should I be doing to read in this damn text file??
__________________
He who asks is a fool for five minutes, but he who does not ask remains a fool forever.

The fool wonders, the wise man asks. - Benjamin Disraeli

There are no foolish questions and no man becomes a fool until he has stopped asking questions. Charles Steinmetz
DanFraser is offline   Reply With Quote
Old 10-17-2006, 12:38 PM   #2
Registered User
 
Join Date: Jun 2003
Posts: 90
Code:
StringReader sr = new StringReader(DataPOSShips.GetString("Ships"));
That's how...
__________________
He who asks is a fool for five minutes, but he who does not ask remains a fool forever.

The fool wonders, the wise man asks. - Benjamin Disraeli

There are no foolish questions and no man becomes a fool until he has stopped asking questions. Charles Steinmetz
DanFraser is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Sorting out a resource manager psychopath Game Programming 1 11-10-2008 07:12 PM
unmanaged resource George2 C++ Programming 2 01-03-2008 04:23 AM
CreateProcess with Resource of executable, not the Filename Ktulu Windows Programming 4 11-04-2006 01:07 AM
resource problem/question stallion Windows Programming 4 01-29-2003 02:08 PM
Serial Communications in C ExDigit Windows Programming 7 01-09-2002 10:52 AM


All times are GMT -6. The time now is 04:03 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22