AutoHotkey Community

It is currently May 26th, 2012, 11:18 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 6 posts ] 
Author Message
PostPosted: November 2nd, 2008, 6:10 am 
Offline

Joined: February 11th, 2005, 6:31 am
Posts: 174
Location: Germany
Hello,

I'm looking for a way, catching the error: "call to non-existent function" via errorlevel or something like this.
So when I start the script and ahk comes to the FunctionThatDoesNotExist() I want to avoid stopping the program. Instead it should be possible to react by the program to this error.

Any help would be appreciated!

Best regards,
Andi


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 2nd, 2008, 3:21 pm 
#ErrorStdOut findest du in der Hilfe. SO einfach ist das. :wink:


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: November 3rd, 2008, 1:39 am 
Online
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8776
You can suppress the error by calling the function dynamically:

Quote:
v1.0.47 released: Stdlib, RegisterCallback, NumGet/Put posted by Chris

Added dynamic function calling. [developed by lexiKos]
Description: A function (even a built-in function) may be called dynamically via percent signs. For example, %Var%(x, "fox") would call the function whose name is contained in Var. Similarly, Func%A_Index%() would call Func1() or Func2(), etc., depending on the current value of A_Index. The called function's definition must exist explicitly in the script, either via #Include or a non-dynamic call to a library containing the function. If the function does not exist -- or if the wrong number or type of parameters is passed to it -- the expression containing the call produces an empty string.





Code:
Func=SubStr
Result := %Func%( "Skan",1,2 )
If ( Result = "" )
    {
      MsgBox, 16, Fatal Error,Function %Func%() Not Defined,5
      ExitApp
    }
Else
 MsgBox, % Result

Func=SubString
Result := %Func%( "Skan",1,2 )
If ( Result = "" )
    {
      MsgBox, 16, Fatal Error,Function %Func%() Not Defined,5
      ExitApp
    }
Else
 MsgBox, % Result

_________________
URLGet - Internet Explorer based Downloader
StartEx - Portable Shortcut Link


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 3rd, 2008, 10:59 pm 
Offline

Joined: February 11th, 2005, 6:31 am
Posts: 174
Location: Germany
Thank you Bobo and Skan :D

When I understand it right, the hint from BoBo with #ErrorStdOut stops the script. But I'm searching more for a solution that Skan descibes that keeps the script running. But additional I want to add the missing function to the lib folder.

So I tried the following, but there is one thing I don't understand: When the last but one line is missing, it leads to an error :roll:
Code:
Func=SubStr
Result := %Func%( "Skan",1,2 )
If ( Result = "" )
    {
      MsgBox, 16, Fatal Error,Function %Func%() Not Defined,5
      ExitApp
    }
Else
 MsgBox, % Result


ifNotExist %A_Scriptdir%\lib\subString.ahk
   {
      ifNotExist %A_Scriptdir%\lib
         FileCreateDir, %A_Scriptdir%\lib
      FileAppend,
      (   ;only for testing
         Substring(String, StartingPos, Length)
            {
               return SubStr(String, StartingPos, Length)
            }
      ), %A_Scriptdir%\lib\SubString.ahk
   }


Func=SubString
Result := %Func%( "Skan",1,2 )
If ( Result = "" )
    {
      MsgBox, 16, Fatal Error,Function %Func%() Not Defined,5
      ExitApp
    }
Else
 MsgBox, % Result
 
;The function above:
;Func=SubString
;Result := %Func%( "Skan",1,2 )
;works only, when the following line exists!?
Result := Substring( "Skan",1,2 )
 MsgBox, % Result


I have to correct me: The first time you run the script, the last but one line stops the script. So when you run the first time without it, you see the error message from the msgbox. But when you run it a second time with the last but one line it doesn't work?!


Last edited by Andi on November 4th, 2008, 5:47 am, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 4th, 2008, 12:38 am 
Online
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8776
What you are trying to accomplish is not possible as on date.
AHK reads the whole script before it will execute a single line of it.
You will need two scripts, where the first script will check for dependencies and set things right and then load the target script.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 4th, 2008, 6:00 am 
Offline

Joined: February 11th, 2005, 6:31 am
Posts: 174
Location: Germany
Thank you Skan for the clarification :D

I skiped the following sentence :oops:
Quote:
The called function's definition must exist explicitly in the script, either via #Include or a non-dynamic call to a library containing the function.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: 0x150||ISO, BrandonHotkey, SKAN and 55 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group