r2d2_25

Code Migration from VBA to VB.NET

Discussion created by r2d2_25 on Apr 8, 2011
Latest reply on Apr 13, 2011 by olamr
I want to migrate some little codes from VBA to VB.NET, but I don't understand any online help, because I'm no programmer! It's only some little code, like to add a field in a table. I have got the VBA code here:

-----------------------------------------------------------------------------------
Sub AddField_Name1()
On Error GoTo ErrorHandler
'
'
Dim pMxDoc As IMxDocument
Dim pLayer As ILayer
Dim pFLayer As IFeatureLayer
Dim pFeatClass As IFeatureClass
Dim NewField As IFieldEdit
Dim strFieldName As String
Dim intFieldType As Integer
Dim intLength As Integer
'
'
'Verweis auf das aktuelle Dokument
Set pMxDoc = ThisDocument
'
Set pLayer = pMxDoc.SelectedLayer
If pLayer Is Nothing Then
MsgBox "Achtung, es ist kein Layer selektiert"
Exit Sub
End If
Set pFLayer = pLayer
Set pFeatClass = pFLayer.FeatureClass
'
' Eingabe der Feldnamen
strFieldName = "Name1"
'
'
intFieldType = 4
intLength = 75
Set NewField = New Field
With NewField
.Length = intLength
.Type = intFieldType
.Name = strFieldName
'
' Kontrolle, ob Feldname schon vorhanden
If pFeatClass.FindField(strFieldName) > -1 Then
  MsgBox "Das Feld '" & strFieldName & "' ist bereits vorhanden, bitte anderen Feldnamen angeben!"
  Exit Sub
  Else
  'MsgBox "Das Feld '" & strFieldName & "' ist noch nicht vorhanden und wird erzeugt!"
End If
'
pFeatClass.AddField NewField 'Neues Feld wird hinzugefügt
'
Exit Sub
'
ErrorHandler:
MsgBox "Es ist ein Fehler aufgetreten, das Programm wird beendet!"
'
'
End With
End Sub
-------------------------------------------------------------------------------------
Can somebody give me some help?? I Don't know what to do. I followed the beginning steps in VisualStudio 2008, but where do I have to put snippets and References?

I Hope somebody of you as a little time to help me :)! Please

Thank you for your help!

Greetings

Outcomes