jcurtis3

Convert vba code  to C# for arc 10

Discussion created by jcurtis3 on Mar 15, 2011
Latest reply on Mar 16, 2011 by mike.robb
I have a code snippet of VBA and I need to convert this to C# code Very Quickly. Can anyone help

Private Sub SignPost_MouseDown(ByVal button As Long, ByVal shift As Long, ByVal x As Long, ByVal y As Long)

   ' Create connection string to connect to SQL Server
    Dim ConnectStr As String
    ConnectStr = "SERVER=esriappprod.memphis.edu;INSTANCE=5151;VERSION=cpgismob1;USER=cofm;PASSWORD=uofm"

    ' Open the SQL Server Workspace Factory
    Dim pWSF2 As IWorkspaceFactory2
    Set pWSF2 = New SdeWorkspaceFactory
    Dim pWS As IWorkspace
    Set pWS = pWSF2.OpenFromString(ConnectStr, 0)
    
    ' Start Editing
    Set pWSEdit = pWS
    pWSEdit.StartEditing True
    pWSEdit.StartEditOperation

    ' Open the feature class
    Dim pFeatureWS As IFeatureWorkspace
    Set pFeatureWS = pWS
    Dim pFClass As IFeatureClass
    Set pFClass = pFeatureWS.OpenFeatureClass("COFM.SignPost")
    
    ' Create new Feature Layer and Point.
    Dim pFL As IFeatureLayer2
    Dim pMxDoc As IMxDocument
    Set pMxDoc = ThisDocument
    Set pMap = pMxDoc.FocusMap
    Dim pBasicMap As IBasicMap
    Set pBasicMap = pMap
    Dim pMxApplication As IMxApplication
    Set pMxApplication = Application
    Dim pRow As IRow
    Dim pRowObj As IRowEdit
    Set pRow = pRowObj
   
    Dim pMVal As Long
    Set pFeat = pFClass.CreateFeature
    Dim pPoint As IPoint
    Set pPoint = pMxDoc.CurrentLocation
    Set pFeat.Shape = pPoint
    Dim pEnvelope As IEnvelope
    Set pEnvelope = pPoint.Envelope
    
    Dim pIdObj As IIdentifyObj
    Dim pFeatIdObj As IFeatureIdentifyObj
    
    Set pFeatIdObj = New FeatureIdentifyObject
    pFeatIdObj.Feature = pFeat
    
    Set pIdObj = pFeatIdObj
    pIdObj.Flash pMxApplication.Display
    
    pFeat.Store
    pMap.SelectByShape pEnvelope, pMxApplication.SelectionEnvironment, True
       
    'Populates the "MOBILEUPDATE" field with the date and time the point was created
    Dim MyDate As Date
    MyDate = FormatDateTime(Now, vbGeneralDate)
    pFeat.Value(pFeat.Fields.FindField("MOBILEUPDATE")) = MyDate
    pFeat.Store
       
    'Records VersionName and EditorName
    Dim pVer As String
    pVer = ("cpgismob1")
    pFeat.Value(pFeat.Fields.FindField("MOBILEVERSION")) = pVer
    Dim strNew As String
    strNew = LCase(strUserName)
    pFeat.Value(pFeat.Fields.FindField("MOBILEEDITOR")) = strNew
    
    ' Stop Editing and refresh active view
    Dim pAV As IActiveView
    Set pAV = pMap
    pWSEdit.StopEditing True
    pWSEdit.StopEditOperation
    pAV.Refresh
    
End Sub

Outcomes