Book a Demo

Author Topic: Re-using script fragments  (Read 4615 times)

Jayson

  • EA User
  • **
  • Posts: 363
  • Karma: +1/-0
    • View Profile
Re-using script fragments
« on: September 01, 2014, 11:38:18 am »
Hi all

I've got some script fragments in VB script that I want to reuse in several larger scripts.

I've looked at how the included scripts do it and they seem to use the INC statement.

So, I have created two script files.

File #1
=====

This includes a main sub plus:

In the header
---------------
!INC Jayson.TestScript


Plus in the main sub
----------------------

TestScript.SayHello


File #2 is called TestScript and is in the Jayson folder.
==================================

It has a simple sub as follows:

sub SayHello
    MsgBox("Say Hello")
end sub

What I expect to happen is execute file #1 and have a message box saying "Say Hello" appear.

What I DO get is an error message in the second file stating:

Jayson.TestScript error: Expected statement, Line 1

So, it would appear that the script engine is trying to execute the SayHello subroutine, but is failing.

Any ideas as to what I am doing wrong?

Cheers

Jays  :)

Uffe

  • EA Practitioner
  • ***
  • Posts: 1859
  • Karma: +133/-14
  • Flutes: 1; Clarinets: 1; Saxes: 5 and counting
    • View Profile
Re: Re-using script fragments
« Reply #1 on: September 02, 2014, 08:11:26 pm »
We meet again! :)

Is that the whole of Jayson.TestScript? Because you get that error if the included script starts with option explicit. In other words, you need to decide beforehand whether a script file is for execution or inclusion, and place option lines only in the former (check out Local Scripts.EAConstants-VBScript; no option lines there).

This is because the !INC statement has the same(ish) semantics as a CPP #include, rather than a Java import: a textual inclusion, not a namespace reference.

For the same reason, it looks as if there's an error in the "main" script as well. Just as you don't specify a namespace for the MsgBox() reference, you shouldn't specify one for SayHello().

HTH,


/Uffe
« Last Edit: September 02, 2014, 08:13:01 pm by Uffe »
My theories are always correct, just apply them to the right reality.

Jayson

  • EA User
  • **
  • Posts: 363
  • Karma: +1/-0
    • View Profile
Re: Re-using script fragments
« Reply #2 on: September 03, 2014, 05:37:16 am »
Thanks for that Uffe!

I'm about to wander off for a long weekend away, so I will give this a shot next week.

Jays :)