2013-01-24 130 views
0

我創建了一個函數來檢查我的表單中是否存在控件類型,但它沒有奏效,我不知道問題出在哪裏。類型'_Control'未定義

這是我寫的代碼:

Private Function testIfControlExists(ByVal _Control As Control) 
    For Each c As Control In Me.Controls 
     If TypeOf c Is _Control Then 
      Return True 
     End If 
    Next 
    Return False 
End Function 

這是錯誤消息我得到:1種類型 '_Control' 沒有定義

錯誤。

回答

2

如果你想檢查表具有控制類型,那麼你可以這樣做:

Public Function testIfControlExists(ByVal _Control As Control) As Boolean 
    For Each c As Control In Me.Controls 
     If c.GetType Is _Control.GetType Then 
      Return True 
     End If 
    Next 
    Return False 
End Function 
0

變化

If TypeOf c Is _Control Then 

If TypeOf c Is Control Then 

好運

+0

但是,這是檢驗c是一個Control,我想測試c,如果它是我在我的函數中作爲參數給出的類型 –

0

參見文檔here

你不能在你嘗試的方式來使用它。你會使用它針對數據類型的名稱,如IntegerString