Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: Runlines from Autoit fo Stata 9.2 MP


From   "Richard Palmer-Jones" <[email protected]>
To   [email protected]
Subject   Re: st: Runlines from Autoit fo Stata 9.2 MP
Date   Mon, 18 Sep 2006 13:24:41 +0100

Dimitri

Here it is between the stars below. I refere to "wmpstata.exe" adn to
"Stata/MP 9.2" which is I think how both are to be addressed. I wonder
if there is some change to the "FileWrite($tempfile2,$commands &
@CRLF)" or to the "Sleep" commands, byt fiddling with the time  in
Sleep() has not dealt withthe problem.

I am compiling with aut2exe 3.1.1 and running from textpad 4.7.3  if
that is any help.

Thanks for your attention

Richard

**************************************************************************
; AutoIt v3 script to run Stata commands from an external text editor.
; Version 2.1.2, Friedrich Huebler (fhuebler at gmail.com), 26 September 2005.
; Updated by Nicholas Winter (nw53 at cornell.edu), 25 May 2005.
; Adapted from a script by Eva Poen (eva.poen at unisg.ch), 27 June 2004.
; AutoIt is available at http://www.autoitscript.com/autoit3/.
; The latest version of this script is at
; http://huebler.info/2005/20050310_Stata_editor.html.

; Declare variables
Global $statapath, $statawin, $commands, $tempfile, $tempfile2

; NOTE: Edit $statapath and $statawin before script is compiled
; Path to Stata executable
$statapath = "C:\Program Files\Stata9\wmpstata.exe"
; Title of Stata window
$statawin = "Stata/MP 9.2"

; If more than one Stata window is open, the window
; that was most recently active will be matched
Opt("WinTitleMatchMode",2)

; Reduce SendKeyDelay and WinWaitDelay to speed up script
Opt("SendKeyDelay", 1)
Opt("WinWaitDelay", 200)

; Clear clipboard
ClipPut("")
; Copy selected lines from editor to clipboard
Send("^c")
; Pause avoids problem with clipboard, may be AutoIt or Windows bug
Sleep(100)
$commands = ClipGet()

; Terminate script if nothing selected
If $commands = "" Then
 Exit
EndIf

; Create file name in system temporary directory
$tempfile = EnvGet("TEMP") & "\statacmd.tmp"

; Open file for writing and check that it worked
$tempfile2 = FileOpen($tempfile,2)
If $tempfile2 = -1 Then
 MsgBox(0,"Error: Cannot open temporary file","at [" & $tempfile & "]")
 Exit
EndIf

; Write commands to temporary file, add CR-LF at end
; to ensure last line is executed by Stata
FileWrite($tempfile2,$commands & @CRLF)
FileClose($tempfile2)

; Check if Stata is already open, run it if not
If WinExists($statawin) Then
 WinActivate($statawin)
 WinWaitActive($statawin)
 ; Activate Stata Command Window and select text (if any)
 Send("^4")
 Send("^a")
 ; Run temporary file
 ; Double quotes around $tempfile needed in case path contains blanks
 ClipPut("do " & '"' & $tempfile & '"')
 ; Pause avoids problem with clipboard, may be AutoIt or Windows bug
 Sleep(100)
 Send("^v" & "{Enter}")
Else
 Run($statapath)
 WinWaitActive($statawin)
 ; Activate Stata Command Window
 Send("^4")
 ; Run temporary file
 ; Double quotes around $dofile needed in case path contains blanks
 ClipPut("do " & '"' & $tempfile & '"')
 ; Pause avoids problem with clipboard, may be AutoIt or Windows bug
 Sleep(100)
 Send("^v" & "{Enter}")
EndIf

**************************************************************************

On 9/18/06, Dimitriy V. Masterov <[email protected]> wrote:
Perhaps this is obvious, but have you already changed all the
references to SE to refer to MP instead in the script? I've had
problems myself with getting $statawin = "Stata/SE 9.2" to reflect
exactly what's written at the top of the  Stata window since I tend to
be clueless about crucial details like that. If this is not your
problem, post the AutoIt script, and maybe I can figure it out later
today.

DVM
*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index