Migrating VBA Script to .Net

Discussion created by keags1 on Jul 7, 2011
Latest reply on Jul 7, 2011 by rwelikal

This is my last attempt at this, I have been trying for the last day to move one script from 9.3.1 to 10.

I have a small Function that runs within a larger VBA script, so far from what I can tell, it falls down in this section when I have converted it to VB.Net:

Private Function GetLayer(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
  Dim pApp As IApplication
  Set pApp = New AppRef
  On Error GoTo GetLayer_Err <---- It doesnt pass this point...

  If TypeOf pApp.Document Is IMxDocument Then
    Set pMxDoc = pApp.Document
    Set players = pMxDoc.FocusMap.layers(, True)
  End If

It does not pass -

pApp = New AppRef

It will also not allow me to use the IApplication due to a "friend" error.
Please could someone help me understand why this is the case?

I am still very new to scripting and have been relying on online samples and help to get me here. From what I can tell this is the last hurdle.

I am using Visual Studio Express 2008
Vb.Net and creating an ArcMap 10 Add-In.

Any and all comments / help will be greatly appreciated.

Thank you!!