AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

COM Standard Library
Goto page Previous  1, 2, 3 ... 41, 42, 43, 44  Next
 
Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
Sean



Joined: 12 Feb 2007
Posts: 2462

PostPosted: Sat Jul 24, 2010 5:20 pm    Post subject: Reply with quote

Show your code. I'd like to see how you separated it first before I comment. BTW, I bet your errors were not consistent, I mean you did not always get the errors at the same item(s) when you run the code as the needed time for a procedure to complete is dependent on the current status of the system. So, you didn't get an error just once means little in this case.
Back to top
View user's profile Send private message
fragman



Joined: 13 Oct 2009
Posts: 1199

PostPosted: Sat Jul 24, 2010 9:37 pm    Post subject: Reply with quote

The errors appeared to happen randomly, this is mainly why I tried the sleep command.

Code:
items := Array()
itemnames := Array()
Loop % doc.Folder.Items.Count
{
   items.append(doc.Folder.Items.Item(A_Index - 1))
   itemnames.append(items[A_Index].Name)
   Sleep 10
}
Loop % Select.len()
{
   filter := Select[A_Index]
   If filter <>
   {
      If(InStr(filter, "*"))
      {
         filter := "\Q" StringReplace(filter, "*", "\E.*\Q", 1) "\E"
         filter := strTrim(filter,"\Q\E")
         Loop % items.len()
         {
            if(RegexMatch(itemnames[A_Index],"i)" filter))
            {
               COM_Invoke(doc,"SelectItem",items[A_Index],index=1 ? value1 : value) ;http://msdn.microsoft.com/en-us/library/bb774047(VS.85).aspx               
               index++
               ;Sleep 10
            }
         }
      }
      else
         COM_Invoke(doc,"SelectItem",doc.Folder.ParseName(filter),(A_Index=1 ? value1 : value)) ;http://msdn.microsoft.com/en-us/library/bb774047(VS.85).aspx               
   }
}


I also just tried this kind of loop so that Count is only requested once:
Code:
count := doc.Folder.Items.Count
Loop % count


It does not seem to do much to the frequency of errors, with both methods I get 0-2 errors on a folder with 44 elements, of which 42 should get selected.
Back to top
View user's profile Send private message
Sean



Joined: 12 Feb 2007
Posts: 2462

PostPosted: Sun Jul 25, 2010 6:25 am    Post subject: Reply with quote

So, back to the my first reply. I already suggested two other solutions than using sleep which may be the simplest but inaccurate. My preferred solution is using the event SelectionChanged, but it's really up to you which one to choose. BTW another simple solution may be turning off the error notification and when retrieving a name is failed, just retry it until succeeded. The result/name will be an empty string when failed. Or you can obtain the hResult(s) of the current invoke by using the global variable COM_HR/COM_LR or by calling COM_Error().
Back to top
View user's profile Send private message
fragman



Joined: 13 Oct 2009
Posts: 1199

PostPosted: Sun Jul 25, 2010 7:40 am    Post subject: Reply with quote

I guess I'll have to use one of those. The drawback of the SelectionChanged event would be having to split the function in two parts, but that's more of cosmetic nature. Thanks for your input!
Back to top
View user's profile Send private message
HotKeyIt



Joined: 18 Jun 2008
Posts: 4653
Location: AHK Forum

PostPosted: Tue Aug 10, 2010 7:25 pm    Post subject: Reply with quote

Hi Sean, I have an error in AutoHotkey_L53 but same code works using COM.ahk
Any Idea what is wrong Sad
Code:
COM_Init() ; Initialize COM.
d := COM_CreateObject("Scripting.Dictionary") ; Create dictionary.
d.Item("a", "Athens")
MsgBox % d.Item("a")
COM_Release(d) ; Done using dictionary d.
      
d := COMObjCreate("Scripting.Dictionary") ; Create dictionary.
d.Item("a", "Athens") ;Error:  0x8002000E - Invalid number of parameters.
d.Item("a") := "Athens" ;works fine
MsgBox % d.Item("a")

_________________
AHK_H (2alpha) AHF TT _Struct WatchDir Yaml _Input ObjTree RapidHotkey DynaRun Wink
Back to top
View user's profile Send private message
jethrow



Joined: 24 May 2009
Posts: 1907
Location: Iowa, USA

PostPosted: Tue Aug 10, 2010 7:30 pm    Post subject: Reply with quote

You already pointed out the issue - the item property is only supposed to have one param. The way the COM Library was designed, the second param was the value to be assigned. With built-in COM support, this is no longer valid syntax. See Item Property.
_________________
Very Happy - in case I forgot to smile
Basic Webpage Controls
COM Object Reference
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger
HotKeyIt



Joined: 18 Jun 2008
Posts: 4653
Location: AHK Forum

PostPosted: Tue Aug 10, 2010 7:57 pm    Post subject: Reply with quote

I see, thanks jethrow Rolling Eyes
_________________
AHK_H (2alpha) AHF TT _Struct WatchDir Yaml _Input ObjTree RapidHotkey DynaRun Wink
Back to top
View user's profile Send private message
jethrow



Joined: 24 May 2009
Posts: 1907
Location: Iowa, USA

PostPosted: Wed Aug 11, 2010 5:00 am    Post subject: Reply with quote

I'm not sure if you want these messages in this thread or not, but I noticed a difference in performance between the COM Library to Built-In COM. The following works as expected with COM_CreateObject, but errors out with ComObjCreate:
Code:
x:=ComObjCreate("ScriptControl"), x.Language:="jScript", a:=x.Eval("a=[1,2]")

loop, % a.length {
   MsgBox, % a[A_Index-1] ; <-- Error:  0x80020006 - Unknown name.
   ; MsgBox, % a[n:=A_Index-1] ; works fine for both
   ; MsgBox, % a["" A_Index-1] ; works fine for both
}

EDIT - the exact error message is: Error: 0x80020006 - Unknown name. (error in the MsgBox line)
EDIT2 - This has now been fixed.
_________________
Very Happy - in case I forgot to smile
Basic Webpage Controls
COM Object Reference


Last edited by jethrow on Wed Aug 11, 2010 10:45 pm; edited 3 times in total
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger
Sean



Joined: 12 Feb 2007
Posts: 2462

PostPosted: Wed Aug 11, 2010 5:28 pm    Post subject: Reply with quote

What was the exact error message? Anyway, the function name of a COM Object should be a string basically. And I suppose that the error was produced in your example since A_Index-1 was resolved to a name of an empty string. BTW, compare it with the following which will work as you expect:
Code:
MsgBox, % a[0] . "|" . a["0"]
MsgBox, % a[1] . "|" . a["1"]

Although making it work as you want is relatively straightforward (:which I don't like to add personally), I think you better post it in AHK_L thread.
Back to top
View user's profile Send private message
ribbs2521



Joined: 28 Sep 2007
Posts: 273
Location: New York

PostPosted: Wed Aug 11, 2010 5:59 pm    Post subject: Reply with quote

I hate to keep being a bother about this but can someone help me out. I had a compiler working fine and now it doesn't.

I found that Compile_AHK II does not work with AutoHotKey_La.exe but the standard issue .ahk to .exe did. Now when using either I get issues.

When using Compile_AHK II I get:
Code:
Could not extract script from .EXE

When using .ahk to .exe I get:
Code:
Error at line 66.

The following variable name contains an illegal character:
".Name"

The program will exit.

It's at a line with rs.Fields(0).Name when trying to get the field name from an ADODB recordset.

I'm at a loss because it works without compiling.
Back to top
View user's profile Send private message
HotKeyIt



Joined: 18 Jun 2008
Posts: 4653
Location: AHK Forum

PostPosted: Wed Aug 11, 2010 7:48 pm    Post subject: Reply with quote

You need to use correct AutoHotkeySC.bin Exclamation
_________________
AHK_H (2alpha) AHF TT _Struct WatchDir Yaml _Input ObjTree RapidHotkey DynaRun Wink
Back to top
View user's profile Send private message
ribbs2521



Joined: 28 Sep 2007
Posts: 273
Location: New York

PostPosted: Thu Aug 12, 2010 11:53 am    Post subject: Reply with quote

I don't know how that got screwed up but I know for next time, thanks. Sorry for the dumb mistake.
Back to top
View user's profile Send private message
Guest






PostPosted: Thu Aug 12, 2010 9:03 pm    Post subject: Reply with quote

Just a thought, but now that AHKL has built-in COM Support, should all the COM_Enwrap calls in the COM_L Library be changed to ComObjEnwrap. I noticed this when trying to determine the ComObjType from an object created with COM_AtlAxCreateControl.
Back to top
lexios
Guest





PostPosted: Fri Aug 13, 2010 5:03 am    Post subject: Reply with quote

Many of the functions which use COM_Enwrap are also obsolete. I think that the following can probably be removed (but it wouldn't hurt to confirm): Init, Term, GetObject, GetActiveObject, AddRef, Release, Enumerate, Error, Invoke, Invoke_, Parameter, Dis/ConnectObject and dependencies (FindConnectionPoint, GetConnectionInterface, Advise, Unadvise, DispInterface, CreateIDispatch, GetDefaultEvents). That's a significant portion of the library. It's possible that some of these might be useful with non-dispatch COM interfaces (which aren't directly supported by AHK_L). On that note, CreateInstance must be kept as it allows non-dispatch objects to be created, but CreateObject can be removed as it's a simple wrapper around CreateInstance.
Back to top
Sean



Joined: 12 Feb 2007
Posts: 2462

PostPosted: Sat Aug 14, 2010 7:21 pm    Post subject: Reply with quote

Now you can think of COM.ahk as just a collection of miscellaneous functions which you can copy when you need them.

BTW, the supported features of COM_Invoke/COM_Parameter and those of the native COM are different. The most notable may be that COM.ahk does support named parameters. For the native COM to be competitive in this respect, I think it should support the same named parameters, or missing parameters, or both. My preference is the second one, support of missing parameters. Until then, I think better leave COM.ahk as it is.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Goto page Previous  1, 2, 3 ... 41, 42, 43, 44  Next
Page 42 of 44

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group