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.

Some questions about VB scipts:

  1. Can I read and modify the code of a VB script? If the answer is yes, how can I do it?
  2. How can I run a VB script?
  3. Can I use it as a VBA code eg.using variables instead of certain data as defined in a model created using the Model Builder?

Thanks

share|improve this question
add comment

1 Answer

up vote 6 down vote accepted

One important distinction between VBScript and VBA is that VBScript does not support ArcObjects because the ArcObjects classes do not implement IDispatch. See the "IDispatch interface" section of Introduction to COM in the VBA SDK help for more info.

Another is that VBScript does not allow or require the Dim'ing of variables of a specific data type (all variables are of type Variant in VBScript, so use Set only).

You can however use the Geoprocessing framework with VBScript, although it is not well documented or supported, as Python has become the favored scripting language for ArcGIS.

See the "Creating the geoprocessor with Perl, VBScript, or JScript" section of Creating the Geoprocessor Object in the ArcGIS Desktop help:

Set gp = WScript.CreateObject("esriGeoprocessing.GPDispatch.1")
gp.workspace = "c:/Tongass"
gp.clip "standb4", "clipcov", "standb4_clip", "POLY", "1.25"

You might find VBScript geoprocessing script examples on the old ArcScripts and the archived ESRI forums.

But my suggestion is to leave both VBScript and VBA behind and learn Python, or a compiled language such as VB.NET, C#, Java, or C++ instead.

share|improve this answer
1  
Agreed - forget about VBScript, it's as much as dead - go with Python for scripting. –  Chad Cooper Oct 7 '11 at 18:21
    
VBScript inside a Field Calculator does use ArcObjects e.g. Dim Output As Double Dim pPoint As IPoint Set pPoint = [Shape] Output = pPoint.X Of Course that is within the ArcGIS environment. –  dslamb Oct 7 '11 at 20:55
    
@dslamb, that's VBA and was removed from the Field Calculator in ArcGIS 10, IIRC. –  blah238 Oct 7 '11 at 23:09
    
Thanks for the answers although they do not ablsolutely focus on my questions. I agree with you that VB scripts and VBA are almost dead. However, I am not a professional progarammer; I am a planner-engineer who begun a PhD project around 2008 using ArcGIS 9.X and VBA. So, it is not wortwhile for me to move in a new language now that I am close to finish. For me, ArcGIS and VBA are just the tools to prove my concepts, theories and methodologies.... –  Demetris Oct 8 '11 at 6:38
1  
Okay, to answer your questions directly: 1) Yes, you can edit .vbs files in any text editor. 2) Through Windows Script Host. Just make sure .vbs files are associated correctly with wscript.exe or cscript.exe. 3) Yes you can read parameters in from the command line and call geoprocessing tools and models. Beyond that I can't say much as I have never used VBScript for geoprocessing. Also I bet that you can pick up Python faster than you think! –  blah238 Oct 8 '11 at 7:12
show 2 more comments

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.