2010-04-27 140 views
0
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!"); 
    } 
} 

说,它不包含定义,但在我的GetSchedule cs文件我把它定义不包含GetDataFromNumber的定义但是我已经定义了它?

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类

公共类GetSchedule { 公共GetSchedule(){ IDnumber [] IDnumbers =新ID号[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 ""; 

}}

} 

}

+0

对不起,你需要改变你的问题,一点也不清楚。 – 2010-04-27 21:32:34

+0

即时通讯对不起,我得到一个错误,说GetDataFromNumber没有定义,不接受类型的第一个参数....但GetDataFromNumber在另一个.cs文件中的第二组代码中使用/定义...我能做些什么来纠正这个!?! – 2010-04-27 21:38:26

+0

你确实有一个名为GetSchedule的类吗?如果是这样,将这个定义包含在问题中可能会有所帮助。 – 2010-04-27 21:40:27

回答

0

检查GetSchedule类是否位于您试图从中调用它的相同名称空间中,或者它是否被引用。

它从你的更新后的文章看起来像你的函数GetDataFromNumber是在一个名为IDNumber的类 - 这是问题吗?

尝试:

IDnumber myNumber = new IDnumber(); 
myNumber.GetDataFromNumber(text); 
+0

我所有的.cs文件都在同一个项目下,并在相同的命名空间Eagle_Eye_Class_Finder .... – 2010-04-27 21:56:25

+0

好吧 - 我已经更新了我的答案。很难从你发布的代码中知道,但它看起来像你的函数不在你正在实例化的类中 – 2010-04-27 22:00:29

+0

是的你是对的它是在IDnumber类中,但它的公共所以我不能使用它贯穿我的项目? – 2010-04-27 22:01:33

0

你确定GetDataFromNumberclass定义里面,而不是后右大括号?

+0

是的,我再次检查它是! – 2010-04-27 21:53:20

0

的问题是,因为你正在创建Web表单,并从一个页面复制代码到另一个。当你这样做时,你必须小心,并确保你不改变页面中的第一个指令。它告诉网络代码页面后面它应该在哪里找到定义和代码逻辑。你遇到这个问题的原因是,当你从一个页面复制并粘贴到另一个页面时,它为另一个页面提供了指令,这很可能没有你定义的页面中调用的函数。因此,请确保您将网页的第一行更改为指向它所继承的文件和类的右侧.cs

相关问题