Jump to content
Sign in to follow this  
jbsoccerbrit

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

Share this post


Link to post
Share on other sites

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!

Share this post


Link to post
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

Share this post


Link to post
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?

Share this post


Link to post
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

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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By kingjacob90
      Hi
      So I am trying to click the green button, this button is not always in the same place. So fare I am trying to click it by finding the color but there is also something else with the same color on the screen (circled in yellow) that is causing issues. Is there a way to use the Title and Class of the window (can't be just the window as there are more than one with the same name).
      How does AutoIt Info get this information?

    • By AZJIO
      My Notepad v0.4 (En, Ru)

      Black theme

       
      My_Notepad.7z (560kb sources + EXE)
       
      I wanted to make an example for the help file. But I could not stop, and made more complicated.
    • By adjist
      Hello all! 
       
      Getting this error :
      (22) : ==> Variable used without being declared.: if $vNumber = 0 Then if ^ ERROR  
      But I'm sure I have defined the variable, as in the top of my script has 
      Global $vNumber = 0  
      How would I go about fixing this?
       
    • By MarkIT
      Hi AutoIT masters,
      Good day! Sorry to have bothered this forum but we really need help. We are working on an automation project that is running on VDI server. The BOTS are in .exe are running fine until AV detected them and deleted the files. The files were re-compiled and AV kept on deleting them. The copy of the .exe BOT deleted were sent to Symantec for whitelisting. After whitelisting, it is no longer deleted but no longer working as designed (showing Line script error). We checked the scripts and there were no issues since we run it using SciTE editor and it performed the desired task. Good thing we found on this thread the solution using .a3x and the BOTS worked fine and no longer deleted. Now, the problem is they are asking why the BOTS won't run in .EXE and what is the reason behind Symantec AV deleting them. We raised a case with Symantec but they cannot provide further information as they are always seeing the file as "False Positive". We even tested with Symantec turned off and those .EXE files are working fine, however, after re-enabling, it got deleted.
      Just seeking help on how to better convince them that it is really Symantec causing the issue and the .a3x file.
    • By AutoitMike
      Scite 3.4.4
      Win 10
      I click "Help" or press F1, there is no response
      If I use the file explorer and double click Autoit.chm or Autoit3.chm help opens.
      There is no dialog to check or uncheck "Always ask before opening this file" when clicking on these files.
       
      If you are curious as to why I dont have the latest version, I am creating a back up laptop that has a VERY extensive automation application that I have written over the past 15 years.
       
      An extremely potent, powerful, needed function has been deleted in the upgrade of Autoit in recent years that I can not do without. If my main laptop dies, which it almost did, I am in a very bad position. So I bought the exact same laptop and I am "cofiguring" it to work exactly the same as my main laptop. However, this one has been "Upgraded" to Win 10 which I hope is not the problem. 
      Thanks for any help
×
×
  • Create New...