Jump to content

Problem with select typer


Recommended Posts

I have a script designed to make it easy to choose statements and transfer them to a word document.

2 probllems

1- How do you run a blank word Document from Autoit if you don't know the directory for word?

2- for some reason, my array thing is not writing all the selected components. heres script

#include <GUIConstants.au3>

Global $Line_[2001], $i, $Item_[2001], $line2_[2001], $k, $input, $nums_[1000], $word


$File =  FileOpen("Patient Statements.txt",1)
If $File= -1 Then
    Msgbox(0,"Error", "An error occurred with file.")
    Exit
EndIf
$FileClose1 = FileClose($File)



FileOpen("Patient Statements.txt",0)
$GuiWin = GUICreate("Statement Printer", 800, 800, -1, -1, $WS_SIZEBOX, $WS_EX_TOPMOST)
    GUISetBkColor(0xCCCCCC)
    $ListView = GUICtrlCreateListView("Number | Statements", 10, 110, 590, 590)
$input= GUICtrlCreateInput("Separate With Commas", 250, 710, 400, 35)
$button = GUICtrlCreateButton("Get Final Document", 605, 605, 150, 30)
$label1 = GUICtrlCreateLabel("Write the number of the statement(s) to inclue in the input below. When ready, push the ""Get Final Document"" button.", 10,10, 780, 100)
GuiSetState()
For $i = 1 to 1500
    $Line_[$i] = FileReadLine("Patient Statements.txt", $i)
    If $line_[$i] = "" Then ExitLoop
    $Item_[$i] = GUICtrlCreateListViewItem($i &"|"& $Line_[$i], $ListView) 
Next

While 1
    $msg = GUIGetMsg()
        If $msg = $GUI_EVENT_CLOSE Then Exitloop
        If $msg = $button then GetStringSpec()
WEnd

Func GetStringSpec()
    $nums = StringSplit($input, ",")
    For $k = 1 to $nums[0]
        $line2_[$k]=FileReadLine("Patient Statements.txt", $nums[$k])
        Type($line2_[$k])
    Next
EndFunc

Func Type($word)
    Run('Notepad.exe')
    WinWait("Untitled - Notepad")
    If WinExists("Untitled - Notepad") Then WinActivate("Untitled - Notepad")
    Send($word & "{ENTER}")
EndFunc

Note: the last function here uses notepad, but i want to use word, run it as is, and you will see that it doesn't write all the selected info

Note2: you Need to edit the document with random text that it creates called "Patient Statments" for me

It has several statements in it that you can choose from

Please Help

TY

Edited by Paulie
Link to comment
Share on other sites

#include <GUIConstants.au3>
Global $gFileNameStatements = "Patient Statements.txt"

Global $Line_[2001], $i, $Item_[2001], $line2_[2001], $k, $input, $nums_[1000], $word

If NOT FileExists("Patient Statements.txt") Then
    Msgbox(16,"Error", "Could not locate file: " & $gFileNameStatements & @CRLF & "NOTE: Creating dumy one")
    CreateDumyFile()
EndIf
CreateMyGui()
LoadFile()
While 1
    $msg = GUIGetMsg()
        If $msg = $GUI_EVENT_CLOSE Then Exitloop
        If $msg = $button then GetStringSpec()
WEnd
exit 
; Functions: ======================================================
Func CreateMyGui()
   ; NOT really good practice to define Globals inside function
   Global $GuiWin = GUICreate("Statement Printer", 600, 600, 10, 10, $WS_SIZEBOX, $WS_EX_TOPMOST) ;Topmost is realy annoying
       GUISetBkColor(0xCCCCCC)
   Global      $ListView = GUICtrlCreateListView("Number | Statements", 10, 110, 390, 390)
   Global $input= GUICtrlCreateInput("Separate With Commas", 250, 510, 400, 35)
   Global $button = GUICtrlCreateButton("Get Final Document", 405, 405, 150, 30)
   Global $label1 = GUICtrlCreateLabel("Write the number of the statement(s) to inclue in the input below. When ready, push the ""Get Final Document"" button.", 10,10, 780, 100)
   GuiSetState()
EndFunc 

Func CreateDumyFile()
   ;Create a dumy file
   FileWriteLine($gFileNameStatements, "This is a dumy statement")
   FileWriteLine($gFileNameStatements, "This is the second line")
   FileWriteLine($gFileNameStatements, "And at last the last one")
EndFunc  

Func LoadFile()
   Local $file = FileOpen($gFileNameStatements, 0)
   While 1
      $i += 1
       $Line_[$i] = FileReadLine($file, $i) ;Read with filehandel
       If @error <> 0 then exitloop 
       If $line_[$i] = "" Then ExitLoop
       $Item_[$i] = GUICtrlCreateListViewItem($i &"|"& $Line_[$i], $ListView)
   Wend 
   FileClose($file)
EndFunc 


Func GetStringSpec()
   ;Need to get the data in the text box
    $nums = StringSplit(GUICtrlRead( $input), ",")
    if $nums[0] > 0 then 
       Run('Notepad.exe')
       if not WinWait("Untitled - Notepad","", 5) Then  ; Use timeout
          MsgBox(16, "ERROR", "Could not load notepad.exe")
      Else 
         For $k = 1 to $nums[0]
            $line2_[$k]=FileReadLine($gFileNameStatements, $nums[$k])
            Type($line2_[$k])
         Next
      EndIf 
     Else
        MsgBox(16, "ERROR", "Must give spec")
      Endif 
EndFunc

Func Type($word)
    ;Running notepad for each call to this function? MOved to GetStringSpec
    If WinExists("Untitled - Notepad") Then WinActivate("Untitled - Notepad")
    ConsoleWrite("$word:=" & $word & @LF)
    Send($word & "{ENTER}")
EndFunc

Link to comment
Share on other sites

Thanks Uten That was Perfect!!!

Now all i need is a way to open word as opposed to notepad

I tried doing this, but i got error

Run('WINWord.exe')

Running it with the directory location worked,

Run(@DesktopDir &"\Office\WinWord.exe")

but is there a way to do it if you don't know the directory?

Edited by Paulie
Link to comment
Share on other sites

I don't have word (MS Office?) installed. But it's location is probably stored in the registry. So the best way is to figure out where (or take a look at your start->...->msword link) and let the script read from there. You can also use process explorer from sysinternals to see where it is loaded from.

Link to comment
Share on other sites

I don't have word (MS Office?) installed. But it's location is probably stored in the registry. So the best way is to figure out where (or take a look at your start->...->msword link) and let the script read from there. You can also use process explorer from sysinternals to see where it is loaded from.

The only problem, is that this is going to be run on my family members comp, not mine, and i don't know where they install their programs. Are you sure you can't find its location and run it from within Autoit?
Link to comment
Share on other sites

Hi

$s_WordPath=RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\8.0\Word\InstallRoot","Path")
MsgBox(0,"","$s_WordPath="&$s_WordPath)
But do you know the version?

You can test for 8.0 entry, 9.0 entry, etc!

Best, randall

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...