Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I want to do some advanced level scripting with VBA in the field calculator. I have done a simple coding in the code block. Here is the codes.

dim X
  if [Name]="University" then
    X=101101
  elseif [Name]= "College" then
    X=101102
  elseif [Name]= "Medical College" then
    X=101103
  elseif [Name]= "School" then
    X=101104
  else
    X=""
  end if

This is working correctly. But I want to do something more. Those are-

  1. If the Name field contain the word University or College or Medical College or School then X return the expecting value.
  2. Is it possible to create new fields through VBScript? If its possible then the X will split into two from its middle (3-3) and put the value in the newly generated column/fields.

If this possible it will help me a lot.

Thanks in advance

share|improve this question
add comment

2 Answers 2

up vote 2 down vote accepted

For your first question, you can use InStr() to find out whether a string exists within another string

dim X   
if InStr([Name], "University") then
   X=101101 
elseif  InStr([Name], "Medical College") then 
  X=101103 
elseif  InStr([Name], "College") then 
  X=101102 
elseif  InStr([Name], "School") then 
  X=101104 
else 
  X=""
end if

Note that you'd have to change your logic slightly, running the If statement on "Medical College" before "College". In your original logic, the Instr function would assign X=101102 to both "College" and "Medical College" since the word "College" is found in each string.

share|improve this answer
    
I am facing some problem. Can you help me a little. I want a case insensitivity. If I wrote "college" instead of college its not returning anything. What should I do? –  Devils Dream Jan 10 '13 at 7:18
    
Use the syntax if InStr( LCase( [Name] ),"college" ) then –  kenbuja Jan 10 '13 at 14:38
add comment

Yes and no. You can create fields from a standalone VBScript, but not within Field Calculator. See link below for how to write VBScript:

Creating the geoprocessor object

I would recommend learning and using python instead for the task that you are trying to do. You could use a SearchCursor to search for the field values, then add your fields based on the SearchCursor result and then calculate.

share|improve this answer
add comment

Your Answer

 
discard

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.