Sign in to follow this  
Followers 0
gcue

strange behavior with return values

5 posts in this topic

hello world!

when more than 1 pc is selected, i am trying to prompt the user again to avoid inadvertent selections.  

 

if i enter the correct value the first time the function returns TRUE around it works great

however

if i enter the wrong value the first time, then the correct value the second time - the return value is 0 and not TRUE so the script does not continue

 

im sure it has to do with re-running the _Authorize function - but i dont see how to fix it - what am i missing????

thanks in advance!

#include <array.au3>
$msg_normal = 0


Test()


Func Test()


$selection_text = "Test"


$pcs_selected = 2;UBound($selected_checkboxes) - 1


If $pcs_selected > 1 Then
$message = "You have selected to " & $pcs_selected & " PCs." & @CRLF & @CRLF & "Please type the number '" & $pcs_selected & "' without quotes to continue."


$authorize = _Authorize($selection_text, $message, $pcs_selected)


Debug($authorize)


If $authorize = False Then
Debug("NOT updating")
Return
EndIf
EndIf


Debug("updating")


EndFunc   ;==>Test


Func _Authorize($selection_text, $message, $requirement)


$authorize = False


$input = InputBox($selection_text, $message, "", " M", 320, 160)


If @error Then
Return $authorize
EndIf


Debug()


If $input = $requirement Then
Debug("passed", $input, $requirement)
$authorize = True
Return $authorize
Else
Debug("failed", $input, $requirement)
_Authorize($selection_text, $message, $requirement)
EndIf


EndFunc   ;==>_Authorize


Func Debug($variable1 = "", $variable2 = "", $variable3 = "")


;~  #include <array.au3>
;~  $msg_normal = 0


If IsArray($variable1) Then
_ArrayDisplay($variable1)
Else
If $variable2 <> "" Then
$variable1 &= @CRLF & $variable2
EndIf


If $variable3 <> "" Then
$variable1 &= @CRLF & $variable3
EndIf


ClipPut($variable1)
MsgBox($msg_normal, "Debug", $variable1)
EndIf


EndFunc   ;==>Debug

 

Share this post


Link to post
Share on other sites



Try it this way instead, this way you're only calling _Authorize once and still able to keep calling up an InputBox until the entry is correct or cancelled.

#Tidy_Parameters=/rel
#include <array.au3>
$msg_normal = 0
Test()
Func Test()
    $selection_text = "Test"
    $pcs_selected = 2;UBound($selected_checkboxes) - 1
    If $pcs_selected > 1 Then
        $message = "You have selected to " & $pcs_selected & " PCs." & @CRLF & @CRLF & "Please type the number '" & $pcs_selected & "' without quotes to continue."
        $authorize = _Authorize($selection_text, $message, $pcs_selected)
        ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $authorize = ' & $authorize & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
        Debug($authorize)
        If $authorize = False Then
            Debug("NOT updating")
            Return
        EndIf
    EndIf
    Debug("updating")
EndFunc   ;==>Test
Func _Authorize($selection_text, $message, $requirement)
    $authorize = False
    $input = InputBox($selection_text, $message, "", " M", 320, 160)
    If @error Then
        Return $authorize
    EndIf
    While $input <> $requirement
        $input = InputBox($selection_text, $message, "", " M", 320, 160)
        If @error Then
            Return $authorize
        EndIf
    WEnd
    Debug("passed", $input, $requirement)
    $authorize = True
    Return $authorize
EndFunc   ;==>_Authorize
Func Debug($variable1 = "", $variable2 = "", $variable3 = "")
    If IsArray($variable1) Then
        _ArrayDisplay($variable1)
    Else
        If $variable2 <> "" Then
            $variable1 &= @CRLF & $variable2
        EndIf
        If $variable3 <> "" Then
            $variable1 &= @CRLF & $variable3
        EndIf
        ClipPut($variable1)
        MsgBox($msg_normal, "Debug", $variable1)
    EndIf
EndFunc   ;==>Debug

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

works great!!

curious - any reason you could see why the other one didnt work - just for my info since i spent so much trying to figure it out !

thank you very much!

Edited by gcue

Share this post


Link to post
Share on other sites

When you called _Authorize the second time here:

Else
        Debug("failed", $input, $requirement)
        _Authorize($selection_text, $message, $requirement)
    EndIf

The return from the successful result is returned and the If/Endif ends, and because you called it twice and only returned once (so far) it doesn't return anything when it hits the EndFunc line except 0, which is translated as False.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

ahhhhhh makes sense!

thank you again =)

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