Jump to content
Macro Express Forums
cldcp00

External Script - Passing Parameters

Recommended Posts

Hi

 

I am toying with the idea of calling a VBScript to handle Copying and Writing to a text file as it appears to be more robust.

 

If I needed to pass the full path name and receive back conformation of Successful run, How this could be done?

 

Thanks for any advise

 

This is the basic code I am proposing to call

 

How would pass the replace the Copyfile hard coded values with variables 

 

File to be copied

C:\Desmond Music\Music Library 2018\000 Music Selected To Play WhatsApp Group\BB Seaton\05 - BB Seaton - Thin Line Between Love & Hate.mp3

Folder to copy to

C:\Desmond Music\New Music Library 2018\Jazz\

 

Option Explicit
Dim fso
Dim fso1
Dim filename   
 
vbsString = "%MacExpString%"

Set fso = CreateObject("Scripting.FileSystemObject")
Set fso1 = CreateObject("Scripting.FileSystemObject")
Set filename = fso1.OpenTextFile("C:\Users\desmo\Desktop\Audit Trail.txt", 8)
 
'To Copy a file
fso.CopyFile "C:\Desmond Music\Music Library 2018\000 Music Selected To Play WhatsApp Group\BB Seaton\05 - BB Seaton - Thin Line Between Love & Hate.mp3", "C:\Desmond Music\New Music Library 2018\Jazz\"

filename.WriteLine "C:\Desmond Music\New Music Library 2018\Jazz\"
filename.Close

 

Share this post


Link to post
Share on other sites

Well you pass parameters to a script easy and you can read the result back into a variable. Look at the External Script section in the help file. "Script Language Parameters", and "Save Console Output to." The help file is a very good resource for things like this. 

Share this post


Link to post
Share on other sites

Hi Cory,

 

Sorry to be a pain.

 

I am having a bit of trouble passing the value of two Variables in my my macro to the VBScript. It works fine when I hard code but not with the variables.

 

I have two variables in my macro that needs to be passed to the VBscript

 

%tFullFilename%

%tDestination%

 

I have read the information you suggested (below) but still do not fully understand. If I set  "%tDestination%" to %MacExpString% , how do I pass the second Variable %tFullFilename%

 

Variable Set String %MacExpString% to "%tDestination%"

 

And in the External Script must the Variable be called vbsString?

 

Have you got and example code?
 

 

 

To pass Macro Express Pro variables to your VB Script do this:

In your macro use the Variable Set String command

Variable Set String %MacExpString% to "Pass this to VBScript"


Then include this line in the External Script command:

vbsString = "%MacExpString%"

Share this post


Link to post
Share on other sites

cldcp00 maybe you could just explain how you got it to work.

 

I don't remember on VBS but in .NET application one passes the command line parameters to the program with each separated by spaces. If the item needs spaces, then enclose in quotes. Then when the program runs they're available in the app using My.Application.CommandLineArgs. This will be an array of string. Each can be accessed like My.Application.CommandLineArgs(0) and My.Application.CommandLineArgs(1). They're zero based. I'm VBS is similar. 

Share this post


Link to post
Share on other sites

Hi Cory,

 

I am away from that PC at the moment,  back home tomorrow evening.

 

I will try and explain tomorrow what I did to get it working, quite straight forward,  my issue was I had left off some needed quotes"      " around the variables. This has something to do with how MEP passes the value to the VBscript

 

 

 

Regards

Share this post


Link to post
Share on other sites

Hi Cory,

 

Below is the MEP Code which passes two values to the External VBScript

 

Variables

%FullFilename%

%Destination%

 

// PURPOSE OF MACRO
Copy the seleced file to another existing user-selectable folder.
 
 

Clipboard Empty
Text Type (Simulate Keystrokes): <F2> // Edit mode.
Delay: 0.2 seconds
// Select all. (Iincluding extension, which I found necessary in Win 10.) Or use @acantor's equally effective method.
Text Type (Simulate Keystrokes): <CONTROL>a
Delay: 0.2 seconds
Clipboard Copy
Delay: 0.2 seconds
Variable Set String %tFilename% from the clipboard contents
Text Type (Simulate Keystrokes): <ESC> // Close edit mode
Delay: 0.1 seconds
// Select address of current folder.
Text Type (Simulate Keystrokes): <ALT>d
Delay: 0.1 seconds
Clipboard Copy
Delay: 0.1 seconds
 
Variable Set String %tFolder% from the clipboard contents
Text Type (Simulate Keystrokes): <ESC> // Close edit mode
Delay: 0.1 seconds
// Now re-assemble the original full filename and path.
Variable Modify String %tFullFilename%: Append Text String Variable (%tFolder%)
Variable Modify String %tFullFilename%: Append Text (\)
Variable Modify String %tFullFilename%: Append Text String Variable (%tFilename%)
Variable Modify String: Save %tFullFilename% to the clipboard
Delay: 0.1 seconds
Variable Set String %tDestination% to "C:\Desmond Music\New Music Library 2018\Classical"
External Script: VBScript
Text Box Display: Results

The External VBscript is called (See code below)

 

image.thumb.png.a7448c509bd02701f80c7d4c8453f8b5.png

 

Things to note

The %Console% variable specified in the  save console output to Box is the means by which and output form the VBscript is passed back to the host MEP script.

So Wscript.Echo has passed "File Copied Successfully" to the the MEP script using Console.

 

Then the last thing I do is display %Console% using Text Box

image.png.2b8bdb1a4aa6a39136741388b5af5e8d.png 

 

Warning

The thing that caught me out was the quotes "%Destination%" around the passed  variables, I did not noticed that they were needed, and it just will not work without them. As i have already said this has something to do with the way MEP passings vales to the External Script.

 

I am a newbie so sorry if I have not used the correct terms but I hopes it helps 

 

Share this post


Link to post
Share on other sites

I would have used the Script Language Parameters field, but whatever works for you. 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...