Sign in to follow this  
Followers 0
Reveille

Paramater Variable Declarations

10 posts in this topic

This should be an easy fix, but thus far the solution has eluded me :/

Can someone please help me with my functions parameter syntax. It says the variable (Delegate) is used without being declared. All suggestions welcome.

Func _Exit($Delegate)
    Local $TermStr
    
    If $Delegate == 1 Then
        $TermStr = " Manual Termination."
    Else
        $TermStr = " Terminating..."
    EndIf
    
    Call("WriteLog","Exit Function called.  Line  1674" & $TermStr,0)
    Call("WriteLog","Exit Function called.  Line  1675" & $TermStr,1)
    Exit
EndFunc

Share this post


Link to post
Share on other sites



This should be an easy fix, but thus far the solution has eluded me :/

Can someone please help me with my functions parameter syntax. It says the variable (Delegate) is used without being declared. All suggestions welcome.

Func _Exit($Delegate)
    Local $TermStr
    
    If $Delegate == 1 Then
        $TermStr = " Manual Termination."
    Else
        $TermStr = " Terminating..."
    EndIf
    
    Call("WriteLog","Exit Function called.  Line  1674" & $TermStr,0)
    Call("WriteLog","Exit Function called.  Line  1675" & $TermStr,1)
    Exit
EndFunc
Works for me (with some tweaking to not use your 'Call'):

_Exit(1)

Func _Exit($Delegate)
    Local $TermStr
    
    If $Delegate == 1 Then
        $TermStr = " Manual Termination."
    Else
        $TermStr = " Terminating..."
    EndIf
    
    ConsoleWrite("WriteLog, Exit Function called.  Line  1674.  " & $TermStr & @LF)
    ConsoleWrite("WriteLog, Exit Function called.  Line  1675.  " & $TermStr & @LF)
    Exit
EndFunc

Perhaps the error is not coming from this function? Are you using that variable name anywhere else?

:whistle:


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

Share this post


Link to post
Share on other sites

Perhaps the error is not coming from this function? Are you using that variable name anywhere else?

I have another function that uses the same variable name, but arent parameters local unless otherwise specified?

Heres my other function that works fine.

Func WriteLog($LogTxt, $Delegate)

I tried changing the variable name to prevent ambiguity but I'm still generating the same error. I've also commented out the 2 'Call' function lines with no solution.

O yea and i forgot to specify that the error is being generated at the if statement that first uses the variable.

ie: If $Delegate2 == 1 Then

_____^here

Share this post


Link to post
Share on other sites

ie: If $Delegate2 == 1 Then

_____^here

Ok, but that's not $Delegate.

"be smart, drink your wine"

Share this post


Link to post
Share on other sites

I have another function that uses the same variable name, but arent parameters local unless otherwise specified?

Heres my other function that works fine.

Func WriteLog($LogTxt, $Delegate)

I tried changing the variable name to prevent ambiguity but I'm still generating the same error. I've also commented out the 2 'Call' function lines with no solution.

O yea and i forgot to specify that the error is being generated at the if statement that first uses the variable.

ie: If $Delegate2 == 1 Then

_____^here

Post a running demo script that includes a call to the function and the function (like mine above). Minimum amount of code that shows the error when you run it.

:whistle:


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

Share this post


Link to post
Share on other sites

My hotkey loop that calls the function:

While 1

$_Run = HotKeySet ( "{INSERT}", "_Run" );//Run hotkey
$_Exit = HotKeySet ( "{HOME}", "_Exit" );//Exit hotkey

  Select

    Case $_Run = 0
      _Run ()
    Case $_Exit = 0
      _Exit(1)
EndSelect

WEnd

The code that generates the error@ 'If $2Delegate2 == 1 Then'

Func _Exit($2Delegate2)
    Local $TermStr
    
    If $2Delegate2 == 1 Then
        $TermStr = " Manual Termination."
    Else
        $TermStr = " Terminating..."
    EndIf
;Call("WriteLog","Exit Function called.  Line " & @ScriptLineNumber & $TermStr,0)
;Call("WriteLog","Exit Function called.  Line " & @ScriptLineNumber & $TermStr,1)
    Exit
EndFunc

this isnt all that relevant but ill post anyway. This is my logging function. Before the parameter names were the same name. This function generates no errors but is essentially the same code.

Func WriteLog($LogTxt, $1Delegate1)
    Local $Time = TimeStamp()
    
    If $1Delegate1 == 0 Then
        $File = FileOpen("C:\VerbooseLog.txt", 1);//append mode, if file doesnt exsist then it is automaticaly created
    ElseIf $1Delegate1 == 1 Then
        $File = FileOpen("C:\ReportLog.txt", 1);//append mode, if file doesnt exsist then it is automaticaly created
    EndIf
    
;//If FileExists("C:\Program Files\AdBux\Log.txt") Then
    If $File == -1 Then
        MsgBox(0, "Error", "Unable to open file.")
        FileClose($File)
        Return(0)
    Else
        FileWriteLine($File, $Time & @TAB & $LogTxt)
        FileClose($File)
    EndIf
EndFunc

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

You can't pass any parameters to a Hotkey function.

When you press {HOME}, _Exit is executed with no parameters. Therefore you get a $2Delegate2 error.

Edited by Siao

"be smart, drink your wine"

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Thanks alot for the info.

Is it possiable to make a call from my hotkey loop without any parameters but to still have parameters in the function itself?

ie

Case $_Exit = 0
      _Exit()
EndSelect

~

Func _Exit($2Delegate2)

Then test for the variables presence. Something like...

If $2Delegate2 ==""

(I know testing for Null wont solve my problem, but is there a test that detects if the variable is declared?)

Or is it possiable to catch and test for a specific error (in this case to test for 'variable not declaired')

Or would it just be easier to make two logging functions and avoid the Delegate functionality all together?

Edited by Reveille

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

(I know testing for Null wont solve my problem, but is there a test that detects if the variable is declared?)

There's IsDeclared

Also if you declare variable as Global, at some point assign a value to it, you can check it inside of such Hotkey function...

Global $2Delegate2 = 0

...

Case $_Exit = 0

$2Delegate2 = 1

_Exit()

...

Edited by Siao

"be smart, drink your wine"

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

Im gonna try the IsDeclaired method to see if that works. Never thought about using a Global var, If I cant get the IsDeclaired method to work the way I need it to ill try that. Thanks again for the ideas!

Edited by Reveille

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0