Field Calculator VBA ArcGIS 9.3 - how to replace the last three characters of a string?

5502
14
Jump to solution
09-22-2014 08:32 AM
StephenDrew1
New Contributor III

Hello, I'm a newbie to VBA Script, so any of the below script could be wrong. I'm trying to use Field Calculator to replace any "_10" at the end of a filename (i.e. an entry in a field, in an attribute table) with "_11". Could anyone help me please? Many thanks in advance! sdrew1

 

Pre-logic VBA Script Code

Dim MyStr as string

Dim strLen as integer

 

strLen = Len([FILENAME])

 

If Right([FILENAME],3) = "_10" Then

MyStr = Left([FILENAME], strLen-3)) & "_11"

Else

MyStr = [FILENAME]

End if

 

Filename =

MyStr

14 Replies
StephenDrew1
New Contributor III

Ah great, thanks very much! Good to see the Replace function written out, thats informative!

0 Kudos
JoeBorgione
MVP Emeritus

A simple find and replace couldn't be used here?

That should just about do it....
0 Kudos
StephenDrew1
New Contributor III

Hi Joe, Thanks for reply. I did consider that but I didn't want it to get rid of the '_100' or '_210' so I thought it might be easier the alternative route. Sorry, you weren't to know that there might be '210' etc as an alternative. Cheers again.

0 Kudos
JoeBorgione
MVP Emeritus

My mistake; just re-read the original post and I was thinking attribute value and you are renaming files.

That should just about do it....
0 Kudos
StephenDrew1
New Contributor III

No problem - thanks for posting.

0 Kudos