I think I got the scope thing...
Inside class + inside method = private and invisible...
Inside class + ouside method = public or private but visible...
Right? :$
So I'll have to declare it outside the button_click event or the method...
What I don't get is this:
The above gives the error "object reference is not set to an instance of an object". This occurs because of the last line "drugSPC[x].path" which is null ! Why is it null? I used "DrugData [] drugSPC;" to declare it and "drugSPC=new DrugData [lengthDOC+lengthPDF];" to initialize it...Code:public class DrugData { public StringBuilder active; public StringBuilder brand; public StringBuilder path; public StringBuilder date; } public partial class Form1 : Form { DrugData [] drugSPC; ..... ....... ...... ...... (blah blah blah) .... .... ..... .... private void button1_Click (object sender, EventArgs e) { getLibrary (); } public void getLibrary() { int x=0; byte temp=0; byte nameEnd=0; StringBuilder tempStr=new StringBuilder (); FileStream myFileCreate=new FileStream (testFile, FileMode.Create); string [] filesPDF=Directory.GetFiles (progDir, "*.pdf", SearchOption.AllDirectories); string [] filesDOC=Directory.GetFiles (progDir, "*.doc", SearchOption.AllDirectories); int lengthPDF=filesPDF.Length; int lengthDOC=filesDOC.Length; drugSPC=new DrugData [lengthDOC+lengthPDF]; string [] filesALL=new string [lengthPDF+lengthDOC]; for (int count=0 ; count<lengthPDF+lengthDOC ; count++) { if (count<lengthPDF) { filesALL [count]=filesPDF [count]; } else { filesALL [count]=filesDOC [count-lengthPDF]; } } foreach (string s in filesALL) { tempStr.Append ("any"); tempStr.Replace (tempStr.ToString (), string.Empty); tempStr.Insert (0, s); nameEnd=(byte) (s.Length-4); tempStr.Remove (nameEnd, 4); drugSPC [x].path=new StringBuilder ();
When I change the class DrugData to struct DrugData like this:
everything works perfectly fine! Why?Code:public partial class Form1 : Form { DrugData [] drugSPC; public struct DrugData { public StringBuilder brand; public StringBuilder active; public StringBuilder date; public StringBuilder path; }




Reply With Quote