views:

72

answers:

3

There's an error: "The type being set is not compatible with the value representation of the tag."

  string fi = null;


        public void reading(object sender, EventArgs e)
    { 
        read_from_folder = folderBrowserDialog1.ShowDialog();

        if (read_from_folder == DialogResult.OK)
        {
            files_in_folder = Directory.GetFiles(folderBrowserDialog1.SelectedPath);

            foreach (string fi files_in_folder)
            {
                string fi_nam = filese_in_folder.ToString();
                 ...
             }
          }
       }



    private void button1_Click(object sender, EventArgs e)
    {
                DicomDirectory cop = new DicomDirectory(fi);
                 cop.Load(fi);
    } 
A: 

fi is declared outside of the functions shown so it should have class scope and not local scope in one function. This means you should be able to use it in both of your functions function. This assumes that the two functions you showed are in the same class ("Form1" for example).

You may want to post the class declaration that these functions are contained in also, which will verify that they are in the same class.

Jeremy Sena
A: 

fi won't be local, it's going to be global for that class.

What you have there will work.

Ryan Ternier
+1  A: 

I agree with Frederik, the local fi hides the class-level member. But it isn't clear what you expect to be in that variable in the button click handler.

Because you're looping, if you use the class member fi, you'll only have the last file referenced. This probably doesn't make sense. If you were searching for a match, say, in the loop, and stopping on that match, then un-hiding the class-level fi would make sense, and the code you have will work. What specifically are you trying to do with fi?

Also, the for loop you have won't work as listed... should be:

//  Missing the 'in'
foreach (string fi in files_in_folder)


* Update * In response to your changes in the question, where are you getting this error? In the button click event? On which line? It sounds like a custom internal error to the DicomDirectory object, whatever that is.

James B
the error -> first line in button1_click
What is a DicomDirectory? Is that a line in your code, or a third-party object?
James B