tags:

views:

89

answers:

2
public void button2_Click(object sender, System.EventArgs e)
{
    string text = textBox1.Text;
    Mainform = this;

    this.Hide();

    GetSchedule myScheduleFinder = new GetSchedule();
    string result = myScheduleFinder.GetDataFromNumber(text);// says there is no definition
    if (!string.IsNullOrEmpty(result))
    {
        MessageBox.Show(result);
    }
    else
    {
        MessageBox.Show("Enter A Valid ID Number!");
    }
}

says it does not contain definition for it but on my GetSchedule .cs file i have it defined

public string GetDataFromNumber(string ID)//defined here
{

    foreach (IDnumber IDCandidateMatch in IDnumbers)
    {

        if (IDCandidateMatch.ID == ID)
        {
            StringBuilder myData = new StringBuilder();
            myData.AppendLine(IDCandidateMatch.Name);
            myData.AppendLine(": ");
            myData.AppendLine(IDCandidateMatch.ID);
            myData.AppendLine(IDCandidateMatch.year);
            myData.AppendLine(IDCandidateMatch.class1);
            myData.AppendLine(IDCandidateMatch.class2);
            myData.AppendLine(IDCandidateMatch.class3);
            myData.AppendLine(IDCandidateMatch.class4);
            //return myData;
            return myData.ToString();
        }
    }
    return "";
}

GetSchedule Class

public class GetSchedule { public GetSchedule() { IDnumber[] IDnumbers = new IDnumber[3]; IDnumbers[0] = new IDnumber() { Name = "Joshua Banks", ID = "900456317", year = "Senior", class1 = "TEET 4090", class2 = "TEET 3020", class3 = "TEET 3090", class4 = "TEET 4290" }; IDnumbers[1] = new IDnumber() { Name = "Sean Ward", ID = "900456318", year = "Junior", class1 = "ENGNR 4090", class2 = "ENGNR 3020", class3 = "ENGNR 3090", class4 = "ENGNR 4290" }; IDnumbers[2] = new IDnumber() { Name = "Terrell Johnson", ID = "900456319", year = "Sophomore", class1 = "BUS 4090", class2 = "BUS 3020", class3 = "BUS 3090", class4 = "BUS 4290" };

    }
    public class IDnumber
    {
        public string Name { get; set; }
        public string ID { get; set; }
        public string year { get; set; }
        public string class1 { get; set; }
        public string class2 { get; set; }
        public string class3 { get; set; }
        public string class4 { get; set; }


       public static void ProcessNumber(IDnumber myNum)
            {
                StringBuilder myData = new StringBuilder();
                myData.AppendLine(myNum.Name);   
                myData.AppendLine(": ");
                myData.AppendLine(myNum.ID);
                myData.AppendLine(myNum.year);
                myData.AppendLine(myNum.class1);
                myData.AppendLine(myNum.class2);
                myData.AppendLine(myNum.class3);
                myData.AppendLine(myNum.class4);  
                MessageBox.Show(myData.ToString());
            }

        public string GetDataFromNumber(string ID)
        {
            IDnumber[] IDnumbers = new IDnumber[3];
            foreach (IDnumber IDCandidateMatch in IDnumbers)  

            { 

                if (IDCandidateMatch.ID == ID)
                {
                 StringBuilder myData = new StringBuilder();
                 myData.AppendLine(IDCandidateMatch.Name);   
                 myData.AppendLine(": ");
                 myData.AppendLine(IDCandidateMatch.ID);
                 myData.AppendLine(IDCandidateMatch.year);
                 myData.AppendLine(IDCandidateMatch.class1);
                 myData.AppendLine(IDCandidateMatch.class2);
                 myData.AppendLine(IDCandidateMatch.class3);
                 myData.AppendLine(IDCandidateMatch.class4);  
                 //return myData;
                 return myData.ToString();
    }
}
return "";

} }

}

}

A: 

Did you make sure GetDataFromNumber is inside the class definition, and not after the closing brace?

egrunin
yes ive double checked that it is!
JB
A: 

Check that the GetSchedule class is in the same namespace that you are trying to call it from, or that it is referenced.

It looks from your updated post like your function GetDataFromNumber is in a class called IDNumber - is this the problem?

Try:

IDnumber myNumber = new IDnumber();
myNumber.GetDataFromNumber(text);
pm_2
all my .cs files are in the same project and under the same namespace Eagle_Eye_Class_Finder....
JB
Okay - I've updated my answer. It's difficult to tell from the code you've posted, but it looks like your function is not in the class that you're instantiating
pm_2
yes you are right it is in the IDnumber class, but its public so shouldnt i be able to use it throughout my project?
JB
Yes - but you have to instantiate the correct class. If you instantiate the IDnumber class then you'll be able to call it using that.
pm_2
OK that makes sense, i am a little new to C#, any help allowed on how i could instantiate this the correct way???
JB
I've updated the post with an example.
pm_2