Solved! Go to Solution.
I know how to do it in Avenue and I see old threads about how to do it in VBA. But how do I do it now with VB or Python? This should be simple but every time I get an error. I have one column with numbers and its a String field. I added a new field as a Long and am trying to use the field calculator to populate it with the same data as the string field, but as a number. How?
If IsNumeric([String_Field]) Then Output = CLng(Trim([String_Field])) ' Or use Cdbl for double Else Output = [Number_Field] ' This will keep Null values. Or use 0 or -1 End If
I know how to do it in Avenue and I see old threads about how to do it in VBA. But how do I do it now with VB or Python? This should be simple but every time I get an error. I have one column with numbers and its a String field. I added a new field as a Long and am trying to use the field calculator to populate it with the same data as the string field, but as a number. How?
If IsNumeric([String_Field]) Then Output = CLng(Trim([String_Field])) ' Or use Cdbl for double Else Output = [Number_Field] ' This will keep Null values. Or use 0 or -1 End If
Richard, If your ever down in Camarillo stop by, I owe you a big steak dinner for all the help you've provided for me time and again!
Thanks Richard. I needed to add zeros in front of the numbers less than three digits long. By putting them in a number field I could sort them, then select the ones in the text field in one swoop, instead of hunting and pecking for them with the odd sorting of text fields. But your tips for finding blanks will be very useful in the future too.
def AddZeros(strFld): If strFld.isnumeric(): longNumber = round(float(strFld), 0) else: longNumber = 0 return "%(num)04.0f" % {'num':longNumber}