Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to select data based on whether it starts with certain characters and then update a field. For example if [Asbuilt] starts with "WL" then do something. Here are the two methods I have tried and neither work.

dim hyplink as string
If InStr([Asbuilt],"WL") then
   hyplink = "Water Info\Water AsBuilt Scans\City_Waterlines_WL\" & [Asbuilt]
   InStr([Asbuilt], "CWL") then
   hyplink = "Water Info\Water AsBuilt Scans\County_Waterlines_CWL\" & [Asbuilt]
hyplink = [hyperlink]
End If

Dim hyplink As String
Dim asbuilt as string
asbuilt = [Asbuilt]
If asbuilt.startswith("WL") then
   hyplink = "Water Info\Water AsBuilt Scans\City_Waterlines_WL\" & [Asbuilt]
   hyplink = [Hyperlink]
End if
share|improve this question
The second example is the better way to go about it, but the syntax looks odd to me. What's not working about it? – nagytech Apr 9 '13 at 0:19

As @Geoist said, the 2nd option that you had looks the best. It took me a bit to figure out the oddity in the code though. There are a couple of things going on.

  1. Turns out you are mixing code types. The .startswith() function is Python. The rest of what you were doing was VBScript. To accomplish the same thing, you would want to use the InStr functions, of Left, Right and Mid.
  2. Depending on what version of ArcGIS you are using, there may be an issue with the way you declared your variables. If you are using ArcGIS 10 or newer, then take a look at the relevant help file that discusses Field Calculator Examples. The salient point is that:

VBScript does not allow you to explicitly declare any data types; all variables are implicitly Variant. Statements like Dim x as String should be removed or simplified to Dim x.

So, where you defined your two variables as String, they would need to be simply defined as Dim hyplink and Dim asbuilt.

Here is a VBScript code sample that does what you are looking for:

Parser:  VBScript

Expression: hyplink

Code Block:
  Dim hyplink
  Dim asbuilt
  asbuilt = [Asbuilt]
  If left(asbuilt,2) = "WL" then
     hyplink = "Water Info\Water AsBuilt Scans\City_Waterlines_WL\" & asbuilt
     hyplink = [Hyperlink]
  End if

If you want to use Python, try this code sample instead:

Parser:  Python

Expression:  fixhyperlink(str(!Hyperlink!),str(!Asbuilt!))

Code Block:

def fixhyperlink(hyperlink,asbuilt):
  if (asbuilt.startswith("WL")):
    hyplink = "Water Info\Water AsBuilt Scans\City_Waterlines_WL\" + asbuilt
    hyplink = hyperlink
  return hyplink

Please note that there are major differences in syntax between the VBScript and the Python languages. Please refer to the Field Calculator link above for some basic information, or go here for more detailed information on Python: Python

Hope this helps!

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.