duzers Posted November 6, 2010 Share 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 Link to comment Share on other sites More sharing options...
JohnOne Posted November 7, 2010 Share 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. Link to comment Share on other sites More sharing options...
trancexx Posted November 7, 2010 Share 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 Link to comment Share on other sites More sharing options...
duzers Posted November 7, 2010 Author Share 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. Link to comment Share on other sites More sharing options...
trancexx Posted November 7, 2010 Share 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 Link to comment Share on other sites More sharing options...
duzers Posted November 7, 2010 Author Share 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 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