aGorilla Posted May 10, 2008 Share Posted May 10, 2008 (edited) Based on DaleHohm's comments in this thread, and GaryFrost's dictionary object thread Out of personal preference, I did a bit of renaming, and changed the indent to 2 spaces. If that's sacrilege, let me know. I've added error handling (possibly too much), and the function headers needed for documentation. I'm a bit confused by Gary's code referring to a COM error handler, and I'm not quite sure when a COM error would occur, and whether @error would be set or not, so some of the error handling is likely to be off. Let me know if you see anything wrong, or have suggestions for improvement. Please check both, the headers, and the code. Thanks for your help. I'd post as an attachment, but it's not liking Mozilla. I broke down and ran IE.Hash.au3Edit: updated code, Added attachment. Edited May 17, 2008 by aGorilla Search AutoItScript.com via Google Link to comment Share on other sites More sharing options...
sbgwb0769 Posted May 13, 2008 Share Posted May 13, 2008 what? Link to comment Share on other sites More sharing options...
aGorilla Posted May 13, 2008 Author Share Posted May 13, 2008 While I appreciate the bump, that doesn't really add much to the conversation. Do you actually have a question? Search AutoItScript.com via Google Link to comment Share on other sites More sharing options...
JRSmile Posted May 13, 2008 Share Posted May 13, 2008 nice udf, adds many abillities i missed in the previous ones, Thumbs UP :-) $a=StringSplit("547275737420796F757220546563686E6F6C75737421","") For $b=1 To UBound($a)+(-1*-1*-1)step(2^4/8);&$b+=1*2/40*µ&Asc(4) Assign("c",Eval("c")&Chr(Dec($a[$b]&$a[$b+1])));''Chr("a")&"HI" Next ;time_U&r34d,ths,U-may=get$the&c.l.u.e;b3st-regards,JRSmile; MsgBox(0x000000,"",Eval("c"));PiEs:d0nt+*b3.s4d.4ft3r.1st-try:-) Link to comment Share on other sites More sharing options...
aGorilla Posted May 13, 2008 Author Share Posted May 13, 2008 nice udf, adds many abillities i missed in the previous ones, Thumbs UP :-)Thanks, but I can't take credit for that. The feature set was pretty much laid out by DaleHohm and GaryFrost, I just added a bit of error checking (which I'm hoping is correct), and function documentation.I'm hoping to work on examples next week, and that should help me find out if the error checking is ok.In the mean time, if you use it, I'd love to hear how it goes. Search AutoItScript.com via Google Link to comment Share on other sites More sharing options...
DaleHohm Posted May 14, 2008 Share Posted May 14, 2008 I haven't had time to stress test it, but by observation it looks good. There are some issues with the error handling however. First on _HashAdd you need to check IsObj after the ObjCreate instead of relying on @error. In most of the other routines checking @error as you are won't help you because without a COM error handler instantiated, the COM errors will be fatal and you'll bomb out of the script before @error can be checked. This is a difficult issue... If you instantiate your own COM error handler you can conflict with IE.au3 and Word.au3 and possibly Excel.au3 error handlers. Best solution would probably be to try to anticipate and avoid as many errors as possible and then document a suggestion that the use instantiate their own COM error handler such that the errors are no longer fatal and your @error checks would work. Speaking for me, I need no attribution in this code and I'm guessing that Gary doesn't either (although he can speak for himself). This is why I offered it up for someone to complete. I'd prefer you simply took ownership of it. Dale Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model Automate input type=file (Related) Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded Better Better? IE.au3 issues with Vista - Workarounds SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead? Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble Link to comment Share on other sites More sharing options...
JRSmile Posted May 14, 2008 Share Posted May 14, 2008 In the mean time, if you use it, I'd love to hear how it goes.I'm currently developing a µTorrent UDF and for now it works like a charme.It is utilized to make a "config_variable_name" <> "config_variable_value" relation table.I will use it for nearly every funtion that will be in that UDF.Best regards,J. $a=StringSplit("547275737420796F757220546563686E6F6C75737421","") For $b=1 To UBound($a)+(-1*-1*-1)step(2^4/8);&$b+=1*2/40*µ&Asc(4) Assign("c",Eval("c")&Chr(Dec($a[$b]&$a[$b+1])));''Chr("a")&"HI" Next ;time_U&r34d,ths,U-may=get$the&c.l.u.e;b3st-regards,JRSmile; MsgBox(0x000000,"",Eval("c"));PiEs:d0nt+*b3.s4d.4ft3r.1st-try:-) Link to comment Share on other sites More sharing options...
aGorilla Posted May 15, 2008 Author Share Posted May 15, 2008 Thanks for the feedback. @DaleHohm: I'm thinking you meant _HashNew(), not _HashAdd(), that said... should I check both, IsObj, and then @error? Is it possible that the object would be created, but some other error occured? I'm guessing no, but I'm not sure. I noticed in Gary's example that he was doing the COM error handler in the example code, so I was thinking it would be best to leave that to the user. I'll point that out in the _HashNew() example. I'll also try to dig into the MS docs for Scripting.Dictionary to see if I can figure out when I should use @error. @JRSmile: Thanks for testing it. It should be fairly stable, and I'll try to improve on the error handling this weekend. The biggest changes would likely be in the error return values, but I'll try to keep changes to a minimum. Search AutoItScript.com via Google Link to comment Share on other sites More sharing options...
aGorilla Posted May 17, 2008 Author Share Posted May 17, 2008 Updated code in 1st post. Added (optional) 'compare mode' to _HashNew() Removed @error checks from all but _HashAdd() and _HashDelete() (following GaryFrost's lead). Added links to MSDN docs, and some remarks from those pages. Reduced use of _HashFind() to match the above mentioned docs (although I don't agree with their approach). Took ownership. Set up shell files for examples, but haven't started on them yet. May work on them tommorow. Considering adding a display function (inspired by Array library), would come in handy for examples. Search AutoItScript.com via Google Link to comment Share on other sites More sharing options...
DaleHohm Posted May 17, 2008 Share Posted May 17, 2008 Does it break the comment lines in the code box for you like it does for me? ; ==================================================================================================== =========================== Func _HashSet($oHash, $vKey, $vValue) I have to spend a few minutes cleaning it up before I can test it. Perhaps you can correct the basenote post. Dale Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model Automate input type=file (Related) Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded Better Better? IE.au3 issues with Vista - Workarounds SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead? Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble Link to comment Share on other sites More sharing options...
aGorilla Posted May 17, 2008 Author Share Posted May 17, 2008 Does it break the comment lines in the code box for you like it does for me? ; ==================================================================================================== =========================== Func _HashSet($oHash, $vKey, $vValue) I have to spend a few minutes cleaning it up before I can test it. Perhaps you can correct the basenote post. DaleYep, was annoying me too. Added attachment. Search AutoItScript.com via Google Link to comment Share on other sites More sharing options...
aGorilla Posted May 17, 2008 Author Share Posted May 17, 2008 Best solution would probably be to try to anticipate and avoid as many errors as possible and then document a suggestion that the use instantiate their own COM error handler such that the errors are no longer fatal and your @error checks would work. Removed @error checks from all but _HashAdd() and _HashDelete() (following GaryFrost's lead). It seems I may have jumped the gun on that one. Some day I'll learn to not 'skim' while reading replies. Search AutoItScript.com via Google Link to comment Share on other sites More sharing options...
DaleHohm Posted May 17, 2008 Share Posted May 17, 2008 Another check you can to is to insure that the object actually IS a Dictionary object: If Not (ObjName($oHash) = "IDictionary") Then Return SetError(2, 0, False) Dale Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model Automate input type=file (Related) Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded Better Better? IE.au3 issues with Vista - Workarounds SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead? Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble Link to comment Share on other sites More sharing options...
jaui Posted May 28, 2008 Share Posted May 28, 2008 Updated code in 1st post. ... you have also to update _HashClear, because .RemoveAll didn't require an argument. ; #FUNCTION# ==================================================================================================================== ; Name...........: _HashClear ; Description ...: Remove all key/value pairs. ; Syntax.........: _HashClear($oHash) ; Parameters ....: $oHash - Hash object, created with _HashNew ; Return values .: Success - Returns True ; Failure - Returns False, and sets @error: ; |1 - Invalid $oHash - Not an object ; Author ........: Bill Guindon (aGorilla) ; Modified.......: ; Remarks .......: http://msdn.microsoft.com/en-us/library/45731e2w(VS.85).aspx ; Related .......: ; Link ..........; ; Example .......; ; =============================================================================================================================== Func _HashClear($oHash) If Not IsObj($oHash) Then Return SetError(1, 0, False) $oHash.removeAll() Return True EndFunc Link to comment Share on other sites More sharing options...
nobbe Posted May 28, 2008 Share Posted May 28, 2008 there is also a hash table class in the .net http://msdn.microsoft.com/en-us/library/sy....hashtable.aspx; hash tablesGlobal $hash = ObjCreate("System.Collections.Hashtable"); add$hash.add ($key, $value);get value$value = $hash ($key) ; Link to comment Share on other sites More sharing options...
Moderators big_daddy Posted June 24, 2008 Moderators Share Posted June 24, 2008 Very useful library! I found a bug in _HashClear(), the .removeAll method should be called without parameters. ; #FUNCTION# ==================================================================================================================== ; Name...........: _HashClear ; Description ...: Remove all key/value pairs. ; Syntax.........: _HashClear($oHash) ; Parameters ....: $oHash - Hash object, created with _HashNew. ; Return values .: Success - Returns True ; Failure - Returns False, and sets @error: ; |1 - Invalid $oHash - Not an object ; Author ........: Bill Guindon (aGorilla) ; Modified.......: Bob Anthony (big_daddy) ; Remarks .......: http://msdn.microsoft.com/en-us/library/45731e2w(VS.85).aspx ; Related .......: ; Link ..........; ; Example .......; ; =============================================================================================================================== Func _HashClear($oHash) If Not IsObj($oHash) Then Return SetError(1, 0, False) $oHash.removeAll() Return True EndFunc Link to comment Share on other sites More sharing options...
Skizmata Posted May 10, 2009 Share Posted May 10, 2009 (edited) Based on DaleHohm's comments in this thread, and GaryFrost's dictionary object thread You guys have made my day. In my work I use perl daily and one of the few big points that I have allways wished AutoIt had was a perl style Hash. This is going to be used in everything I use from here on out I think. I cant thank you guys enough. Thank you! aGorilla DaleHohm and GaryFrost *Edit* Is there a reason I should use _HashAdd over _HashSet? In this example it seems HashSet has no problem adding a hash element. $hash = _HashNew() _HashSet($hash, "Key", "Value") MsgBox(0, "", _HashGet($hash, "Key")) _HashSet($hash, "Key", "NewValue") MsgBox(0, "", _HashGet($hash, "Key")) _HashAdd($hash, "Key2", "Value2") MsgBox(0, "", _HashGet($hash, "Key2")) _HashAdd($hash, "Key2", "NewValue2") MsgBox(0, "", _HashGet($hash, "Key2")) Edited May 10, 2009 by Skizmata AutoIt changed my life. Link to comment Share on other sites More sharing options...
hunt Posted July 12, 2009 Share Posted July 12, 2009 Hello! How to set event for _HashAdd or _HashSet? Link to comment Share on other sites More sharing options...
Zedna Posted July 12, 2009 Share Posted July 12, 2009 @aGorilla Very nice! Hash.au3 in first post seems to be ready for standard UDF. Why didn't you send it as proposition for standard UDF (on the Trac) already? Trac: http://www.autoitscript.com/trac/autoit Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
monoceres Posted July 12, 2009 Share Posted July 12, 2009 @Zedna, as you already know, there are already a hash/crypt UDF on the way into the standard UDF library. I don't know what advantages this have, mine is pretty much as complete as it gets. Broken link? PM me and I'll send you the file! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now