Jump to content

If conditions not working


Masum
 Share

Recommended Posts

Hi all,

I'm going crazy while I try and work out why a fairly simply if condition isn't working. I will try and explain it clearly, in the hope someone can find out the cause. The portion of the script for these if conditions is copied in below. The first PixelGetColor func is denoted in Screenshot 1, the RED dot signifies where the color is extracted from. The second PixelGetColor func is denoted in Screenshot 2, the YELLOW dot signifies where the color is extracted from. The script is tested for 3 scenarios, where 1. no resource is found (Screenshot 1), 2. multiple resources are found (Screenshot 2), and 3. only 1 resource is found (Screenshot 3). This application is being run via RDP hence I can't access the controls, and therefore relying on the pixel colours. The issue is, for all three scenarios, only the first If condition's first result is shown, even though the actual program shows the 3 screenshots for each of the three scenarios. Any ideas where I'm going wrong?

If PixelGetColor(697, 446, 0xF0F0F0) Then ;If resource is not found, cancel out
        Sleep(200)
        MsgBox(64, 'Error', 'Resource is not found, therefore this pool will not be saved and will cancel out. Click OK to continue.')
        _Excel_RangeWrite($oWorkbook, 'CHFT Pools & RTE Rules', 'Fail', 'I' & $ColumnIRow)
        _Excel_RangeWrite($oWorkbook, 'CHFT Pools & RTE Rules', 'Resource not found. ' & $Notes, 'J' & $ColumnIRow)
        Sleep(500)
        WinActivate('Scheduling Help')
        Sleep(500)
        Send('{ENTER}') ;Click OK
        Sleep(500)
        Send('{SHIFTDOWN}{TAB}{SHIFTUP}{ENTER}') ;Click Cancel
        Sleep(500)
        Send('{SHIFTDOWN}{TAB}{TAB}{TAB}{TAB}{SHIFTUP}{ENTER}') ;Click Close
        Sleep(500)
        WinActivate('Scheduling: DB Flex Rule Tool - Inbox Pool Routing')
        Sleep(500)
        Send('{TAB}{ENTER}') ;Click Yes
        Sleep(500)
        WinActivate('Rules for Pool')
        Sleep(500)
        Send('{TAB}{TAB}{TAB}{ENTER}') ;Click Cancel
        Sleep(500)
        MouseClick('Primary', 1259, 653, 1) ;Click Cancel
    Else
        Send('{TAB}{TAB}{DOWN}') ;Find resource
        If PixelGetColor(725, 383, 0x3399FF) Then ;If there are multiple resources, cancel out
            Sleep(200)
            MsgBox(64, 'Error', 'There are multiple resources, therefore this pool will not be saved and will cancel out. Click OK to continue.')
            _Excel_RangeWrite($oWorkbook, 'CHFT Pools & RTE Rules', 'Redo', 'I' & $ColumnIRow)
            _Excel_RangeWrite($oWorkbook, 'CHFT Pools & RTE Rules', 'Multiple resources. ' & $Notes, 'J' & $ColumnIRow)
            Sleep(500)
            WinActivate('Scheduling Help')
            Sleep(500)
            Send('{TAB}{TAB}{ENTER}') ;Click Cancel
            Sleep(500)
            Send('{SHIFTDOWN}{TAB}{TAB}{TAB}{TAB}{SHIFTUP}{ENTER}') ;Click Close
            Sleep(500)
            WinActivate('Scheduling: DB Flex Rule Tool - Inbox Pool Routing')
            Sleep(500)
            Send('{TAB}{ENTER}') ;Click Yes
            Sleep(500)
            WinActivate('Rules for Pool')
            Sleep(500)
            Send('{TAB}{TAB}{TAB}{ENTER}') ;Click Cancel
            Sleep(500)
            MouseClick('Primary', 1259, 653, 1) ;Click Cancel
        Else ;Select the resource
            Send('{ENTER}') ;Select Order Physician
            MsgBox(0, '', 'save button clicks now')
            _Excel_RangeWrite($oWorkbook, 'CHFT Pools & RTE Rules', 'Complete', 'I' & $ColumnIRow)
            _Excel_RangeWrite($oWorkbook, 'CHFT Pools & RTE Rules', 'Success. ' & $Notes, 'J' & $ColumnIRow)
            ;Send('{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{ENTER}') ;Click Save
        EndIf
    EndIf

Screenshots.png

Link to comment
Share on other sites

When you try to post something, did you see a toolbar on the top of the text box you typing ?. On that toolbar, there is an icon named "Code" with "<>" sign. Click on it and post your code in it. 

Spoiler

My Contributions

Glance GUI Library - A gui library based on Windows api functions. Written in Nim programming language.

UDF Link Viewer   --- A tool to visit the links of some most important UDFs 

 Includer_2  ----- A tool to type the #include statement automatically 

 Digits To Date  ----- date from 3 integer values

PrintList ----- prints arrays into console for testing.

 Alert  ------ An alternative for MsgBox 

 MousePosition ------- A simple tooltip display of mouse position

GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function

Access_UDF  -------- An UDF for working with access database files. (.*accdb only)

 

Link to comment
Share on other sites

Apologies

If PixelGetColor(697, 446, 0xF0F0F0) Then ;If resource is not found, cancel out
        Sleep(200)
        MsgBox(64, 'Error', 'Resource is not found, therefore this pool will not be saved and will cancel out. Click OK to continue.')
        _Excel_RangeWrite($oWorkbook, 'CHFT Pools & RTE Rules', 'Fail', 'I' & $ColumnIRow)
        _Excel_RangeWrite($oWorkbook, 'CHFT Pools & RTE Rules', 'Resource not found. ' & $Notes, 'J' & $ColumnIRow)
        Sleep(500)
        WinActivate('Scheduling Help')
        Sleep(500)
        Send('{ENTER}') ;Click OK
        Sleep(500)
        Send('{SHIFTDOWN}{TAB}{SHIFTUP}{ENTER}') ;Click Cancel
        Sleep(500)
        Send('{SHIFTDOWN}{TAB}{TAB}{TAB}{TAB}{SHIFTUP}{ENTER}') ;Click Close
        Sleep(500)
        WinActivate('Scheduling: DB Flex Rule Tool - Inbox Pool Routing')
        Sleep(500)
        Send('{TAB}{ENTER}') ;Click Yes
        Sleep(500)
        WinActivate('Rules for Pool')
        Sleep(500)
        Send('{TAB}{TAB}{TAB}{ENTER}') ;Click Cancel
        Sleep(500)
        MouseClick('Primary', 1259, 653, 1) ;Click Cancel
    Else
        Send('{TAB}{TAB}{DOWN}') ;Find resource
        If PixelGetColor(725, 383, 0x3399FF) Then ;If there are multiple resources, cancel out
            Sleep(200)
            MsgBox(64, 'Error', 'There are multiple resources, therefore this pool will not be saved and will cancel out. Click OK to continue.')
            _Excel_RangeWrite($oWorkbook, 'CHFT Pools & RTE Rules', 'Redo', 'I' & $ColumnIRow)
            _Excel_RangeWrite($oWorkbook, 'CHFT Pools & RTE Rules', 'Multiple resources. ' & $Notes, 'J' & $ColumnIRow)
            Sleep(500)
            WinActivate('Scheduling Help')
            Sleep(500)
            Send('{TAB}{TAB}{ENTER}') ;Click Cancel
            Sleep(500)
            Send('{SHIFTDOWN}{TAB}{TAB}{TAB}{TAB}{SHIFTUP}{ENTER}') ;Click Close
            Sleep(500)
            WinActivate('Scheduling: DB Flex Rule Tool - Inbox Pool Routing')
            Sleep(500)
            Send('{TAB}{ENTER}') ;Click Yes
            Sleep(500)
            WinActivate('Rules for Pool')
            Sleep(500)
            Send('{TAB}{TAB}{TAB}{ENTER}') ;Click Cancel
            Sleep(500)
            MouseClick('Primary', 1259, 653, 1) ;Click Cancel
        Else ;Select the resource
            Send('{ENTER}') ;Select Order Physician
            MsgBox(0, '', 'save button clicks now')
            _Excel_RangeWrite($oWorkbook, 'CHFT Pools & RTE Rules', 'Complete', 'I' & $ColumnIRow)
            _Excel_RangeWrite($oWorkbook, 'CHFT Pools & RTE Rules', 'Success. ' & $Notes, 'J' & $ColumnIRow)
            ;Send('{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{ENTER}') ;Click Save
        EndIf
    EndIf

 

Link to comment
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
 Share

×
×
  • Create New...