Re: Newbie
- From: "Bob Barrows [MVP]" <reb01501@xxxxxxxxxxxxxxx>
- Date: Wed, 23 Jan 2008 07:23:52 -0500
Barry wrote:
I have imported my sample (.vbs) script into Access' Visual Basic
Editor, and
Why? What was your purpose in doing this? (nothing wrong with doing it - it
just may help us avoid a long drawn-out, and ultimately pointless
conversation if we know why you need to do this)
ran as is (see script below post). Errors came up
Right. vbscript is not VBA
...the first of
which
stated "Compile error: Invalid outside procedure", so I looked it up
in the
Help section and added "Property" to second line (of the actual
script, under
header),
I'm not sure what prompted that action. A procedure is a sub (subroutine) or
function. It was telling you that you needed to encapsulate your code in
either a function or a sub:
Sub MySub()
'your code
End Sub
and ran again...then an error stated "Compile error: Argument
required for Property Let or Property Set", but I did not understand
this
Help section. The "=" was highlighted on the second line of script,
in this
instance.
There is too much information about this than is possible to convey in a
newsgroup post. You need to read the documentation more carefully.
I searched the Help for "VBScript" and found that it is somehow
differenct
scripting language than VBA (based on this ADO).
No. Again, you need to read a little more carefully. Nowhere does the
documentation say that either vbscript or VBA are "based" on ADO. ADO is a
COM library containing the functionality to enable a program that uses it to
communicate and work with a database. Because it is a COM library, it can be
used by any language that has the ability to call COM libraries. All the
VB-based languages: VB, VBA and vbscript have this ability.
VBA is not considered to be a scripting language. Most scripting languages
have the word "script" incorporated as part of the language name: vbscript,
javascrit, ecmascript, perlscript. To attempt to put it simply, scripting
languages are usually based on a "parent" language as far as language
elements, syntax and keywords are concerned. The parent language is usually
a fully compilable language (in other words it is possible to create a
compiled, stand-alone executable file). Scripting languages are usually
"interpreted" and compiled on the fly.
vbscript is based on VB.
VBA is kind of a gray zone - it is compilable but cannot be used to create a
sthandalone executable. Instead, its compiled version is incorporated in the
Access database containing it.
I do not know what
"ADO" is
and therefore, how to incorporate it into a VBScript.
ADO must be getting used by the ArcGIS/ModelBuilder library so it does not
need to be
Can anyone please look at my sample script below and help me to
adjust so
that I can run the outside process from within Access (2003)?
You mean via a user pressing a form button? OK, now we are getting
somewhere. I now know I won't be wasting my time helping you convert this to
VBA.
This question is offtopic here and should have been posted to an Access
group (look under "Office Solutions" in the table of contents over there.
You will see the Access hierarchy, under which you should see the "vba"
groups. I will make a start at this, but you should post followup questions
to the relevant newsgroup.
Script starts below:
'
---------------------------------------------------------------------------
' TabletoFeatureClass.vbs ' Created on: Tue Jan 22 2008 12:22:58 PM
' (generated by ArcGIS/ModelBuilder)
'
---------------------------------------------------------------------------
Your first task is to set a reference to the ArcGIS/ModelBuilder library.
With the code module open, go to the menu Tools>References. A dialog box
with a listbox containing all the installed libraries on your computer will
appear. Scroll down until you see the ArcGIS library, click the checkbox to
select it and click OK.
Now, let's start by encapsulatiing this in a sub - you can name it anything
you want. I've guessed to use the name "BuildModel":
Public Sub BuildModel()
First of all, VBA is a "typesafe" language, which makes it a "best practice"
to declare all variables, assigning the proper datatypes to them:
Dim gp As esriGeoprocessing.GPDispatch.1
Dim Well_test as String
Dim XYWells as String
Dim XYWells_end as String
Dim XYWells_Layer as String
************side track *******************************
It's a good practice to declare variables in vbscript as well, but vbscript
is not typesafe (all variables are variants) so it does not support the "As
datatype" part in Dim statements. In vbscript I would do this:
dim gp, Well_test, XYWells, XYWells_end, XYWells_Layer
********************************************************
' Create the Geoprocessor object
set gp = WScript.CreateObject("esriGeoprocessing.GPDispatch.1")
There is no WScript object built into VBA. It is not needed because you can
use this syntax to instantiate a COM library and assign it to a variable:
Set gp = esriGeoprocessing.GPDispatch.1
<snip>
End Sub
I don't see anything else that needs to change. Give it a try, and if you
have further problems, post to the Access VBA group. You should also
consider getting assistance from ArcGIS
Bob Barrows
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
.
- Follow-Ups:
- Re: Newbie
- From: Bob Barrows [MVP]
- Re: Newbie
- References:
- Newbie
- From: Barry
- Newbie
- Prev by Date: Newbie
- Next by Date: Re: Newbie
- Previous by thread: Newbie
- Next by thread: Re: Newbie
- Index(es):