Jump to content

Ending a copy and paste loop


Recommended Posts

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

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

  • Moderators

@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

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

  • Moderators

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. 

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

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

  • Recently Browsing   0 members

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