cldcp00 Posted October 18, 2019 Report Share Posted October 18, 2019 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 Quote Link to comment Share on other sites More sharing options...
Cory Posted October 18, 2019 Report Share Posted October 18, 2019 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. Quote Link to comment Share on other sites More sharing options...
cldcp00 Posted October 18, 2019 Author Report Share Posted October 18, 2019 Thanks Cory Quote Link to comment Share on other sites More sharing options...
Cory Posted October 18, 2019 Report Share Posted October 18, 2019 You're welcome! Quote Link to comment Share on other sites More sharing options...
cldcp00 Posted October 21, 2019 Author Report Share Posted October 21, 2019 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%" Quote Link to comment Share on other sites More sharing options...
cldcp00 Posted October 22, 2019 Author Report Share Posted October 22, 2019 Hi Cory Managed to get it sorted. Found one of your old post and figured it out. Thanks for all your old posts, much appreciated Quote Link to comment Share on other sites More sharing options...
amonaghan Posted October 22, 2019 Report Share Posted October 22, 2019 Do you have a link to Cory's old post? Quote Link to comment Share on other sites More sharing options...
cldcp00 Posted October 22, 2019 Author Report Share Posted October 22, 2019 Sorry I cannot seem to find it again. I cannot remember the search term that i used. Quote Link to comment Share on other sites More sharing options...
terrypin Posted October 23, 2019 Report Share Posted October 23, 2019 23 hours ago, amonaghan said: Do you have a link to Cory's old post? Hi Alan, Possibly this?https://pgmacros.invisionzone.com/topic/7613-variable-value-from-external-script-to-mep/ Or these, containing advice on external scripts from others too:https://pgmacros.invisionzone.com/topic/248-how-to-multiple-field-input-form-example/https://pgmacros.invisionzone.com/topic/4916-how-to-return-value-from-external-script-to-mep/https://pgmacros.invisionzone.com/topic/3640-external-scripts-how-far-are-you-pushing-them/ Terry Quote Link to comment Share on other sites More sharing options...
amonaghan Posted October 23, 2019 Report Share Posted October 23, 2019 Thanks Terry, I'll try making time over the weekend to have another look at it. Quote Link to comment Share on other sites More sharing options...
Cory Posted October 23, 2019 Report Share Posted October 23, 2019 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. Quote Link to comment Share on other sites More sharing options...
cldcp00 Posted October 23, 2019 Author Report Share Posted October 23, 2019 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 Quote Link to comment Share on other sites More sharing options...
cldcp00 Posted October 24, 2019 Author Report Share Posted October 24, 2019 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) 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 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 Quote Link to comment Share on other sites More sharing options...
Cory Posted October 24, 2019 Report Share Posted October 24, 2019 I would have used the Script Language Parameters field, but whatever works for you. Quote Link to comment Share on other sites More sharing options...
cldcp00 Posted October 24, 2019 Author Report Share Posted October 24, 2019 Correct Cory Would have saved a lot of pain with the quotes Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.