Select to view content in your preferred language

Basic VB or Python help needed

775
4
07-24-2012 02:12 PM
SandraHanslip
New Contributor
I have 2 tasks for which I cannot find the right syntax and really would like some help

First I have a column with strings and I need to calculate how many characters are in each string and put that number in my field_len column. Sounds simple - and sad to say, I did it once but cannot pull it out of my hat again.:cool:
(There are two of these counts and when I ran another calculation on a separate field, the numbers switched ie: in a field where most values were 14 they are now 10 and the field where the values should and used to be mostly 10, they are now 14.) So I just want to run the character counts again.

Second, I have a column (string) which I need to take the 1st 10 characters and copy over to another field - actually, did this once as well but it left over 1000 blank - for no discernible reason. Copy and pasting these one by one is gonna take forever.

Any help or directions are greatly appreciated. I can usually find my way through Python or VB but I just can't get there on this.

Sandra
Tags (2)
0 Kudos
4 Replies
SolomonPulapkura
Occasional Contributor III

  1. Right click on field_len column > Field Calculator > len(!String Field!)

  2. Right click on the other column > Field Calculator > !String Field![0:10]

0 Kudos
SandraHanslip
New Contributor

  1. Right click on field_len column > Field Calculator > len(!String Field!)

  2. Right click on the other column > Field Calculator > !String Field![0:10]



Thank you for your response.
I tried this and the process failed and the error I get is 99999
I manually corrected the Account Numbers so they are 10 characters if available, now just need to get the counts.

I have attached a word doc with screen captures of errors and abbreviated table I am trying to run calculations.
Acctnum_Len should return a maximum of 10 and acctID_len should return a maximum of 14  (These fields are to give a count of how many characters in Account Identifier and Account Number)

Thanks again,
Sandra
0 Kudos
SolomonPulapkura
Occasional Contributor III
In the Field Calculator dialog select Python parser at the top instead of VB and try again.

The only other thing I would check is the length and type of the acctID_len and Acctnum_Len fields.
If they are TEXT fields make sure the field length is not less than the number of characters it will hold.
0 Kudos
SandraHanslip
New Contributor
In the Field Calculator dialog select Python parser at the top instead of VB and try again.

The only other thing I would check is the length and type of the acctID_len and Acctnum_Len fields.
If they are TEXT fields make sure the field length is not less than the number of characters it will hold.


Yes, thank you again. I have already checked all of those and I just can't get the Acctnum_Len field calculator to count the characters in the account number field. I did it before for both fields and it was not difficult but I just can't get there again!

It's really strange that they have reversed themselves. Maybe I'll just switch the names of the *_len fields;)

Sandra
0 Kudos