没有'As'子句的变量声明;假定的对象类型

时间:2015-08-10 01:03:54

标签: vb.net form-control

我有 form

enter image description here

我有 code

'For Tab Schedule
Dim Schedule_Tab = frmSettings.Tab_Schedule.Controls 'the tab page for schedule
Dim Panel_Set_Num As String
Dim Set_Num As String = "00"

Public Function Schedule_Get() As String
    For Each Ctrl_Panel_Set As Control In Schedule_Tab
        If TypeOf Ctrl_Panel_Set Is Panel And Ctrl_Panel_Set.Name.StartsWith("Panel_Set_") Then
            For Each Ctrl_Lbl_Temp In Ctrl_Panel_Set.Controls
                If TypeOf Ctrl_Lbl_Temp Is Label Then
                    If Ctrl_Lbl_Temp.Name.StartsWith("Lbl_Temp_") Then
                        If Ctrl_Lbl_Temp.Text = "0" Then
                            Panel_Set_Num = CType(Ctrl_Panel_Set, Panel).Name
                            Set_Num = "CSR" & Panel_Set_Num.Substring(Panel_Set_Num.Length - 2) & "^"
                            Return Set_Num
                        End If
                    End If
                End If
            Next
        End If
    Next Ctrl_Panel_Set
    Return "Done"
End Function

我有 error

  

1。没有'As'子句的变量声明;假定的对象类型。   
  
   2。警告视为错误:没有'As'子句的变量声明;假定的对象类型。

错误的 emphasize 位于此行代码中。

Dim Schedule_Tab = frmSettings.Tab_Schedule.Controls 'the tab page for schedule

我尝试按照错误说明,因此我 changed Dim Schedule_Tab转到Dim Schedule_Tab As Form.ControlCollection,但会导致此类错误 {{1 }}

An unhandled exception of type System.TypeInitializationException' occurred in xxxxxxxxx.exe

  1. 在那种情况下我该怎么做?
  2. 我应该如何声明 Questions:

2 个答案:

答案 0 :(得分:1)

应该这样声明:

Dim Schedule_Tab As Control.ControlCollection = frmSettings.Tab_Schedule.Controls

答案 1 :(得分:0)

尝试

Dim Schedule_Tab as New frmSettings.Tab_Schedule.Controls