HOW TO
Use the script below to create a string field based on a number field so commas can be displayed.
Code:
'This script assumes that a table is the active document
'It will prompt you for the numeric field that you want to
'convert to a string field with commas.
'It will also ask you for a name for the new string field
'The script will put your table in edit mode, add the new field,
'populate the field and then save the changes and stop editing.
aTable = av.GetActiveDoc 'Gets active table
aVtab = aTable.GetVtab
flds = aVtab.GetFields
f_List = List.Make
for each f in flds
if (f.IsTypeNumber) Then
nf = f_List.Add(f)
end
end
select = MsgBox.ListAsString(f_List,"Select a Number Field","Selection")
newFieldName = MsgBox.Input("Please input a name for the new string field:", "New Field","Comma")
newfld = Field.Make(newFieldName,#FIELD_CHAR,20,0)
aVtab.SetEditable(true)
aVtab.AddFields({newfld})
For each rec in aVtab
aVal = aVtab.ReturnValueNumber(select,rec)
'MsgBox.Info(aVal.AsString,"aVal")
com = ","
c = aVal.AsString.Count
If (c = 4) Then
num = (aVal.AsString.Left(1))+(com+aVal.AsString.Right(3))
ElseIf (c = 5) Then
num = (aVal.AsString.Left(2))+(com+aVal.AsString.Right(3))
ElseIf (c = 6) Then
num = (aVal.AsString.Left(3))+(com+aVal.AsString.Right(3))
ElseIf (c = 7) Then
num =
(aVal.AsString.Left(1))+(com+aVal.AsString.Middle(1,3))+(com+aVal.AsString.Right(3))
ElseIf (c = 8) Then
num =
(aVal.AsString.Left(2))+(com+aVal.AsString.Middle(2,3))+(com+aVal.AsString.Right(3))
ElseIf (c = 9) Then
num =
(aVal.AsString.Left(3))+(com+aVal.AsString.Middle(3,3))+(com+aVal.AsString.Right(3))
else
num = aVal.AsString
end 'end If Then
aVtab.SetValue(newfld,rec,num)
end 'For
aVtab.SetEditable(false)
Article ID:000005042
Get help from ArcGIS experts
Download the Esri Support App