Description
Moves the current record position to the first record in the RecordSet.
Syntax
Example
Populate a point layer's X and Y attributes with each point feature's geographic X and Y coordinates.
AddXYValues Example (VBScript) | Copy Code |
---|
Sub AddXYValues(p_pRS, p_XFieldName, p_YFieldName)
Dim pFields
Set pFields = p_pRS.Fields
p_pRS.MoveFirst
Do While Not p_pRS.EOF
pFields(p_XFieldName).Value = pFields.Shape.X
pFields(p_YFieldName).Value = pFields.Shape.Y
p_pRS.Update
p_pRS.MoveNext
Loop
End Sub
'++ here's an example of calling AddXYValues to populate the LATITUDE and LONGITUDE fields of layer 1
Dim pRS
Map.Layers(1).Editable = True
Set pRS = Map.Layers(1).Records
Call AddXYValues(pRS, "LONGITUDE", "LATITUDE")
Set pRS = Nothing
Map.Layers(1).Editable = False |
AddXYValues Example (JScript) | Copy Code |
---|
function AddXYValues(p_pRS, p_XFieldName, p_YFieldName)
{
var pFields = p_pRS.Fields;
p_pRS.MoveFirst();
while (!p_pRS.EOF)
{
pFields(p_XFieldName).Value = pFields.Shape.X;
pFields(p_YFieldName).Value = pFields.Shape.Y;
p_pRS.Update();
p_pRS.MoveNext();
}
}
// here's an example of calling AddXYValues to populate the LATITUDE and LONGITUDE fields of layer 1
Map.Layers(1).Editable = true;
var pRS = Map.Layers(1).Records;
AddXYValues(pRS, "LONGITUDE", "LATITUDE");
pRS = null;
Map.Layers(1).Editable = false; |
MaxByEOF finds the maximum value in the ID field of the first layer by moving forward through the recordset.
RecordSet Example 1 (VBScript) | Copy Code |
---|
Sub MaxByEOF
Dim objRS, objLayer, varCurrValue, varMax
'Get a reference to the first layer
Set objLayer = Application.Map.Layers(1)
'Get a reference to the layer's recordset
Set objRS = objLayer.Records
'Move to the first record
objRS.MoveFirst
'Initialize varMax to the first record
varMax = objRS.Fields("ID").Value
'Move forward through all the records, updating varMax if necessary
While Not objRS.EOF
varCurrValue = objRS.Fields("ID").Value
If varCurrValue > varMax Then
varMax = varCurrValue
End If
objRS.MoveNext
Wend
Set objRS = Nothing
Set objLayer = Nothing
'Display the max in a message box
MsgBox "The maximum value is: " & CStr(varMax)
End Sub
Sub MaxByBOF
Dim objRS, objLayer, varCurrValue, varMax
'Get a reference to the first layer
Set objLayer = Application.Map.Layers(1)
'Get a reference to the layer's recordset
Set objRS = objLayer.Records
'Move to the last record
objRS.MoveLast
'Initialize varMax to the last record
varMax = objRS.Fields("ID").Value
'Move backwards through all the records, updating varMax if necessary
While Not objRS.BOF
varCurrValue = objRS.Fields("ID").Value
If varCurrValue > varMax Then
varMax = varCurrValue
End If
objRS.MovePrevious
Wend
Set objRS = Nothing
Set objLayer = Nothing
'Display the max in a message box
MsgBox "The maximum value is: " & CStr(varMax)
End Sub |
DeleteSelected deletes the selected feature.
RecordSet Example 2 (VBScript) | Copy Code |
---|
Sub DeleteSelected
Dim objSelLayer, objRS
'Get selected layer and index
Set objSelLayer = Application.Map.SelectionLayer
If objSelLayer Is Nothing Then
MsgBox "Please select a feature!"
Exit Sub
End If
'Get the RecordSet of the selected Layer
Set objRS = objSelLayer.Records
'Move to the selected feature
objRS.Bookmark = Application.Map.SelectionBookmark
'Delete the selected feature
objRS.Delete
'Update the RecordSet
objRS.Update
'Refresh the Map
Application.Map.Refresh(True)
End Sub
Sub DeleteSelectedToLast
Dim objSelLayer, objRS
'Get selected layer and index
Set objSelLayer = Application.Map.SelectionLayer
If objSelLayer Is Nothing Then
MsgBox "Please select a feature!"
Exit Sub
End If
'Get the RecordSet of the selected Layer
Set objRS = objSelLayer.Records
'Move to the selected feature
objRS.Bookmark = Application.Map.SelectionBookmark
'Delete all features from the selected feature to the last feature added
While Not objRS.EOF
objRS.Delete
'Update the RecordSet after each deletion
objRS.Update
objRS.MoveNext
Wend
'Refresh the Map
Application.Map.Refresh(True)
End Sub
Sub DeleteSelectedToFirst
Dim objSelLayer, objRS
'Get selected layer and index
Set objSelLayer = Application.Map.SelectionLayer
If objSelLayer Is Nothing Then
MsgBox "Please select a feature!"
Exit Sub
End If
'Get the RecordSet of the selected Layer
Set objRS = objSelLayer.Records
'Move to the selected feature
objRS.Bookmark = Application.Map.SelectionBookmark
'Delete all features from the selected feature to the first feature added
While Not objRS.BOF
objRS.Delete
'Update the RecordSet after each deletion
objRS.Update
objRS.MovePrevious
Wend
'Refresh the Map
Application.Map.Refresh(True)
End Sub |
See Also