Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Embedded Windows Scripting (VBScript & JScript) and COM


  • Please log in to reply
68 replies to this topic
YMP
  • Members
  • 424 posts
  • Last active: Apr 05 2012 01:18 AM
  • Joined: 23 Dec 2006
I'm not sure about the source of this little bug, but thought it would be worth mentioning. The timeout parameter in the Popup method doesn't work properly. The dialog will apparently stay forever.
Code=
(
  sh=new ActiveXObject("WScript.Shell");
  sh.Popup('Hello, world!', 2);
)

WS_Initialize("JScript")
WS_Exec(Code)
WS_Uninitialize()
I found only a few exceptions: 1, 1.1, 1.2, 1.3, 1.4 . With these values, the dialog closes.

user
  • Members
  • 476 posts
  • Last active: Dec 23 2011 07:18 PM
  • Joined: 05 Oct 2006
it looks very nice

erictheturtle
  • Members
  • 101 posts
  • Last active: Sep 04 2011 02:07 PM
  • Joined: 27 Jun 2007

I'm not sure about the source of this little bug, but thought it would be worth mentioning. The timeout parameter in the Popup method doesn't work properly. The dialog will apparently stay forever.

Code=
(
  sh=new ActiveXObject("WScript.Shell");
  sh.Popup('Hello, world!', 2);
)

WS_Initialize("JScript")
WS_Exec(Code)
WS_Uninitialize()
I found only a few exceptions: 1, 1.1, 1.2, 1.3, 1.4 . With these values, the dialog closes.

Wow YMP, thanks for reporting this. What a very odd bug. Here are some of the things I've tried:[*:r3w09be2]The bug seems to occur when the timeout value is >=1.5 seconds (the timeout works correctly at 1.49999).
[*:r3w09be2]Using WS_Initialize("VBScript") and changing the code to VBScript still produces the bug.
[*:r3w09be2] Putting that JScript or VBScript code directly into a .js or .vbs file directly does not produce the bug.
[*:r3w09be2] Putting that VBScript code in Excel VBA does not produce the bug.
[*:r3w09be2] Using Microsoft Scripting Control in a .vbs script to run this code does not produce this bug.
[*:r3w09be2] Using the Microsoft Scripting Control in Excel VBA to run the code does produce this bug.Since I can produce the bug in Microsoft Excel's VBA, it is likely ws4ahk is not to blame. I tried searching for this, and any other bugs associated with the Microsoft Scripting Control. Unfortunately it doesn't appear to be a known problem.

So congratulations on finding a bug no one has ever seen before :) ...it's too bad we'll probably never see a fix for it in our lifetimes.

Of course if you need a message box with a timeout, the simple work-around is to use our actively maintained and open source Autohotkey's Msgbox function instead. I hope that will meet your needs well enough.

Thanks again for reporting this. Sorry that there doesn't seem to be any fix for it.
-m35

erictheturtle
  • Members
  • 101 posts
  • Last active: Sep 04 2011 02:07 PM
  • Joined: 27 Jun 2007

@ erictheturtle
I thought about to (slightly) improve the GUI of WS_DEDemo2.ahk.
Well, desperately waiting for your sign off :)

Gui, +Resize +LastFound +theme
Gui, Add, Button, x0 		 y2 		w110 	h22 gSetBold, Bold
Gui, Add, Button, xp+111 	yp 		wp	 	hp gSetItalic,italic
Gui, Add, Button, xp+111 	yp 		wp 		hp gSetUnderLine, underline
gui, Add, Button, xp+111 	yp 		wp 		hp gSetBlue, Blue
Gui, Add, Button, xp+111 	yp 		wp 		hp gSetImageLink, Image
Gui, Add, Button, xp+111 	yp 		wp 		hp gSetHyperLink, Link
Gui, Add, Button, xp+111 	yp 		wp 		hp gLoadUrl, LoadURL
Gui, Add, Button, x0 		 yp+23 	wp 		hp gGetDocument, GetHtml
gui, add, button, xp+111 	yp 		wp 		hp gSetDocument, SetHtml
Gui, Add, button, xp+111 	yp 		wp 		hp gSaveDocument, SaveHtml
Gui, Add, button, xp+111 	yp 		wp 		hp gBrowseMode, BrowseMode Toggle
Gui, add, button, xp+111 	yp 		wp 		hp gNewDocument, New
Gui, add, button, xp+111 	yp 		wp 		hp gFindText, FindText
Gui, add, button, xp+111 	yp 		wp 		hp gSetBackColor, SetBackColor
Gui, add, button, x0 		 yp+23 	wp 		hp gSetFontName, SetFontName
Gui, add, button, xp+111 	yp 		wp 		hp gSetFontSize, SetFontSize
Gui, add, button, xp+111 	yp 		wp 		hp gSetFont, SetFont
Gui, add, button, xp+111 	yp 		wp 		hp gList1, List1
Gui, add, button, xp+111 	yp 		wp 		hp gList2, List2
gui, Add, Button, xp+111 	yp 		wp 		hp gInsertTable, InsertTable
	ShowW = 776
	ShowH = 600
Gui, Show, % "w" ShowW " h" ShowH Center, DhtmlEdit_Test
hWnd := WinExist()

; Create the COM control
  ppvDEdit := DE_Add(hWnd, 0, 72, ShowW-1, ShowH-72)

   .
   .
   .

GuiSize:
	DE_Move(ppvDEdit, 0, 72, A_GuiWidth, A_GuiHeight-72)
Return

Thanks for the improvement BoBo¨. I know the buttons were running off the window. Style wise, I admit I liked how ABCyourway was arranging them. I've adjusted the buttons a bit so they all fit on the form now (but of course the design of the window isn't really the focus of the demo).

I'm somewhat ashamed, because I just realized it was a little rude of me to use ABCyourway's code as a ws4ahk demo without actually asking. ABCyourway, if you happen to read this post, I just wanted to get your OK to use your DEdit script as a ws4ahk demo. Please PM me, or post a reply when you get a chance.
-m35

YMP
  • Members
  • 424 posts
  • Last active: Apr 05 2012 01:18 AM
  • Joined: 23 Dec 2006

So congratulations on finding a bug no one has ever seen before

Oh, great indeed! It's an honour to me. :D

Of course if you need a message box with a timeout, the simple work-around is to use our actively maintained and open source Autohotkey's Msgbox function instead. I hope that will meet your needs well enough.

No doubt. AHK forever! :) Besides, with 1, the Popup dialog actually stays about 2 seconds. Enough time to read a short message, I believe.

Thanks for the detailed reply (and for ws4ahk, of course!!).

Chris
  • Administrators
  • 10727 posts
  • Last active:
  • Joined: 02 Mar 2004
Eric,

I finally added a link to Windows Scripting for AutoHotkey to the DllCall page. Hopefully this will bring more attention to the great work you've done.

Andi
  • Members
  • 195 posts
  • Last active: Apr 18 2014 05:03 PM
  • Joined: 11 Feb 2005
I'm trying to read and write to an excel file without opening it in excel. I'm shure that this would be possible, but unfortunately I'm not very handy in using vba. :?

I found here a description how to do this with ado http://support.micro...b/257819/EN-US/

Is there someone who has a working example for me, how to realize this with ws4ahk.ahk? :)

erictheturtle
  • Members
  • 101 posts
  • Last active: Sep 04 2011 02:07 PM
  • Joined: 27 Jun 2007
Hmm, I can't say I know much about using ADO. You might find more help with ADO on a VB specific board. Once you are able to get some working VB code, then I would be happy to help you modify it for ws4ahk.
-m35

Joy2DWorld
  • Members
  • 562 posts
  • Last active: Jun 30 2014 07:48 PM
  • Joined: 04 Dec 2006
indeed, Andi, please report back once you've figured it out! ADO looks really cool. as for ws4ahk .. it lets you run VB scripts from AHK.. but unfortunately... it doesn't yet code up the VB scripts for you... :roll:
Joyce Jamce

  • Guests
  • Last active:
  • Joined: --
ADO COM :roll:

Zoulou
  • Guests
  • Last active:
  • Joined: --
Hi, erictheturtle
Can you explain me how to call correctly the XL_OpenDile function correctly.
I can't succeed, I don't know why.
WS_Initialize()

XL_VBCode =
(
	Const adOpenStatic = 3
	Const adLockOptimistic = 3
	Const adCmdText = &H0001

	Dim objConnection, objRecordSet, XL_ADO_SheetRange, XL_ADO_SQLStat, XL_ADO_StatHDR, XL_ADO_TargetFile, i

	Sub XL_OpenConnexion
	Set objConnection = CreateObject("ADODB.Connection")
	Set objRecordSet = CreateObject("ADODB.Recordset")
	End Sub

	Sub XL_OpenFile(XL_ADO_TargetFile, XL_ADO_StatHDR)
'	objConnection.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & XL_ADO_TargetFile & ";Extended Properties=""Excel 8.0;HDR=" . XL_ADO_StatHDR . ";"";"
	End Sub
	
)
WS_Exec(XL_VBCode)

WS_Exec("XL_OpenConnexion")

XL_ADO_File := "Try.xls"
XL_ADO_TargetFile := A_ScriptDir . "\" . XL_ADO_File
XL_ADO_StatHDR := "YES"

WS_Exec("XL_OpenFile " . VBStr(XL_ADO_TargetFile) . "," . VBStr(XL_ADO_StatHDR))
msgbox %ErrorLevel%
Thanks by advance

erictheturtle
  • Members
  • 101 posts
  • Last active: Sep 04 2011 02:07 PM
  • Joined: 27 Jun 2007
Sub XL_OpenFile(XL_ADO_TargetFile, XL_ADO_StatHDR)
  objConnection.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & XL_ADO_TargetFile & ";Extended Properties=""Excel 8.0;HDR=" [color=red]&[/color] XL_ADO_StatHDR [color=red]&[/color] ";"";"
End
Your code looks very good. The only problem I see is the use of periods in the VB code for concatenating. If you change these periods to ampersands, does that get it working?
-m35

Zoulou
  • Guests
  • Last active:
  • Joined: --
Thanks erictheturtle,

It seems to work. It was an error of inattention.
If the prog work, I'll publish it, of course...

AHKnow
  • Members
  • 121 posts
  • Last active: May 17 2009 09:11 PM
  • Joined: 03 Jul 2004
Ahhhhh.... This is awesome!

My head hurts trying to understand how you got to this point and that includes Sean's raw COM. However, the functionality of this is what I always wanted to see in AutoHotkey.

I think raw com (thanks Sean) or this method to embed jscript and vbscript are the best ways.

I've always voted for embedding jscript or vbscript into AutoHotkey for dealing with COM, versus AutoHotkey making up its on syntax. This is because there is a HUGE amount of information and scripts already for jscript and vbscript. Why re-invent the wheel? Why do over something that has already been done, just to have your "flavor" of it.

I like sean's raw com too, because you can or at least try to see how COM works. Its a good study in addition as a way to shorten COM related code. However, it can make your head hurt. So the embedded method is their to help you relax.

AutoHotkey, to me, is about doing things the easy way or quickly. When an AutoHotkey user, that is not an experienced or professional programmer, comes across problems in which COM is the solution than he can now (thanks to this script) see what's out there in vbscript and jscript. Often finding a solution that has already been thought of. He can integrate that into his AutoHotkey script and keep moving.

If he wants to know more about COM than there is just this huge load of information and examples in vbscript and jscript to teach him. It allows you to take all the expertise, debating on the best way, and history of vbscript and jscript and make use of it.

Even looking at the AutoIt implementation of COM, they often do a lot of converting or copying from vbscript to AutoIt's version of it. You are then jumping back and forth between different flavors of doing COM. How do I re-create this vbscript the AutoIt way?

The only way I could see having AutoHotkey syntax for doing COM being an advantage is that it was easier to use or understand. Another argument on how to do it would be to create a syntax so close to vbscript, that you would be hard pressed to know the difference.

The other advantage of embedding, is you can look to this method to include other script and programming languages to work in a more integrated manner with AutoHotkey. When you can't do something in AutoHotkey, than you can reach out and grab something "off the shelf" so to speak to do what you want done. I also think that was part of Microsoft's point, to use their scripting language with your programming language, when they created the Windows Scripting Control.

Related COM topics-

<!-- m -->https://ahknet.autoh...y.com/~easycom/<!-- m -->

<!-- m -->http://www.autohotke... ... sc&start=0<!-- m --> ( Easycom.dll )

<!-- m -->http://www.autohotke... ... sc&start=0<!-- m --> ( COM standard library )

<!-- m -->http://www.autohotke... ... 65&start=0<!-- m --> ( ADO COM )

<!-- m -->http://www.autohotke... ... 31&start=0<!-- m --> ( COM Helper )

<!-- m -->http://www.microsoft... ... laylang=en<!-- m -->

<!-- m -->http://www.codeguru.... ... e.php/c15/<!-- m -->

<!-- m -->http://en.wikipedia....ows_Script_Host<!-- m -->

<!-- m -->http://en.wikipedia....eX_Data_Objects<!-- m -->

AHKnow
  • Members
  • 121 posts
  • Last active: May 17 2009 09:11 PM
  • Joined: 03 Jul 2004

ADO COM :roll:


Would like to see examples of ws4ahk.ahk working with Microsoft Access databases. Definitely have to play with that.