Cary Bondoc
Cary Bondoc

Reputation: 2986

Variable declaration without an 'As' clause; type of Object assumed

I have this form

enter image description here

And I have this 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

And I have this error

1. Variable declaration without an 'As' clause; type of Object assumed.

2. Warning treated as error : Variable declaration without an 'As' clause; type of Object assumed.

The emphasize of the error is in this line of code.

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

I tried to follow what the error says so I changed Dim Schedule_Tab to Dim Schedule_Tab As Form.ControlCollection but it result in this kind of error An unhandled exception of type System.TypeInitializationException' occurred in xxxxxxxxx.exe.

Questions:

  1. What should I do in that situation?
  2. How should I declare Schedule_Tab?

Upvotes: 0

Views: 1778

Answers (2)

Idle_Mind
Idle_Mind

Reputation: 39142

It should be declared like this:

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

Upvotes: 1

Jerry Rhule
Jerry Rhule

Reputation: 47

Try

Dim Schedule_Tab as New frmSettings.Tab_Schedule.Controls

Upvotes: 0

Related Questions