oktoberfest2 Posted October 25, 2007 Share Posted October 25, 2007 I'm finding that COM support in Auto-It just isn't cutting it. I'm trying to access contents in a public folder. Below is my converted code from VB to Auto-It. VB works fine and hopefully I can get this to run in Auto-It with a little help. Any help would be much appreciated and revive my confidence in the program. Thanks Dim $objApp Dim $objNS Dim $colFolders Dim $objFolder ;Substitute MyPublicFolder for one that exists on your system _GetFolder ("Public Folders\All Public Folders\MyPublicFolder") ;Return count of items in folder msgbox(0,"test",$objFolder.Items.Count) Func _GetFolder($strFolderPath) Dim $arrFolders Dim $i $arrFolders = StringSplit($strFolderPath, "\") $objApp = ObjCreate("Outlook.Application") $objNS = $objApp.GetNamespace("MAPI") $objFolder = $objNS.Folders.Item($arrFolders[1]) If stringlen($objFolder)>0 Then For $i = 2 To $arrFolders[0] $colFolders = $objFolder.Folders $objFolder = $colFolders.Item($arrFolders[$i]) If stringlen($objFolder)=0 Then ExitLoop EndIf Next EndIf $GetFolder = $objFolder EndFunc Link to comment Share on other sites More sharing options...
PsaltyDS Posted October 25, 2007 Share Posted October 25, 2007 (edited) I'm finding that COM support in Auto-It just isn't cutting it. I'm trying to access contents in a public folder. Below is my converted code from VB to Auto-It. VB works fine and hopefully I can get this to run in Auto-It with a little help. Any help would be much appreciated and revive my confidence in the program. Thanks Func _GetFolder($strFolderPath) ; ... If stringlen($objFolder)>0 Then ; ... EndIf $GetFolder = $objFolder EndFunc So... you're testing the StringLen() of an object variable... and this function returns what...??? Oh, well. You should just give up. COM object methods must be way over AutoIt's head! P.S. I am appropriately ashamed of myself for sarcasm and rude laghter. :"> P.P.S. ...ahem. Shame on me. Edited October 25, 2007 by PsaltyDS Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
ptrex Posted October 25, 2007 Share Posted October 25, 2007 @oktoberfest2 1. When you have a problem with a converted vbscript, than it's best to include the orginal script as well 2. When using COM it is best to include the COM error routine for bug tracking regards, ptrex Contributions :Firewall Log Analyzer for XP - Creating COM objects without a need of DLL's - UPnP support in AU3Crystal Reports Viewer - PDFCreator in AutoIT - Duplicate File FinderSQLite3 Database functionality - USB Monitoring - Reading Excel using SQLRun Au3 as a Windows Service - File Monitor - Embedded Flash PlayerDynamic Functions - Control Panel Applets - Digital Signing Code - Excel Grid In AutoIT - Constants for Special Folders in WindowsRead data from Any Windows Edit Control - SOAP and Web Services in AutoIT - Barcode Printing Using PS - AU3 on LightTD WebserverMS LogParser SQL Engine in AutoIT - ImageMagick Image Processing - Converter @ Dec - Hex - Bin -Email Address Encoder - MSI Editor - SNMP - MIB ProtocolFinancial Functions UDF - Set ACL Permissions - Syntax HighLighter for AU3ADOR.RecordSet approach - Real OCR - HTTP Disk - PDF Reader Personal Worldclock - MS Indexing Engine - Printing ControlsGuiListView - Navigation (break the 4000 Limit barrier) - Registration Free COM DLL Distribution - Update - WinRM SMART Analysis - COM Object Browser - Excel PivotTable Object - VLC Media Player - Windows LogOnOff Gui -Extract Data from Outlook to Word & Excel - Analyze Event ID 4226 - DotNet Compiler Wrapper - Powershell_COM - New Link to comment Share on other sites More sharing options...
DaleHohm Posted October 25, 2007 Share Posted October 25, 2007 Hopefully this will restore your faith in AutoIt. It is obviously a new language for you and there are conventions and syntax you need to absorb. Note the IsObj test and how to return values from a function. BTW, the Count property returned 0 and I didn't go and study the object model docs -- .Name is returning an appropriate value. Need to check your item count syntax. expandcollapse popup#AutoIt3Wrapper_run_debug_mode=Y Dim $objApp Dim $objNS Dim $colFolders Dim $objFolder ;Substitute MyPublicFolder for one that exists on your system $oFolder = _GetFolder ("Public Folders\All Public Folders\MyFolder") ;Return count of items in folder ;msgbox(0,"test",$oFolder.Items.Count) msgbox(0,"test",$oFolder.Name) Func _GetFolder($strFolderPath) Dim $arrFolders Dim $i $arrFolders = StringSplit($strFolderPath, "\") $objApp = ObjCreate("Outlook.Application") $objNS = $objApp.GetNamespace("MAPI") $objFolder = $objNS.Folders.Item($arrFolders[1]) ConsoleWrite(ObjName($objFolder) & @CR) If IsObj($objFolder) Then For $i = 2 To $arrFolders[0] $colFolders = $objFolder.Folders $objFolder = $colFolders.Item($arrFolders[$i]) If Not IsObj($objFolder) Then ExitLoop EndIf Next EndIf Return $objFolder EndFunc 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...
oktoberfest2 Posted October 25, 2007 Author Share Posted October 25, 2007 First, I apologize as my problem was not clearly stated. From DaleHohm's example and the rude laughter of PsaltyDS I corrected my script and was able to get it to work. isObj did the trick As suggested, I have also added COM Error handling to the script. Just to get a second opinion, using a variable ByRef is not supported in AutoIt, correct? If you also want a more worthy problem of mine (related to Crystal Reports Viewer COM object) that is better explained, check out the following: DateParameter Again I appreciate your help, especially as I failed to clearly state my problem. Link to comment Share on other sites More sharing options...
Nevin Posted October 25, 2007 Share Posted October 25, 2007 (edited) I've seen Internet explorer UDFs which used Byrefs in their parameters in the help file examples, if that means anything.Inserting shameless help topic advertisement:Speaking of the IE UDFs, Dale, aren't you the one who wrote them? Maybe you could help me in the thread I recently made in this section? Never mind. Thanks Psalty. Edited October 25, 2007 by Nevin Link to comment Share on other sites More sharing options...
PsaltyDS Posted October 25, 2007 Share Posted October 25, 2007 First, I apologize as my problem was not clearly stated. From DaleHohm's example and the rude laughter of PsaltyDS I corrected my script and was able to get it to work. isObj did the trick As suggested, I have also added COM Error handling to the script. Wahoo! Just to get a second opinion, using a variable ByRef is not supported in AutoIt, correct? You really need to start reading the help file, or there WILL be more rude laughter! Func...Return...EndFunc -------------------------------------------------------------------------------- Defines a user-defined function that takes zero or more arguments and optionally returns a result. Func functioname ( [Const] [byRef] $param1, ..., [Const] [byRef] $paramN, $optionalpar1 = value, ...) ... [Return [value]] EndFunc Remarks The ByRef keyword is optional and means: (1) the parameter must a variable, and (2) the original variable is linked to the parameter, so that any changes to the parameter inside the function, would affect the original variable as well. By default, a parameter is passed by value which means that a copy of the parameter's value, is manipulated by the function. The order of the ByRef and Const keywords is not important, so long as they are in front of the variable they modify. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
DaleHohm Posted October 26, 2007 Share Posted October 26, 2007 Yes, read the docs, but in this case they don't tell the whole story. byRef is certainly supported in AutoIt, but object variables are treated as byVal even when passed byRef. To my knowledge this is not in the docs, only in recent discussions here in the forum. 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...
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