VBScript Syntax

Z

zacks

I am trying to write a VBScript that will be executed by a VB.NET 2005
program using Microsoft's Scripting Control. I have gotten a few simple
scripts to work but I am having problems on one. I need to parse a
character string value and pick out the pieces that are delimited by
periods. For example, the input value may be:

58000.44.51.

and I want to parse out the 58000 and return that value. I wrote the
following script:

Dim MyString As String
MyString = ScriptProcessor.Fields.Item(0)
ScriptProcessor.ReturnValue = MyString.Substring(0,
MyString.IndexOf(".") - 1)

But when VB tried to execute the script, I get the runtime error
"Expecting end of statement". After some experimentation, it appears
that the "As String" datatype declaration is what is causing the error.
So how do I declare local string variables?
 
C

CT

So how do I declare local string variables?

You can't, VBScript is typeless. So, just remove "As String".
 
Z

zacks

Not only is it typeless, it is a subset of VB6, not VB.NET, so the
String Class and its methods are not implemented, so I had to reveret
back to the old InStr and Mid functions.
 
H

Herfried K. Wagner [MVP]

I am trying to write a VBScript that will be executed by a VB.NET 2005
program using Microsoft's Scripting Control. I have gotten a few simple
scripts to work but I am having problems on one. I need to parse a
character string value and pick out the pieces that are delimited by
periods. For example, the input value may be:

58000.44.51.

and I want to parse out the 58000 and return that value. I wrote the
following script:

Dim MyString As String
MyString = ScriptProcessor.Fields.Item(0)
ScriptProcessor.ReturnValue = MyString.Substring(0,
MyString.IndexOf(".") - 1)

Remove 'As String'. Use 'Mid' and 'InStr' instead of 'Substring' and
'IndexOf'.
 
C

Chris Dunaway

I am trying to write a VBScript that will be executed by a VB.NET 2005
program using Microsoft's Scripting Control. I have gotten a few simple
scripts to work but I am having problems on one. I need to parse a

Why not just write VB.Net code and use the classes in the
System.CodeDom namespace to execute the code? This way, you can use
the full VB.Net syntax and methods, etc.
 
K

KitWest

Here is another suggestion: use the Split function, giving it the
string to parse, along with the separator character. For instance:
MyArray = Split("Item0.Item1.Item2.Item3", ".")
MsgBox MyArray(2)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top