VB.Net Code: UserForm and RadioButton: Where is my mistake? Please help!!

475
0
04-13-2011 11:57 PM
DeniseL
New Contributor
Hello everybody!

I wrote some code in VB.Net.
I want so add a new individual field in a table. The User can click on a button and write the name of the field in an inputbox, then an userform should open and you can choose the type of the field.
Thats the theory, does somebody know whats wrong?

Perhaps the code
If Formular.RadioButton1.Checked Then
Is this right?
Or this:
Dim Formular As New Form1
Formular.Show()


This is the whole code:
Protected Overrides Sub OnClick()
        Try


            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 strSonder As String
            Dim intLength As Integer


            ''Variable für Fehlermeldung bei Sonderzeicheneingabe
            strSonder = "Bitte kein Sonderzeichen eingeben!"
            '
            'Verweis auf das aktuelle Dokument
            pMxDoc = My.ArcMap.Document

            '
            pLayer = pMxDoc.SelectedLayer
            If pLayer Is Nothing Then
                MessageBox.Show("Achtung, es ist kein Layer selektiert", "", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
                Exit Sub
            End If
            pFLayer = pLayer
            pFeatClass = pFLayer.FeatureClass

            strFieldName = InputBox("Bitte einen Feldnamen eingeben:" & "Feldname")

            'Prüfen, ob Feldnamen korrekt
            If strFieldName Like "*%*" Then
                MessageBox.Show(strSonder)
                Exit Sub
            ElseIf strFieldName Like "*&*" Then
                MessageBox.Show(strSonder)
                Exit Sub
            ElseIf strFieldName Like "*§*" Then
                MessageBox.Show(strSonder)
                Exit Sub
            ElseIf strFieldName Like "*/*" Then
                MessageBox.Show(strSonder)
                Exit Sub
            ElseIf strFieldName Like "*(*" Then
                MessageBox.Show(strSonder)
                Exit Sub
            ElseIf strFieldName Like "*)*" Then
                MessageBox.Show(strSonder)
                Exit Sub
            ElseIf strFieldName Like "*=*" Then
                MessageBox.Show(strSonder)
                Exit Sub
            ElseIf strFieldName Like "*@*" Then
                MessageBox.Show(strSonder)
                Exit Sub
            ElseIf strFieldName Like "*???*" Then
                MessageBox.Show(strSonder)
                Exit Sub
            ElseIf strFieldName Like "[0-9]*" Then
                MessageBox.Show("Der Feldname darf nicht mit einer Zahl beginnen!")
                Exit Sub
            ElseIf strFieldName Like "*!*" Then
                MessageBox.Show(strSonder)
                Exit Sub
            ElseIf strFieldName Like "* *" Then
                MessageBox.Show("Bitte kein Leerzeichen 12eingeben!")
                Exit Sub
            ElseIf strFieldName Like "*.*" Then
                MessageBox.Show("Bitte keinen Punkt eingeben!")
                Exit Sub
            ElseIf strFieldName Like "" Then
                MessageBox.Show("Bitte einen Feldnamen eingeben!")
                Exit Sub
            Else
            End If

            Dim Formular As New Form1
            Formular.Show()
            '-----------------------------------------------------
            If Formular.RadioButton1.Checked Then

                NewField = New Field
                With NewField
                    .Type_2 = esriFieldType.esriFieldTypeInteger
                    .Name_2 = strFieldName
                End With

            ElseIf Formular.RadioButton2.Checked Then

                NewField = New Field
                With NewField
                    .Type_2 = esriFieldType.esriFieldTypeDate
                    .Name_2 = strFieldName
                End With

            ElseIf Formular.RadioButton4.Checked Then

                NewField = New Field
                With NewField
                    .Type_2 = esriFieldType.esriFieldTypeDouble
                    .Name_2 = strFieldName
                    .Precision_2 = 20
                    .Scale_2 = 2
                End With

            Else
                intLength = InputBox("Wie lang soll das Attributfeld sein? " & "Length")
                NewField = New Field
                With NewField
                    .Type_2 = esriFieldType.esriFieldTypeString
                    .Name_2 = strFieldName
                    .Length_2 = intLength
                End With
            End If

            '
            ' Kontrolle, ob Feldname schon vorhanden
            If pFeatClass.FindField(strFieldName) > -1 Then
                MessageBox.Show("Das Feld '" & strFieldName & "' ist bereits vorhanden, bitte anderen Feldnamen angeben!", "", MessageBoxButtons.OK, MessageBoxIcon.Information)
                Exit Sub
            Else
                MessageBox.Show("Das Feld '" & strFieldName & "' ist noch nicht vorhanden und wird erzeugt!")
            End If
            '
            pFeatClass.AddField(NewField) 'Neues Feld wird hinzugefügt
            '


        Catch ex As Exception
            MessageBox.Show("Es ist ein Fehler aufgetreten, das Programm wird beendet!", "", MessageBoxButtons.OK, MessageBoxIcon.Error)

        End Try

        My.ArcMap.Application.CurrentTool = Nothing
    End Sub
0 Kudos
0 Replies