Embedded Windows Scripting (VBScript & JScript) and COM
I wish I could offer help with ADO, but I've never used it before. I know a simple google search brings up many examples.
This weekend I think I'll pull myself away from my other projects and update ws4ahk to a stdlib-ready version.
your library is "WS",
*everything* GLOBAL in that library should be "WS_"
so.. "__IUnknown_Release(ppv)" won't conflict with another "__IUnknown_Release()" function in someone's script, keep it within your library... ie. "WS__IUnknown_Release(ppv)"
there will NEVER BE A CONFLICT WITH ANY OTHER LIBRARY/FUNCTION..
include your webpage address in the function notes...
hope is helpful.
WS_Initialize() pWord := WS_GetObject("Word.Application") clipboard := ErrorLevel . ";" . pWord WS_UnInitialize()and it works perfecly. But I think you know is it possible, in VBScript, to specify a file name to know if the file is loaded in Word (in this case). The syntax of GetObject is : GetObject([pathname] [, class])
So, if pWord := WS_GetObject("Word.Application") works great,
pWord := WS_GetObject("Z:\Try.doc") should work,
and pWord := WS_GetObject("Z:\Try.doc,Word.Application") too, but no one of the two last forms works.
The error code in ErrorLevel is "-2147221005 (800401F3) incorrect class string"
Please where is the problem ? Is it a problem with the Microsoft Scripting Control ?
Is there a solution ? If it is, which one please ?
Thanks by advance
WS_GetObject(sProgIDorClassID [, sInterfaceID = IDispatch ] ) ; the sInterfaceID parameter can usually be ignoredVB syntax:
GetObject([pathname] [, class])
The work around would be to use VBScript to get the object.
WS_Eval(pWord, "GetObject(""Try.doc"")") ; could also be written other ways: ; * put the code in a variable before evaluating it (no need to escape quotes) sCreateObjCode = ( GetObject("Try.doc") ) WS_Eval(pWord, sCreateObjCode) ; * use the printf style (if you're comfortable with it) ; woops! a ws4ahk bug prevents this from working. ; Edit: this is now fixed in v0.12! WS_Eval(pWord, "GetObject(%s)", "Try.doc") ; * using the VBStr function (not helpful in this case) WS_Eval(pWord, "GetObject(" . VBStr("Try.doc") . ")")
I spent about an hour searching for what VB's GetObject() function does internally, but couldn't find anything except this little snippit
[quote name="http://www.cgoakley.demon.co.uk/prog/oleaut.html"]GetObject will not be explored here. Suffice it to say that it uses non-automation OLE interfaces to read an object from a file, or other persistent storage.[/quote]
It also seems that Python's COM libraries don't provide the VB style GetObject function either. Could this functionality be so complicated that even Python doesn't mess with it?
So I have no idea how VB's can get an object from a file. If anyone knows, maybe this feature can be added to ws4ahk.
The first one, of course, Ws4Ahk.
The second one, your work on my question. Your aswer is very instructive.
I made, too, some trys.
After a certain number of trys, the syntax
GetObject([pathname] [, class])is effectively not supported by Ws4Ahk, but this one
GetObject([pathname])yes (I made many trys...).
My results :
With the syntax :
myDoc := "D:\Try.doc" ppWord := WS_Eval(pWord, "GetObject(%s)", myDoc) or ppWord := WS_Eval(pWord, "GetObject(%s)", VBStr(myDoc))I had no success.
With the syntax :
myDoc := "D:\Try.doc" ppWord := WS_Eval(pWord, "GetObject(" . VBStr(myDoc) . ")"), if Word is launched and it has the file loaded in it, success...
But, surprise, if Word is launched but empty or when Word is not launched at all, the result is ... success !!! If Word is empty, the file isn't loaded in it...
So GetObject seems to try to launch the file in Word but seems to not do it... Strange...
If I try with a doc file with macros in it, I have the window to choose to activate them or not. When I go to Word to see if the file is loaded, I don't see anything... Is it loaded in invisibly mode ? I don't know... I can make any choice (activate the macros or not, cancel), the file is not displayed in Word if it is launched... But the same window (choice to activate macros or not) appears even if there isn't any Word instance launched...
With the syntax
myDoc := "D:\Try.doc" sCreateObjCode = ( GetObject("%myDoc%") ) ppWord := WS_Eval(pWord, sCreateObjCode)the results are the same.
So for me the solution is probably to verify with AHK commands if there is a Word window which exists with the file name I want to use, and after to use one of these syntaxes to act on the file if it is already loaded in Word.
Thanks again, erictheturtle, for your beautifull work and your nice help.
The first syntax is the correct one. Did you try this with the new v0.12? It should work the same as your other examples now.
With the syntax :myDoc := "D:\Try.doc" ppWord := WS_Eval(pWord, "GetObject(%s)", myDoc) [color=green]; correct[/color] or ppWord := WS_Eval(pWord, "GetObject(%s)", VBStr(myDoc)) [color=red]; xx incorrect[/color]I had no success.
I didn't specifically mention it in my previous post, but all 3 of those bits of Autohotkey code will execute the exact same VBScript code. I just provided the 3 different AHK syntaxes to give you (and others) options. Use whichever one you are most comfortable with.
With the syntax :myDoc := "D:\Try.doc" ppWord := WS_Eval(pWord, "GetObject(" . VBStr(myDoc) . ")")...
With the syntaxmyDoc := "D:\Try.doc" sCreateObjCode = ( GetObject("%myDoc%") ) ppWord := WS_Eval(pWord, sCreateObjCode)the results are the same.
While all of your examples will work, I see you use "ppWord := WS_Eval(...)". The syntax of WS_Eval is
blnSuccess := WS_Eval(ByRef ReturnValue, sScriptCode [, values for %v or %s])so after the call, ppWord will hold True or False. Is this what you were intending?
I see it now. I will try.
Did you try this with the new v0.12? It should work the same as your other examples now.
I understood. Thanks for giving us the choice. IMO, I prefer the second syntax...
I just provided the 3 different AHK syntaxes to give you (and others) options. Use whichever one you are most comfortable with.
Yes absolutely, for try purpose. I put pWord, ppWord and ErrorLevel in the clipboard to test them and see what are the return values.
so after the call, ppWord will hold True or False. Is this what you were intending?
Concerning the strange behavior I spoke about (when you test if the file is loaded in Word and there isn't any active Word instance or an instance without the file loaded in it, it seems that there are trys to load the file and the result of the function is positive), it seems that it's a VBScript itself behavior.
Im absolutely enthralled
one very important question
#Include ws4ahk.ahk WS_Initialize() Code = ( Dim foo1 foo1 = "bar" ) WS_Exec(Code)this will of course create a visual basic variable called foo1
i would like to retreive the value "bar" and use it in ahk script
conceptually to set a edit feild with the value arrived at from vb
unfortuanately this is part of something larger im working and vb is the only language i can interact with another application with
(local pc policy) if that even sounds reasonable
#Include ws4ahk.ahk WS_Initialize() Code = ( Dim foo1 foo1 = "bar" ) WS_Exec(Code) WS_Eval(getval, "foo1") Msgbox % getval ; displays a message box with 'bar'Hope this provides what you are looking for.
Note: I'm out of town for winter vacation starting tomorrow, so I can't say when I may be able to post additional replies. If I'm not back before new years, happy holidays everyone!
You did accurately interpret my question
I have VB code almost 2000 lines for interacting with a very archaic system and only respond well to VB
Some of the functions scrape data off a terminal application and store those values in a variable.
Without this answer i was going to have to abandon my current project all together, as some of these values were for error checking within the app. Others were to post results to a GUI form I’m creating with AHK
The app in question will be used in a call center of a bank.
WIN or LEARN.
ws4ahk has been updated v0.13, which adds some missing error handling, and a few comments improvements/corrections.
Don't forget, ws4ahk is still considered beta software. While I try my best to ensure quality, it can't be guaranteed to be wholly reliable.
WIN or LEARN.
- WS_Exec()/WS_Eval(): Better handling of errors.
Removed printf() style functionality, moved to codef() function.
Removed leftover Clipboard debug.
- codef(): New function to handle printf() style formatting of code.
Also fixes the bug if in hex mode.
Note that if you are using the printf style in WS_Exec or WS_Eval (I doubt anyone is), you will need to slightly modify your code to use the new codef() function.