Help with VBS, Please

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
User avatar
PepsiHog
Automation Wizard
Posts: 494
Joined: Wed Apr 08, 2009 4:19 pm
Location: Florida

Help with VBS, Please

Post by PepsiHog » Mon Dec 30, 2019 5:45 pm

Hello Everyone,

Trying to get this vbs I got online to work in MS. It is giving an error, expected end of line.

Will someone please show how to get this to work?

Code: Select all

VBSTART

Sub Split_Example1()

  Dim MyText As String
  Dim i As Integer
  Dim MyResult() As String

  MyText = "My Name is Excel VBA"
  MyResult = Split(MyText)

End Sub


VBEND


VBRun>Split_Example,This;is;a;test
VBEval>MyResult,n
mdl>%n_1%
I am trying to modify it so I am passing the string to it, but I can't get past the "end of statement expected" error to even get to figuring out the rest.

Thanks for helping,
PepsiHog
Windows 7

PepsiHog. Yep! I drink LOTS of Pepsi (still..in 2021) AND enjoy programming. (That's my little piece of heaven!)

The immensity of the scope of possibilities within Macro Scheduler pushes the user beyond just macros!

User avatar
Marcus Tettmar
Site Admin
Posts: 7331
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Re: Help with VBS, Please

Post by Marcus Tettmar » Mon Jan 06, 2020 8:48 pm

Ok,

1. This is not VBScript it is VB.
2. You are trying to call a function called Split_Example which does not exist. Your VBScript code has a function called Split_Example1. Note the 1 at the end.
3. Not sure why you have that semicolon delimited list of text after the call as your subroutine does not take any parameters. Plus the Split function's default is to use the space character and you haven't overridden that. The value you are passing Split is already defined inside the function.
4. Your VBEval statement is trying to evaluate a variable which is defined inside a subroutine. You can't do that. You can only evaluate global scope variables.
5. You cannot pass a VBScript array variable into a MacroScript array variable, but you CAN evaluate an array _element_.

So, this is what I THINK you wanted:

Code: Select all

VBSTART

'global variable we can access later ... 
Dim MyResult

Sub Split_Example1()

  Dim MyText

  MyText = "My Name is Excel VBA"
  MyResult = Split(MyText)

End Sub
VBEND

VBRun>Split_Example1

//access the second word (index 1)
VBEval>MyResult(1),val
mdl>val
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

User avatar
PepsiHog
Automation Wizard
Posts: 494
Joined: Wed Apr 08, 2009 4:19 pm
Location: Florida

Re: Help with VBS, Please

Post by PepsiHog » Fri Jan 10, 2020 6:40 pm

@Marcus,
Yep. I have as much knowledge about VB as you have about the loch ness monster. There is no way of passing mytext instead? Forgive me. Macro Sch uses VBS. And you gave me what I wanted, in vbs. I believe you were saying my errors based on it being VB. So my question is can it be passed in your vbs? Is changing the delimitter the same as it was in vb (mytext,";")?

As far as the nonsense in my attempt at using it, just seeing if I could figure it or something out before posting. But, no such luck. :shock:

Thanks for the script,
PepsiHog
Windows 7

PepsiHog. Yep! I drink LOTS of Pepsi (still..in 2021) AND enjoy programming. (That's my little piece of heaven!)

The immensity of the scope of possibilities within Macro Scheduler pushes the user beyond just macros!

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts