Jump to content
idontknow989

Ending a copy and paste loop

Recommended Posts

idontknow989

I have a simple script that copies a list of patients in an Allscripts PM database and pastes them into an Excel file. I am having trouble figuring out how to stop the script after it gets to the last person. If anyone could help me with this it would be greatly appreciated.

While 1
    WinActivate("Allscripts PM")
    WinWaitActive("Allscripts PM")
    Send("^c")
    Sleep(100)
    Send("{DOWN}")

    WinActivate("Microsoft Excel - Book1")
    WinWaitActive("Microsoft Excel - Book1")
    Send("^v")
    Sleep(100)
    Send("{DOWN}")
 WEnd

Share this post


Link to post
Share on other sites
Earthshine

you should read in all the names to an array, then traverse the array. you could also query the database and check for recordcount, then loop until EOR

Also there is an Excel UDF that Water wrote (I think) that is super nice and super easy.

But hey, would you try this and see if it works?

try a Control A to select all then just past to excel as you do. you may not have to loop

WinActivate("Allscripts PM")
    WinWaitActive("Allscripts PM")
    Send("^a")    
    Send("^c")
    Sleep(100)
    Send("{DOWN}")

    WinActivate("Microsoft Excel - Book1")
    WinWaitActive("Microsoft Excel - Book1")
    Send("^v")
    Sleep(100)
    Send("{DOWN}")

 

Edited by Earthshine

My resources are limited. You must ask the right questions

 

Share this post


Link to post
Share on other sites
idontknow989

In Allscripts only one patient can be selected at a time, which is why I made the loop to go back and forth between Allscripts and Excel. I am not able to read the list of patients any other way besides loading them up inside of Allscripts.

Share this post


Link to post
Share on other sites
JLogan3o13

@idontknow989 just a couple of questions for clarification. You activate the window, copy the patient name, then hit the down button to move to the next. So:

  • When you reach the last patient record, copy it and then hit down, what is the behavior? Does it just stay on that same line in the app?
  • Are the patient names full names, first names only, etc.? Are they unique enough that you could compare the last string placed on the clipboard and be reasonably sure of the outcome? For example:
Notepad with first names:

Jim
John
James
Joey
Diana
Diana   ....Should fail here
Jim
John
James
Joey
Diana
ClipPut('') ;Clear the Clipboard

Local $sName = ""
Local $x = 1

    While 1
        WinActivate("Untitled - Notepad")
        Sleep(500)
        Send("+{END}") ;Shift end to capture whole line
        Send("^c") ;Copy
        Send("{DOWN}{HOME}") ;Down arrow then Home button to the beginning of the next line
        
        If $sName == ClipGet() Then ;If what was just captured is Case-sensitive equal to what is on the clipboard
            ConsoleWrite(ClipGet() & " already in the clipboard" & @CRLF)
            ExitLoop
        Else
            $sName = ClipGet()
            ConsoleWrite("Turn " & $x & ": " & $sName & @CRLF)
        EndIf
        $x += 1
    WEnd

   You would have to modify this a bit to fit your needs, but it should give you an idea of a way to go about it. If the application's behavior is different when you reach the last line, please explain in greater detail. If possible, a screenshot would be helpful.

Edited by JLogan3o13
  • Like 1

√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites
Earthshine

Sorry then. 

Edited by Earthshine

My resources are limited. You must ask the right questions

 

Share this post


Link to post
Share on other sites
idontknow989

@JLogan3o13 When the script gets to the last person it will stay on that person and copy and paste them over and over. The patients are unique enough since it includes names, addresses, payment, etc.; I will give your script a try and see if it works.

 

Share this post


Link to post
Share on other sites
idontknow989

Thank you JLogan3o13 that ended up working.

  • Like 1

Share this post


Link to post
Share on other sites
JLogan3o13

Glad it worked out for you. If in the future you want to get away from the Send commands (which are notoriously unreliable) we can assist with that as well. 


√-1 2^3 ∑ π, and it was delicious!

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

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.