yeah that code is not going to work... The messagebox call does an implicit cast of the value in the field to a string (calls default toString method.) However if the value in the field is a null (dbnull.value) or a value that does not have a tostring method (i.e. geometry, blob, raster...), you will get an error for sure.
Dim pMap As IMap = My.ArcMap.Document.FocusMap
Dim pPIDLayer As IFeatureLayer = pMap.Layer(0)
Dim pPIDFClass As IFeatureClass = pPIDLayer.FeatureClass
Dim pPIDFCursor As IFeatureCursor = pPIDFClass.Search(Nothing, False)
Dim pPIDFeature As IFeature = pPIDFCursor.NextFeature
For i As Integer = 0 To 5
if pPIDFeature.fields.field(i).type <> esriFieldTypeGeometry andalso _
pPIDFeature.fields.field(i).type <>esriFieldTypeBlob andalso _
pPIDFeature.fields.field(i).type <>esriFieldTypeRaster andalso _
pPIDFeature.Value(i) isnot system.dbnull.value then
MsgBox(pPIDFeature.Value(i))
end if
Next
The code above assumes the table has more than 6 fields, otherwise it will also fail. If you check the field types on the featureclass before doing the search, you can pass in a query filter with only the field names in the subfields that can be converted to a string and only query those fields. You still have to check for nulls though...
One last thing, when posting to the forum that you have 'an error' it is useful to the forum to post the exact error message, that cuts out a lot of guessing.