Jump to content

Changing application to write to Notepad.


Recommended Posts

Could anyone please tell me how I get this application to write its information out to a notepad file? Thank you in advance.
I had tried changing the code to reference "Untitled - Notepad" instead of the Product 2009 and I would think the send commands and references to buttons and specific pages would need to be removed also.

For example I would like to set the $amount to say 100 and then have it write 000-00-0001, 000-00-0002 etc etc until the end of the count into the notepad file.

 

#include <GUIConstants.au3>
#include <IE.au3>

$me = GUICreate("Desktop Generator", 450, 200)
GUISetBkColor(0xFFFFFF) ; background color

$textbox1 = GUICtrlCreateEdit("", 10, 90, 430, 100)
$Pic1 = GUICtrlCreatePic("image.jpg", 300, 1, 141, 42)
$Labelnumberstart = GUICtrlCreateLabel("number Start", 10, 1, 60, 20)
$Estart = GUICtrlCreateInput("000-00-", 75, 1, 45, 20)
$Eend = (GUICtrlCreateInput("0000", 125, 1, 40, 20))
$LabelAnount = GUICtrlCreateLabel("# ", 10, 25, 60, 20)
$amount = GUICtrlCreateInput("000", 75, 25, 30, 20)
$newReturn = GUICtrlCreateButton("Create ", 10, 47, 151, 20)
$helpButton = GUICtrlCreateButton("Help", 10, 67, 151, 20)




fRunGui()
Func fRunGui()
    GUISetState()
    While 1
        $msg = GUIGetMsg()
        Select
            Case $msg = $GUI_EVENT_CLOSE ; closes when red x is pressed
                ExitLoop



            Case $msg = $newReturn
                GUICtrlSetData($textbox1, "");deletes the text
                openRetrun()

            Case Else
                ;;;
        EndSelect

    WEnd
EndFunc   ;==>fRunGui



Func openRetrun()
    $iCount = 0

    For $count = 0 To GUICtrlRead($amount) - 1 Step 1
        $numberEnd = GUICtrlRead($Eend) + $count

        While StringLen($numberEnd) < 4

            $numberEnd = "0" & $numberEnd

        WEnd

        $number = GUICtrlRead($Estart) & $numberEnd


        fThrowError(@ScriptLineNumber, WinActivate("product 2009 :", ""))
        Send("^n")
        fThrowError(@ScriptLineNumber, WinWaitActive("Enter number", "", 10))
        fThrowError(@ScriptLineNumber, ControlSetText("Enter number", "", "TMaskEdit3", $number))
        fThrowError(@ScriptLineNumber, ControlSetText("Enter number", "", "TMaskEdit1", $number))

        Send("{TAB}")
        If (WinExists("Confirm", "&Yes")) Then
            fThrowError(@ScriptLineNumber, WinActivate("Confirm", "&Yes"))
            fThrowError(@ScriptLineNumber, ControlClick("Confirm", "", "TButton1", "left", 1))
            fThrowError(@ScriptLineNumber, WinWaitActive("Enter number", "", 10))
            fThrowError(@ScriptLineNumber, ControlClick("Enter number", "", "TButton3", "left", 1))
            GUICtrlSetData($textbox1, "- - - - The return " & $number & " already exists" & @CRLF, 1)
        Else
            fThrowError(@ScriptLineNumber, ControlClick("Enter number", "", "TButton4", "left", 1))

            fThrowError(@ScriptLineNumber, WinWaitActive("product 2009 :", "pnlNavigation", 10))
            Send("!f")
            Send("c")
            fThrowError(@ScriptLineNumber, WinWaitActive("product 2009 :", "homepage.htm", 10))
            GUICtrlSetData($textbox1, "- - - - The return " & $number & " Created" & @CRLF, 1)
            $iCount = $iCount + 1
        EndIf
    Next; end of for statement
    GUICtrlSetData($textbox1, "A total of " & $iCount & " returns were created" & @CRLF, 1)
EndFunc   ;==>openRetrun


Func fThrowError($sMessage, $iZero)
    If ($iZero = 0) Then

        MsgBox(1, "Error", "Please restart tool" & $sMessage)
        fRunGui()
        Exit
    EndIf
EndFunc   ;==>fThrowError


Exit
Edited by jbsoccerbrit
Link to comment
Share on other sites

  • Moderators

You are correct, if you want to change where it writes to, you will need to activate the notepad window instead of the "Product 2009" window, and change all the references used to write to that window to write to Notepad instead. Have you attempted to do this already?

"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

I've tried changing it to the below, it sets the focus on the Notepad application but nothing is ever written to it and then it just displays the error message at the end of the code.

 

#include <GUIConstants.au3>
#include <IE.au3>

$me = GUICreate("Desktop Generator", 450, 200)
GUISetBkColor(0xFFFFFF) ; background color

$textbox1 = GUICtrlCreateEdit("", 10, 90, 430, 100)
$Pic1 = GUICtrlCreatePic("image.jpg", 300, 1, 141, 42)
$Labelnumberstart = GUICtrlCreateLabel("number Start", 10, 1, 60, 20)
$Estart = GUICtrlCreateInput("000-00-", 75, 1, 45, 20)
$Eend = (GUICtrlCreateInput("0000", 125, 1, 40, 20))
$LabelAnount = GUICtrlCreateLabel("# ", 10, 25, 60, 20)
$amount = GUICtrlCreateInput("000", 75, 25, 30, 20)
$newReturn = GUICtrlCreateButton("Create ", 10, 47, 151, 20)
$helpButton = GUICtrlCreateButton("Help", 10, 67, 151, 20)




fRunGui()
Func fRunGui()
    GUISetState()
    While 1
        $msg = GUIGetMsg()
        Select
            Case $msg = $GUI_EVENT_CLOSE ; closes when red x is pressed
                ExitLoop



            Case $msg = $newReturn
                GUICtrlSetData($textbox1, "");deletes the text
                openRetrun()

            Case Else
                ;;;
        EndSelect

    WEnd
EndFunc   ;==>fRunGui



Func openRetrun()
    $iCount = 0

    For $count = 0 To GUICtrlRead($amount) - 1 Step 1
        $numberEnd = GUICtrlRead($Eend) + $count

        While StringLen($numberEnd) < 4

            $numberEnd = "0" & $numberEnd

        WEnd

        $number = GUICtrlRead($Estart) & $numberEnd


        fThrowError(@ScriptLineNumber, WinActivate("Untitled - Notepad", ""))
        fThrowError(@ScriptLineNumber, WinWaitActive("Enter number", "", 10))
        fThrowError(@ScriptLineNumber, ControlSetText("Enter number", "", "TMaskEdit3", $number))
        fThrowError(@ScriptLineNumber, ControlSetText("Enter number", "", "TMaskEdit1", $number))


        If (WinExists("Confirm", "&Yes")) Then
            fThrowError(@ScriptLineNumber, WinActivate("Confirm", "&Yes"))
            fThrowError(@ScriptLineNumber, WinWaitActive("Enter number", "", 10))
            GUICtrlSetData($textbox1, "- - - - The return " & $number & " already exists" & @CRLF, 1)
        Else

            fThrowError(@ScriptLineNumber, WinWaitActive("Untitled - Notepad", "", 10))
            Send("!f")
            Send("c")
            fThrowError(@ScriptLineNumber, WinWaitActive("Untitled - Notepad", "", 10))
            GUICtrlSetData($textbox1, "- - - - The return " & $number & " Created" & @CRLF, 1)
            $iCount = $iCount + 1
        EndIf
    Next; end of for statement
    GUICtrlSetData($textbox1, "A total of " & $iCount & " returns were created" & @CRLF, 1)
EndFunc   ;==>openRetrun


Func fThrowError($sMessage, $iZero)
    If ($iZero = 0) Then

        MsgBox(1, "Error", "Please restart tool" & $sMessage)
        fRunGui()
        Exit
    EndIf
EndFunc   ;==>fThrowError


Exit
Link to comment
Share on other sites

Not really. Didn't work did it?

For FileWriteLine you will need to OPEN & CLOSE a text file. Get the example and play with it, it is pretty straightforward.

I am still mulling through your script and trying to make some sense of it.

Why does your loop include the fthrowerror function?

Link to comment
Share on other sites

Hi again,

  I cant figure what its supposed to be doing so I changed it around a bit to test.

Have a look. It is counting and writing to your GUI and to the text file.

Maybe you can change it around to do what you want now. :)

#include <GUIConstants.au3>
#include <IE.au3>
#include <File.au3>

Local $file = FileOpen("test.txt", 2) ;file to write to

$me = GUICreate("Desktop Generator", 450, 200)
GUISetBkColor(0xFFFFFF) ; background color

$textbox1 = GUICtrlCreateEdit("", 10, 90, 430, 100)
$Pic1 = GUICtrlCreatePic("image.jpg", 300, 1, 141, 42)
$Labelnumberstart = GUICtrlCreateLabel("number Start", 10, 1, 60, 20)
$Estart = GUICtrlCreateInput("000-00-", 75, 1, 45, 20)
$Eend = (GUICtrlCreateInput("0000", 125, 1, 40, 20))
$LabelAnount = GUICtrlCreateLabel("# ", 10, 25, 60, 20)
$amount = GUICtrlCreateInput("000", 75, 25, 30, 20)
$newReturn = GUICtrlCreateButton("Create ", 10, 47, 151, 20)
$helpButton = GUICtrlCreateButton("Help", 10, 67, 151, 20)

fRunGui()
Func fRunGui()
    GUISetState()
    While 1
        $msg = GUIGetMsg()
        Select
            Case $msg = $GUI_EVENT_CLOSE ; closes when red x is pressed
                ExitLoop
            Case $msg = $newReturn
                GUICtrlSetData($textbox1, "");deletes the text
                openRetrun()
            Case Else
        EndSelect
    WEnd
EndFunc   ;==>fRunGui

Func openRetrun()
    ;$iCount = 0
    For $count = 0 To GUICtrlRead($amount) - 1 Step 1
        FileWriteLine($file, $count & @ScriptLineNumber & "Some Other Stuff")  ;;;---------------------
        ;$numberEnd = GUICtrlRead($Eend) + $count
        ;While StringLen($numberEnd) < 4
        ;$numberEnd = "0" & $numberEnd
        ;WEnd
        ;$number = GUICtrlRead($Estart) & $numberEnd

;~         fThrowError(@ScriptLineNumber, WinActivate("product 2009 :", ""))
;~         Send("^n")
;~         fThrowError(@ScriptLineNumber, WinWaitActive("Enter number", "", 10))
;~         fThrowError(@ScriptLineNumber, ControlSetText("Enter number", "", "TMaskEdit3", $number))
;~         fThrowError(@ScriptLineNumber, ControlSetText("Enter number", "", "TMaskEdit1", $number))

;~         Send("{TAB}")
;~         If (WinExists("Confirm", "&Yes")) Then
;~             fThrowError(@ScriptLineNumber, WinActivate("Confirm", "&Yes"))
;~             fThrowError(@ScriptLineNumber, ControlClick("Confirm", "", "TButton1", "left", 1))
;~             fThrowError(@ScriptLineNumber, WinWaitActive("Enter number", "", 10))
;~             fThrowError(@ScriptLineNumber, ControlClick("Enter number", "", "TButton3", "left", 1))
;~             GUICtrlSetData($textbox1, "- - - - The return " & $number & " already exists" & @CRLF, 1)
;~         Else
;~             fThrowError(@ScriptLineNumber, ControlClick("Enter number", "", "TButton4", "left", 1))

;~             fThrowError(@ScriptLineNumber, WinWaitActive("product 2009 :", "pnlNavigation", 10))
;~             Send("!f")
;~             Send("c")
;~             fThrowError(@ScriptLineNumber, WinWaitActive("product 2009 :", "homepage.htm", 10))
;~             GUICtrlSetData($textbox1, "- - - - The return " & $number & " Created" & @CRLF, 1)
;~             $iCount = $iCount + 1
;~         EndIf
   ;Next; end of for statement
    GUICtrlSetData($textbox1, "A total of " & $amount & " returns were created" & @CRLF, 1)
        Next
FileClose($file)
EndFunc   ;==>openRetrun


Func fThrowError($sMessage, $iZero)
    If ($iZero = 0) Then

        MsgBox(1, "Error", "Please restart tool" & $sMessage)
        fRunGui()
        Exit
    EndIf
EndFunc   ;==>fThrowError


Exit

Good luck!

Bill

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