Jump to content
Macro Express Forums

Variable value from External Script to MEP


Recommended Posts

Hi,

 

Is there any way to preserve the value of a variable from External Script file and place it in MEP variable %T[*]%.

 

I've gone through the post "How to return a value from external script to MEP" earlier posted in this forum. But failed to find any conclusion on it. Can some one post a simple method of capturing the variable value from ES to MEP.

 

FYI..I'm using VBscrpit in External Script.

 

Thanks in advance.

Gagan

Link to comment
Share on other sites

First off stop using the old T variables. Name your variables.

 

Second we have covered this before. I can't fathom why you're still stuck on this. In the external script command there is a field "Save console output to:" Where you specify the variable to errr... well... capture the console output. I can't think of how this could be more simple. See the attached macro. Run it and you should get "Gagan Test" in a message box. Does this make sense now? Also it would help if you provided a simple example of something you are having trouble with.

Gagan Test.mex

  • Like 1
Link to comment
Share on other sites

Thanks Cory...That was a magical one liner :)

 

If possible can you share some script to activate/focus on a particular window. I'm able to open a new windo and perform anything on it. But couldn't get code to activate a particular window. I tried using the Shell object and using AppActivate fuction but failed to get any results.

 

Thanks a ton :)

Link to comment
Share on other sites

I don't know how to do that, I'd have to research it. And I don't know what it is your trying to do. Again it would be helpful if we knew what the goal was.

 

Using MEP and VBS in this way is really a kludge and fraught with issues. You can automate IE with scripts and such but I watched guy in VBA forums try to do it and even there it was difficult. And you will not be able to interact with the VBS once it gets going. This is why I do all of these in VB.NET now.

 

There are two ways I automate. First is to not use a web browser at all. I use HTTPRequest/Response classes to request and retrieve raw HTML and process to extract data, make decisions. IOW have a conversation directly with the web server. Second is to use a WebBrowser control. In a sense one builds their own web browser in a WinForm app. But because it's your control you have, well, control. Though I only have to resort to this method rarely.

Link to comment
Share on other sites

Cory,

 

I've found the code to activate a particular window through VBA. But when i put the code under external script and run it doesn't works. I know there are certain functions/ methods which vba supports but vb script doesn't.

 

Through the below code you can activate a particular window. EX. In the below code it activate the window with urls as Google. It checks the string "Google" in the url and once it finds it maximize the window.

Declare Function apiShowWindow Lib "user32" Alias "ShowWindow" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Global Const SW_MAXIMIZE = 3
Global Const SW_SHOWMINIMIZED = 2
Global Const SW_SHOWNORMAL = 1

Sub getIE()
Dim IE_Tab As SHDocVw.InternetExplorer
Dim SH_Win As SHDocVw.ShellWindows
Dim T_Str As String
Set SH_Win = New SHDocVw.ShellWindows
For Each IE_Tab In SH_Win
    T_Str = IE_Tab.LocationURL
    If InStr(T_Str, "Google") > 0 Then
         IE_Tab.Visible = True
         apiShowWindow IE_Tab.hwnd, SW_MAXIMIZE
         IE_Tab.Refresh
    Else
         '   do something
    End If
Next
Set IE_Tab = Nothing
Set SH_Win = Nothing

End Sub


I'll appriciate if someonce can help me converting this script to work as VB script.

 

Regards,

 

Gagan

Link to comment
Share on other sites

I'm sorry but I don't have time to research and test this for you. And like I said I decided this was a poor path o take so I went a completely different route by writing a proper compiled WinForm application. If it were a paying gig it would be different but at the moment I need to spend my time on my clients. You might look around online for a converter. I've used a few to go between C# and VB with good success.

Link to comment
Share on other sites

I'm able to capture the value from an External script option and pass the value to another variable by using "Wscript.Echo %test%" command

 

How can i pass the value captured in %test% via ME to another app.

 

Here's a brief about the scnerio.

 

1) Input box to capture value from user (%test)%

2) Use External script (setup a connection to another app) and pass the value captured above to the connected app.

 

I've tried the above command(Wscript.Echo %test%) but not getting results. Any suggestions ??

Link to comment
Share on other sites

I don' t know exactly but there are a few ways to feed back data. You can write to the console, write to the registry, or write to a file. You then use the console option in External Script to get the value back or for the other two use the normal MEP commands to read in a file or registry entry.

 

What I'm not sure about on writing to the console is how it works in MEP using WScript versus CScript. When it comes to output the apparent difference is that CScript will output to the console, What you might call a Command Prompt" and WScript will use the MessageBox WinForm. IE a pop-up window. In the past dealing only with VBS this was an important distinction and one had to make sure to run their script with the correct interpreter. But I'm not sure how MEP does it. I seem to remember that MEP uses CScript so in that case a WScript.echo will result in essentially command line output and will be captured as console output.

 

I did a quick test and in the macro I gave you before I modified the script to use a variable. Here I create an integer variable intTest and echo it to the console. For small value this is how I would return a value.

intTest = 42
Wscript.Echo intTest
Link to comment
Share on other sites

I was just thinking you might be confused about the use of variable in the VBScript itself. They dont' exist in the script.

 

When you put an MEP variable in the External Script box MEP will convert that to the literal string value. So in your macro lets say you have an integer variable of %TestInput% and assigned it a value of 42 before running the external script it might look like this:

intTest = %TestInput%
Wscript.Echo intTest

But at run time MEP will create and execute this:

intTest = 42
Wscript.Echo intTest

Does that make sense? So you can't use MEP variables in the script per se other than to build the script.

Link to comment
Share on other sites

I don't see where reading a variable from an input box would be a problem.

strInput = InputBox("Type something")
Wscript.Echo strInput

I modified my macro I sent you as such and it works fine. Can you tell me why this doesn't work for you?

Link to comment
Share on other sites

From what you describe I would recommend a different way. If it were me I'd grab the raw HTML with an HTTPRequest and use RegEx to extract the data you want. About 3 lines of code to do that and I'd be willing to write the expression for you. If you decide to do this here's your expression:

docid=(\d{13})

I wonder if WebCleint works in VBS. But if you have an IE object you can do the same with the document text property. Or if it's a WebBrowser object that support the HTML DOM you can use that too.

Link to comment
Share on other sites

Cory already showed how to pass a variable from Macro Express Pro to a VBScript. Maybe this more detailed explanation will help you understand how it works.

 

VBScript does not know anything about Macro Express Pro. It has no way to directly read the content of a Macro Express variable. Macro Express has its way to store variables. VBS has another way to store variables.

 

To pass the content of a Macro Express Pro variable into a VBScript you have to use the VBS command to set a value to a variable. The format to create variables and set them to specific values in VBS looks something like this:

intTest=42
strTest="gagangoomer's macro"

To create variables in Macro Express Pro and set them to specific values do this:

Variable Set Integer %intTemp% to 42
Variable Set String %strTemp% to "gagangoomer's macro"

Then, in the External Script command, include these lines:

intTest=%intTemp%
strTest="%strTemp%"

When the macro runs the External Script command and passes the script information to VBScript the contents of the Macro Express variables ("42" and "gagangoomer's macro" respectively) will be substituted for the variable names ("%intTemp%" and "%strTemp%") so WScript (the program that runs the VBScript) will see it like this:

intTest=42
strTest="gagangoomer's macro"

This is the way to pass a variable into VBScript via the External Script command.

 

Another thing to consider would be to put the values you need into a resource that both Macro Express Pro and WScript / VBScript can access. If your VBScript can read from the registry you could have Macro Express Pro write values into the registry. Similiarly, Macro Express could write information into a file in a location where VBScript can read it. Paul suggested using the clipboard but you said that wouldn't work. I am not a VBScript expert but it would surprise me if a VBScript cannot read from the clipboard.

Link to comment
Share on other sites

  • 1 month later...

Here's another Question on the board :)

 

I've capture certain info by using object in IE and stored them in a External script (ES) variable.

Dim IE
Dim URLFound
Dim ObjORS
Dim fln

Call Look_For_URL
If URLFound = True Then
                IE.Visible = True
                fln = IE.document.getElementById("ETSMaster_MainContentPlaceHolder_ETSHeader_pnlHeaderInfo_hypWandFLN").innerHTML
                Caseid = IE.document.getElementById("ETSMaster_MainContentPlaceHolder_ETSHeader_pnlHeaderInfo_lblCaseID").innerHTML
                date = IE.document.getElementById("ETSMaster_MainContentPlaceHolder_ETSHeader_pnlHeaderInfo_lblCaseID").innerHTML
                Status = IE.document.getElementById("ETSMaster_MainContentPlaceHolder_ETSHeader_pnlHeaderInfo_lblCaseID").innerHTML
                Wscript.Echo fln
                Wscript.Echo Caseid
            
End If

Above script will return value in a variable %Result%. When i call %Result% it will show the values which i've called in script through Wscript.echo command. My question : Is there any way i can use the able values captured in another External script. I'm creating a new e-mail via ES option and want to pass the values retrieved from %Result%.

 

'Script from Body of the mail.

 

strMsg = "Case id : " %Result%

 

objMail.body = strMsg
objMail.display

Link to comment
Share on other sites

I've found the code to activate a particular window through VBA......

I'll appriciate if someonce can help me converting this script to work as VB script.

I'm sure you would! Converting a VB6 call to a dll into Vbscript is by no means a trivial operation. I'd be very surprised if you could persuade someone to do this for you gratis.

Link to comment
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...