阅读:1247回复:3
数据编辑疑惑。
<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> |
|
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> |
|
|
2楼#
发布于:2004-07-19 12:47
<P>果然如此,成功了。可是在编程时没有办法得到任何提示?如何办?谢谢,destnity</P>
|
|
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>
|
|
|