Jump to content

how to use multiple conditions with if then


Recommended Posts

below is my script code , _ConfirmBeforeSubmit(),  _PrintReport are the function called ,

$sRemark = _ConfirmBeforeSubmit()

                 If $sRemark <> "Is checked" Then
                      If $sRemark <> "Is not checked" Then
 ;************************************************************************************************************  
    $iTestNum += 1                                                              
        _PrintReport($iTestNum, $iTestPoint, $sRemark)  
        Return "Error: " & $sRemark
     EndIf

 

What i want is that the code

$iTestNum += 1                                                              
        _PrintReport($iTestNum, $iTestPoint, $sRemark)  
        Return "Error: " & $sRemark
     EndIf

should run only if both conditions i.e.

If $sRemark <> "Is checked"
 If $sRemark <> "Is not checked"

are failed, i.e. if a single condition is true then it should not run $iTestNum += 1, i do not know how to do this i have used OR operator but with that any one condition gets failed and  $iTestNum += 1 gets executed which i do not want.

please help, i will be very thankful to you

Link to comment
Share on other sites

  • Moderators

vis,

If you want both conditions to be satisfied then you need to use AND like this:

#include <Constants.au3>

$sRemark = "I should run" ; Should run

 If $sRemark <> "Is checked" And $sRemark <> "Is not checked" Then
    MsgBox($MB_OK, "Result", "I am running")
Else
    MsgBox($MB_OK, "Result", "I am NOT running")
EndIf

$sRemark = "Is checked" ; Should NOT run

If $sRemark <> "Is checked" And $sRemark <> "Is not checked" Then
    MsgBox($MB_OK, "Result", "I am running")
Else
    MsgBox($MB_OK, "Result", "I am NOT running")
EndIf
All clear? :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Hi M23
 
Thanks a lot for helping, but if i used AND operator then at the same time both conditions need to be true which is not possible,
i think i need to explain it more.
In the code mentioned above
when

$sRemark match "Is checked" then it will do what is mentioned in the function _ConfirmBeforeSubmit()
and if  $sRemark find "Is not checked" then it will do according to the function
 
and if 

$sRemark do not match either with "Is checked" or with "Is not checked" then only it will call the _PrintReport function mentioned above
i m pasting the function _ConfirmBeforeSubmit() might help you to understand more
 

Func _ConfirmBeforeSubmit()

    Local $sRemark

    Local $iWindow = WinWait("Options")

    If $iWindow == 0 Then
        $sRemark = "FAIL"
        $sLogMsg = "Unable to find the opened Option window "
        ConsoleWrite($sLogMsg & @CRLF)
        _LogMsg("ERROR", 2, $sLogMsg, True)
        Return $sRemark
    Else

        WinActivate("Options")

        Local $iCheck = ControlCommand("Options", "", "[CLASS:Button; INSTANCE:13]", "IsChecked")

        If $iCheck Then
            $sRemark = "Is checked"
            ControlClick("Options", "", 1)
            $sLogMsg = "Checkbox is checked already"
            _LogMsg("INFO", 2, $sLogMsg, False)
            Return $sRemark

        Else
            $sRemark = "Is not checked"
            ControlClick("Options", "", 288)
            Sleep(3000)
            ControlClick("Options", "", 1)

            $sLogMsg = "checkbox has been ENABLED"
            _LogMsg("INFO", 2, $sLogMsg, False)
            Return $sRemark

        EndIf
    EndIf

EndFunc   ;==>_ConfirmBeforeSubmit
Edited by Melba23
Added code tags
Link to comment
Share on other sites

  • Moderators

vis,

I am afraid that explanation is a clear as mud to me. :(

Are you thinking of something like this?

Switch $sRemark
    Case "Is checked"
        ; Run some code here
    Case "Is not checked"
        ; Run some other code here
    Case Else
        ; Neither are true so run some different code here
EndSwitch
Does that help at all? :huh:

M23

P.S. When you post code please use Code tags - see here how to do it. Then you get a scrolling box and syntax colouring as you can see above now I have added the tags. ;)

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

M23

This code is not working. i try to explain it again.

I have created a function _ConfirmBeforeSubmit   <<<<<the code for the same function is mentioned above>>>>>

This function has 3 return types which are mentioned below.

1. "Is checked"

2. "Is not checked"

3. "FAIL"

(AND ALL these return types are stored in the variable $sRemark)

AND I am calling the function _ConfirmBeforeSubmit in a script.

let say script name "check"

$sRemark = _ConfirmBeforeSubmit()   (From this line of code written in the script "check" you can understand that i have used variable $sRemark which will store the return type received by _ConfirmBeforeSubmit() )

ok and now i just want to write the code which will check

1. for the return type "Is checked" if it get it then will do the same as mentioned in the function _ConfirmBeforeSubmit()

2. if ist return type "Is checked" does not match then check for the 2nd return type "Is not checked".

3. Important:  if both of the above mentioned return type does not match then only it will run the code for the 3rd return type "FAIL"

i hope it would be clear to you

Edited by vis
Link to comment
Share on other sites

Hi john can you provide me some code that how can we call a function within a switch statement.

 

i am pasting the code here please provide your feedback on this

$sRemark = _ConfirmBeforeSubmit()

Switch $sRemark
    Case "Is checked"
       
     ;which code should I run here as I am comparing the string "Is checked"
    ;and which in return execute the code of the function _ConfirmBeforeSubmit()


    Case "Is not checked"
        ; Run some other code here
    Case Else
        ; Neither are true so run some different code here
EndSwitch
Edited by vis
Link to comment
Share on other sites

$sRemark = _ConfirmBeforeSubmit()

Switch $sRemark
    Case "Is checked"
       
     somefunction()


    Case "Is not checked"

        someotherfunction()

    Case Else

        somedifferentfunction()

EndSwitch

You are not making much sense., you have already ran function _ConfirmBeforeSubmit(). and found what $sRemark is.

So just put the function you want to run for each return value after the relevant Case.

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

I m getting below mentioned error by using the above code

Unable to parse line.:
    Case "Is checked"
^ ERROR
>Exit code: 1    Time: 0.343
 

but thank you very much for cooperating, i do not know how i am going to run this script

Link to comment
Share on other sites

; Below is the function 

Func _ConfirmBeforeSubmit()  

Local $sRemark 

Local $iWindow =  WinWait("Options")  

    If $iWindow == 0 Then
        $sRemark = "FAIL"
        $sLogMsg = "Unable to find the opened Option window "
        ConsoleWrite($sLogMsg & @CRLF)
        _LogMsg("ERROR", 2, $sLogMsg, True)
        Return $sRemark
     Else                   
    WinActivate("Options")      
    Local $iCheck = ControlCommand("Options", "", "[CLASS:Button; INSTANCE:13]", "IsChecked") 
    
    If $iCheck Then    
       $sRemark = "Is checked" 
       ControlClick("Options","",1)
       WinWait(" - Microsoft Outlook") 
         
       $sLogMsg = "Checkbox is checked already"     
        _LogMsg("INFO", 2, $sLogMsg, False)                     
     Return $sRemark           
    Else
       $sRemark = "Is not checked" 
       ControlClick("Options","",288)
       Sleep(3000)
      ControlClick("Options","",1)
       WinWait(" - Microsoft Outlook")
      
      $sLogMsg = "Confirm before submitting a report checkbox has been ENABLED"     
        _LogMsg("INFO", 2, $sLogMsg, False) 
    Return $sRemark     
     EndIf  
     EndIf
   
      EndFunc

#cs 
IMPORTANT NOTE:

From the above function you can see that we have 3 return types
1. "Is checked"
2. "Is not checked" 
3. “FAIL”

And now I just want to create a script in which the 3rd return type i.e. “FAIL” should only be called 

if and only if both return types i.e. "Is checked" and "Is not checked" do not match.

And if any single return type either "Is checked" or "Is not checked" is match then it execute the functionality for the same mentioned above in the function.

As you provide some code yesterday using switch statement, I used that but got the error unable to parse line “Is checked”.

Then I further R&D on the same and try to do it using select statement but did not succeed .Hence pasting the same code which I have written in the script.

#ce

;SCRIPT CODE:

$iTestPoint = "Verify to enable the checkbox for confirm before submitting a report "


Select
    Case $sRemark = "Is checked"
       
    _ConfirmBeforeSubmit()  ; 


    Case $sRemark = "Is not checked"

       _ConfirmBeforeSubmit()

    Case Else

      $iTestNum += 1
        _PrintReport($iTestNum, $iTestPoint, $sRemark)
        Return "Error: " & $sRemark

EndSelect

Edited by vis
Link to comment
Share on other sites

$iTestPoint = "Verify to enable the checkbox for confirm before submitting a report "
$sRemark = _ConfirmBeforeSubmit()
Select
Case Not $sRemark = "Is checked" And Not $sRemark = "Is not checked"
    $iTestNum += 1
    _PrintReport($iTestNum, $iTestPoint, $sRemark)
    Return "Error: " & $sRemark
EndSelect
;this is the code which i have ran provided by you, is there any logical mistake in that?

HI ALL,

I have tried all the things but still not working , i have used the recent code provided by 0xdefea7 but did not work and get the below mentioned error:

 Unable to parse line.:

    $iTestNum += 1

^ ERROR

>Exit code: 1    Time: 0.222

<< Is this impossible to do the things which i have mentioned above i do not know but i think it can be done>>

Link to comment
Share on other sites

  • Moderators

vis,

As you have been asked before, post ALL of the script, not just this single function. There is no sensible reason why the code we have suggested to you does not work (and it should definitely parse), so there must be something in the rest of the script that is causing a problem. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Hi M23 ,

I have provided all the code to you, i think the function mentioned above was totally clear to you ,and there is no other part of the script , there are so many functions which i have run through the same type of script. Beside that what i want in the script i have also mentioned above , i thick the conditions which we have written in the scripts have some problems. please go through the comments i have written above. :mellow:

Link to comment
Share on other sites

  • Moderators

vis,

 

i think the function mentioned above was totally clear to you

Think again - no-one who has posted in this thread can work out what it is you want to do! :wacko:

As I stated above, there is no reason why the various code structures with which you have have provided do not parse or do not work as you wish. If you are unwilling to provide the rest of the script in which this code sits - and which must be the cause of the problem - then there is very little point in continuing. We need to see a runnable script - rather than snippets of functions and random error messages which purport to tell us that AutoIt cannot parse perfectly good code lines - or we might as well stop wasting Jon's bandwidth. :(

So either you post a full runnable script showing exactly how you use this _ConfirmBeforeSubmit function or I will close the thread. If you will not help us to help you, then you deserve no help - clear? :naughty:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

M23
I am pasting another function and the script for it which are working fine.
This function will close the outlook

;The function mentioned below will close the Microsoft outlook


Func _CloseOutlook()
    Local $sRemark
    If WinExists(" - Microsoft Outlook") Then       
       WinClose (" - Microsoft Outlook")            
        
        WinWait("Microsoft Outlook", "Do you want to save changes?", 5)
        WinActivate("Microsoft Outlook", "Do you want to save changes?")
        ControlClick("Microsoft Outlook", "&No", "Button2")
        Sleep(2000)
        ProcessClose("outlook.exe")
           
        If ProcessExists("outlook.exe") Then
            $sRemark = "FAIL"
            $sLogMsg = "Failed to close the Outlook."
            ConsoleWrite($sLogMsg & @CRLF)
            _LogMsg("ERROR", 2, $sLogMsg, True)
        Else
            $sRemark = "PASS"
            $sLogMsg = "Outlook has been closed."
            ConsoleWrite($sLogMsg & @CRLF)
            _LogMsg("INFO", 2, $sLogMsg, False)
        EndIf
    Else
        $sRemark = "PASS"
        $sLogMsg = "Outlook is already closed."
        _LogMsg("INFO", 2, $sLogMsg, False)
        ConsoleWrite($sLogMsg & @CRLF)
    EndIf
    Return $sRemark
EndFunc   


;script for the above function

$sRemark = _CloseOutlook()
    If $sRemark <> "PASS" Then
        $iTestNum += 1
        _PrintReport($iTestNum, $iTestPoint, $sRemark)
        Return "Error: " & $sRemark
    EndIf

    ;HTML Report Checkpoint
    $iTestNum += 1
    _PrintReport($iTestNum, $iTestPoint, $sRemark)
Link to comment
Share on other sites

Perhaps you can point out

; Below is the function 

Func _ConfirmBeforeSubmit()  

Local $sRemark 

Local $iWindow =  WinWait("Options")  

    If $iWindow == 0 Then
        $sRemark = "FAIL"
        $sLogMsg = "Unable to find the opened Option window "
        ConsoleWrite($sLogMsg & @CRLF)
        _LogMsg("ERROR", 2, $sLogMsg, True)
        Return $sRemark
     Else                   
    WinActivate("Options")      
    Local $iCheck = ControlCommand("Options", "", "[CLASS:Button; INSTANCE:13]", "IsChecked") 
    
    If $iCheck Then    
       $sRemark = "Is checked" 
       ControlClick("Options","",1)
       WinWait(" - Microsoft Outlook") 
         
       $sLogMsg = "Checkbox is checked already"     
        _LogMsg("INFO", 2, $sLogMsg, False)                     
     Return $sRemark           
    Else
       $sRemark = "Is not checked" 
       ControlClick("Options","",288)
       Sleep(3000)
      ControlClick("Options","",1)
       WinWait(" - Microsoft Outlook")
      
      $sLogMsg = "Confirm before submitting a report checkbox has been ENABLED"     
        _LogMsg("INFO", 2, $sLogMsg, False) 
    Return $sRemark     
     EndIf  
     EndIf
   
      EndFunc

#cs 
IMPORTANT NOTE:

From the above function you can see that we have 3 return types
1. "Is checked"
2. "Is not checked" 
3. “FAIL”

And now I just want to create a script in which the 3rd return type i.e. “FAIL” should only be called 

if and only if both return types i.e. "Is checked" and "Is not checked" do not match.

And if any single return type either "Is checked" or "Is not checked" is match then it execute the functionality for the same mentioned above in the function.

As you provide some code yesterday using switch statement, I used that but got the error unable to parse line “Is checked”.

Then I further R&D on the same and try to do it using select statement but did not succeed .Hence pasting the same code which I have written in the script.

#ce

;SCRIPT CODE:

$iTestPoint = "Verify to enable the checkbox for confirm before submitting a report "


Select
    Case $sRemark = "Is checked"
       
    _ConfirmBeforeSubmit()  ; 


    Case $sRemark = "Is not checked"

       _ConfirmBeforeSubmit()

    Case Else

      $iTestNum += 1
        _PrintReport($iTestNum, $iTestPoint, $sRemark)
        Return "Error: " & $sRemark

EndSelect

Perhaps you can point out where $iTestNum comes from in the all of your script you just posted.

Edited by JohnOne

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

  • Moderators

vis,

Last chance - include a runnable script which contains all your variables in your next post or the thread gets locked. :naughty:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

M23

Try to understand me ,I am not a allowed to provide the runnable script, i have provided the best i can.

And In the last reply by john he asked where $iTestNum comes from,  it has been declared and working well for all other script.well for that  i am providing the code again...

Func Main_checkBefore()
    
    Local $iTestPoint
    Local $iTestNum = 0
    Local $sRemark

$iTestPoint = "Verify to enable the checkbox for confirm before submitting a report "

local $sRemark = _CloseOutlook()
    If $sRemark <> "PASS" Then
        $iTestNum += 1
        _PrintReport($iTestNum, $iTestPoint, $sRemark)
        Return "Error: " & $sRemark
    EndIf

EndFunc

One more thing i just want to ask for my information,

One of my friend has told me that if i keep on asking the questions then you can block me so that i would not be able to ask any more questions in future. is it true?

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...