ge_zi
论坛版主
论坛版主
  • 注册日期2003-09-04
  • 发帖数278
  • QQ
  • 铜币633枚
  • 威望0点
  • 贡献值0点
  • 银元0个
阅读:1247回复:3

数据编辑疑惑。

楼主#
更多 发布于:2004-07-19 10:56
<P>这个函数是先创建一个表,包括3个字段,OID,Shape,Deviceid    </P>
<P>Private Sub CreateFeatureClass(pFeatureWorkspace As IFeatureWorkspace, className As String, GeomType As esriGeometryType, pFeatureClass As IFeatureClass, progress As Long)
  lblSchema.Caption = "Creating Feature Class " ; className</P>
<P>  ' Add the Fields to the class the OID and Shape are compulsory
  Dim pFieldsEdit As IFieldsEdit
  Set pFieldsEdit = New Fields
  pFieldsEdit.FieldCount = 3</P>
<P>  Dim pFieldEdit As IFieldEdit
  
  Set pFieldEdit = New Field
  With pFieldEdit
    .Name = "OID"
    .Type = esriFieldTypeOID
    .AliasName = "Object ID"
    .IsNullable = False
  End With
  Set pFieldsEdit.Field(0) = pFieldEdit</P>

<P>  Dim numPoints As Long
  numPoints = 1
  Select Case GeomType
    Case esriGeometryPoint
      numPoints = 1
    Case esriGeometryPolyline
      numPoints = 2
    Case esriGeometryPolygon
      numPoints = 4
  End Select
  
  Dim pGeomDef As IGeometryDefEdit
  Set pGeomDef = New GeometryDef
  With pGeomDef
    .AvgNumPoints = numPoints
    .GeometryType = GeomType
    .GridCount = 1
    .GridSize(0) = 100
    .HasM = False
    .HasZ = False
  End With
  
  Set pFieldEdit = New Field
  With pFieldEdit
    .Name = "Shape"
    .Type = esriFieldTypeGeometry
    .IsNullable = True
    .Editable = True
    .AliasName = "Shape"
    Set .GeometryDef = pGeomDef
  End With
  Set pFieldsEdit.Field(1) = pFieldEdit
  
  'dddddddddddddd
Set pFieldEdit = New Field
  With pFieldEdit
    .Name = "DeviceID"
    .Type = esriFieldTypeInteger
    .AliasName = "DEVICEID"
    .Precision = 10
    .IsNullable = True
  End With
  Set pFieldsEdit.Field(2) = pFieldEdit
'dddddddddddddd</P>
<P>  Dim pUID As IUID
  Set pUID = New UID
  pUID.Value = "esriCore.Feature"</P>
<P>  Set pFeatureClass = pFeatureWorkspace.CreateFeatureClass(className, pFieldsEdit, pUID, Nothing, esriFTSimple, "Shape", "")
  progress = progress + 1
  prgDatabaseCreation.Value = progress
  prgOverall.Value = prgOverall.Value + 1
End Sub</P>
<P>在这个函数中我想给表格添加记录,但是我不知道怎么给第三个字段deviceid赋值??谢谢</P>
<P>Private Sub CreatePointFeatures(pFeatureClass As IFeatureClass, numberToCreate As Long)
  If (numberToCreate = 0) Then Exit Sub
  
  lblFeatures.Caption = "Creating Points"
  lblFeatures.Refresh
  prgIndividual.Value = 0
  prgIndividual.Max = numberToCreate
  Dim i As Long
  Dim pFeature As IFeature
  Dim pPoint As IPoint
  
  For i = 1 To numberToCreate
    Set pFeature = pFeatureClass.CreateFeature
    Set pPoint = New Point
    pPoint.X = 1001 * Rnd
    pPoint.Y = 1001 * Rnd
    Set pFeature.Shape = pPoint
<FONT color=#ff0000>  </FONT><b><FONT color=#ff0000>  'MsgBox pFeature.Fields(2)
    Set pFeature.Fields(2) = 1   ‘该语句出错,如果去掉则可以运行,但是deviceid字段全部为空。谢谢。</FONT></b>
    
    pFeature.Store
    prgIndividual.Value = i
    prgOverall.Value = prgOverall.Value + 1
  Next i
End Sub</P>
喜欢0 评分0
destnity
路人甲
路人甲
  • 注册日期2004-03-25
  • 发帖数341
  • QQ
  • 铜币272枚
  • 威望0点
  • 贡献值0点
  • 银元0个
1楼#
发布于:2004-07-19 11:57
<P>可以采用下面的方法,而用你的<b><FONT color=#ff0000>Set pFeature.Fields(2) = 1  ,百分之一万要出错。</FONT></b></P><P>   Dim prow As IRow
   Set prow = pFeature
   prow.Value(prow.Fields.FindField("deviceid")) = 你要赋的值。
   prow.Store
   pFeature.Store
</P>
签 名: 不能超过 250 个字符 文字将出现在您发表的文章的结尾处。
举报 回复(0) 喜欢(0)     评分
ge_zi
论坛版主
论坛版主
  • 注册日期2003-09-04
  • 发帖数278
  • QQ
  • 铜币633枚
  • 威望0点
  • 贡献值0点
  • 银元0个
2楼#
发布于:2004-07-19 12:47
<P>果然如此,成功了。可是在编程时没有办法得到任何提示?如何办?谢谢,destnity</P>
举报 回复(0) 喜欢(0)     评分
destnity
路人甲
路人甲
  • 注册日期2004-03-25
  • 发帖数341
  • QQ
  • 铜币272枚
  • 威望0点
  • 贡献值0点
  • 银元0个
3楼#
发布于:2004-07-19 12:54
<P>你是说出错的代码及描述吗?</P><P>可以使用 </P><P>pub xxx xxx</P><P>on error goto EH:</P><P>exit sub</P><P>EH:</P><P>  msgbox cstr(err.number) ; ":" ; err.descript?</P><P>end sub</P>
签 名: 不能超过 250 个字符 文字将出现在您发表的文章的结尾处。
举报 回复(0) 喜欢(0)     评分
游客

返回顶部