duzers 0 Posted November 6, 2010 (edited) Hello, I try to catch error in this code: $AmiBroker = ObjCreate("Broker.Application"); $ChkTicker = "ABC" $bb=$AmiBroker.Stocks($ChkTicker).Ticker If in program Broker "ABC" exist than all is alright, but if "ABC" not exist I get error. I translate code from Windows Stript Host, but this problem resolved by "TRY, CATCH" AmiBroker = new ActiveXObject( "Broker.Application" ); ChkTicker = "ABC"; function Main() { if( AmiBroker.Stocks.Count > 0 ) { try { return AmiBroker.Stocks( ChkTicker ).Ticker == ChkTicker; } catch( e ) { WScript.echo("error"); } } return false; } Main(); How I do this in Autoit? THX Edited November 6, 2010 by duzers Share this post Link to post Share on other sites
JohnOne 1,603 Posted November 7, 2010 If...Then...ElseIf...Then...Else maybe. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Share this post Link to post Share on other sites
trancexx 1,013 Posted November 7, 2010 @JohnOne, like this? Global $oError = ObjEvent("AutoIt.Error", "_ErrFunc") Func _ErrFunc() ;~ ConsoleWrite("! COM Error ! Number: 0x" & Hex($oError.number, 8) & " ScriptLine: " & $oError.scriptline & " - " & $oError.windescription & @CRLF) EndFunc ;==>_ErrFunc Global $AmiBroker = ObjCreate("Not.Broker.Application"); If $oError.number Then MsgBox(48, "Error", "Error number = " & Hex($oError.number, 8)) Else ; Maybe EndIf ;... ♡♡♡ . eMyvnE Share this post Link to post Share on other sites
duzers 0 Posted November 7, 2010 If...Then...ElseIf...Then...Elsemaybe.I try use ObjEvent and @error, but it's not work.My code returns: ==> Object referenced outside a "With" statement.:$bb=$AmiBroker.Stocks($ChkTicker).Ticker$bb=$AmiBroker.Stocks($ChkTicker)^ ERROR,when result "ABC" is not on database at broker application.I only wont to chect it, and javascript allows to chect it by Try/Catch.BTW if in javascript I use etc. If AmiBroker.Stocks(ChkTicker).Ticker=="ABC" it returns similar error. Share this post Link to post Share on other sites
trancexx 1,013 Posted November 7, 2010 You don't know what javascript allows. You don't have that capability. Learn basics (like 1+1=2) and then ask what you want. ...Only then you won't since you'll be seeing that your question is already answered. ♡♡♡ . eMyvnE Share this post Link to post Share on other sites
duzers 0 Posted November 7, 2010 (edited) You don't know what javascript allows. You don't have that capability. Learn basics (like 1+1=2) and then ask what you want. ...Only then you won't since you'll be seeing that your question is already answered. ok but I have it!, look: Global $g_eventerror = 0 ; to be checked to know if com error occurs. Must be reset after handling. $oMyError = ObjEvent("AutoIt.Error","MyErrFunc") ; Install a custom error handler ; Performing a deliberate failure here (object does not exist) $oIE = ObjCreate("Broker.Application") $oStocks = $oIE.Stocks("ABC"); $oSymbol = $oStocks.ticker; if $g_eventerror then Msgbox(0,"","the previous line got an error.") Exit ; This is my custom error handler Func MyErrFunc() $HexNumber=hex($oMyError.number,8) Msgbox(0,"","We intercepted a COM Error !" & @CRLF & _ "Number is: " & $HexNumber & @CRLF & _ "Windescription is: " & $oMyError.windescription ) $g_eventerror = 1 ; something to check for when this function returns Endfunc This code returns COM error info when "ABC" is not on "the list". Thx to all Edited November 7, 2010 by duzers Share this post Link to post Share on other sites