shravan.phil

VBA to C# Conversion

Discussion created by shravan.phil on Nov 21, 2010
Latest reply on May 2, 2011 by alain.hj
Could anyone help me in converting the below VBA code into C#, i appreciate for the help you guys do.



Public Sub DumpAttributesToFileExample()

'Open a new text file to write to
Open "c:/temp/outfile.txt" For Output As #1

Dim pMxDoc As IMxDocument
Dim pMap As IMap
Dim pFLayer As IFeatureLayer
Dim pFClass As IFeatureClass

Set pMxDoc = ThisDocument
Set pMap = pMxDoc.FocusMap

'Get reference to layer in table of contents (0 is topmost layer)
Set pFLayer = pMap.Layer(0)
Set pFClass = pFLayer.FeatureClass

'Use a Query Filter to select a subset of features using
'a simple SQL where clause
Dim pQFilter As IQueryFilter
Set pQFilter = New QueryFilter
pQFilter.WhereClause = ""

'Establish a cursor used for looping
Dim pFCursor As IFeatureCursor
Set pFCursor = pFClass.Search(pQFilter, True)
Dim pFeature As IFeature
Set pFeature = pFCursor.NextFeature
 
'Loop thru all features and write attributes to output file
Do Until pFeature Is Nothing


'Note: below, pFeature.value(1) and pFeature.value(2) use field index numbers of the 2nd and 3rd fields in the table
'to write the values in these fields to output file. Also, the _ character continues an expression to the next line


Print #1, "Field #2 = " & pFeature.Value(1)   & " and Field #3 = " & pFeature.Value(2)
Set pFeature = pFCursor.NextFeature

Loop

Close #1

End Sub

Outcomes