When you create a command through VB.NET, it sets up the hook for the application automatically.Looks like this at the beginning of your code:NOTE: This is autogenerated code! Should already exist in your base command! Public Overrides Sub OnCreate(ByVal hook As Object)
If Not hook Is Nothing Then
m_application = CType(hook, IApplication)
'Disable if it is not ArcMap
If TypeOf hook Is IMxApplication Then
MyBase.m_enabled = True
Else
MyBase.m_enabled = False
End If
End If
' TODO: Add other initialization code
End Sub
So your code should look something like this:Public Function GetLayer(ByVal sLayer) As ILayer
Dim pMxDoc As IMxDocument
Dim i As Integer
Dim players As IEnumLayer
Dim pLayer As ILayer
Dim pL As ILayer
Dim ii As Integer
Dim pCL As ICompositeLayer
pMxDoc = m_application.Document
On Error GoTo GetLayer_Err
players = pMxDoc.FocusMap.Layers(, True)
End If
pLayer = players.Next
Do While Not pLayer Is Nothing
If TypeOf pLayer Is ICompositeLayer Then
pCL = pLayer
For ii = 0 To pCL.Count - 1
pL = pCL.Layer(ii)
If UCase(pL.Name) = UCase(sLayer) Then
GetLayer = pL
Exit Function
End If
Next
Else
If UCase(pLayer.Name) = UCase(sLayer) Then
GetLayer = pLayer
Exit Function
End If
End If
pLayer = players.Next
Loop
Exit Function
GetLayer_Err:
End Function
Should work.