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 red0fireus
      #NoTrayIcon #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Res_Description=Rainmeter Suspend #AutoIt3Wrapper_Res_Fileversion=0.0.0.1 #AutoIt3Wrapper_Res_Fileversion_AutoIncrement=y #AutoIt3Wrapper_Res_ProductName=Rainmeter Suspend #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <WinAPI.au3> #include <WindowsConstants.au3> Opt("TrayAutoPause",0) while 1 sleep(5000) _IsFullScreen() WEnd Func _IsFullScreen () Local $hwnd = WinGetHandle ("[ACTIVE]") Local $aWinRect = WinGetPos ($hwnd) If ($aWinRect[2] >= _WinAPI_GetSystemMetrics($SM_CXSCREEN)) OR ($aWinRect[3] >= _WinAPI_GetSystemMetrics($SM_CYSCREEN)) Then _ProcessSuspend("rainmeter.exe") Else _ProcessResume("rainmeter.exe") EndIf EndFunc Func _ProcessSuspend($process) $processid = ProcessExists($process) If $processid Then $ai_Handle = DllCall("kernel32.dll", 'int', 'OpenProcess', 'int', 0x1f0fff, 'int', False, 'int', $processid) $i_sucess = DllCall("ntdll.dll","int","NtSuspendProcess","int",$ai_Handle[0]) DllCall('kernel32.dll', 'ptr', 'CloseHandle', 'ptr', $ai_Handle) If IsArray($i_sucess) Then Return 1 Else SetError(1) Return 0 Endif Else SetError(2) Return 0 Endif EndFunc Func _ProcessResume($process) $processid = ProcessExists($process) If $processid Then $ai_Handle = DllCall("kernel32.dll", 'int', 'OpenProcess', 'int', 0x1f0fff, 'int', False, 'int', $processid) $i_sucess = DllCall("ntdll.dll","int","NtResumeProcess","int",$ai_Handle[0]) DllCall('kernel32.dll', 'ptr', 'CloseHandle', 'ptr', $ai_Handle) If IsArray($i_sucess) Then Return 1 Else SetError(1) Return 0 Endif Else SetError(2) Return 0 Endif EndFunc  
      I'm getting this error when running my script: "Error: Subscript used on non-accessible variable" 
      I'm very confused because the script works 99% of the time and then I just get the random error. What am I missing?
    • By Langmeister
      Hi, I'm sure that this is a simple question regarding webdriver udf but my search on the forum did not result in the exact same scenario that I need. I will adapt it to my corporate needs but at first I want it to work with an example everybody can reproduce if needed.
      I navigate to https://www.daysoftheyear.com/ and want to find out what special day today is. Using the following Code returns the wanted text that today is 'shark awareness day' in the console but it is not pasted in notepad as it is not copied as it probably should be.
      #include "wd_core.au3" #include "wd_helper.au3" Local $sDesiredCapabilities, $sSession, $sID _WD_Option("Driver", "C:\Program Files (x86)\AutoIt3\chromedriver.exe") _WD_Option('Port', 9515) _WD_Option('DriverParams', '--log-path="' & @ScriptDir & '\chrome.log"') $sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"w3c": true }}}}' _WD_Startup() $sSession = _WD_CreateSession($sDesiredCapabilities) _WD_Navigate($sSession, "https://www.daysoftheyear.com/?timezone_offset=nan") _WD_LoadWait($sSession) Sleep(3000) Local $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "/html/body/div[2]/header/div/div[1]/div/div[2]/h3/a") _WD_ElementAction($sSession, $sElement, 'text') ClipGet() Run("notepad.exe") Sleep(500) Send("^v") Scite returns this, therefore the text has been found but the last mile to paste it to notepad or excel does not work for me.
      __WD_Get: URL=HTTP://127.0.0.1:9515/session/b72166b774d7fefb258b3721fc1d4306/element/657e6b5d-31a9-46a8-85c4-acb7f72bf659/text __WD_Get: StatusCode=200; $iResult = 0; $sResponseText={"value":"Shark Awareness Day"}... _WD_ElementAction: {"value":"Shark Awareness Day"}... Thanks in advance! 
       
    • By Jamestay97
      Hello! Thanks you for looking at my post
      **No source code I'm sorry work related can't copy information**
      I've been using autoit for about 1 year. 
      I'm having trouble automating a click on an internet explorer web page and I've tried a lot of examples from help pages and forums already. The object I'm trying to click on isnt always in the same spot so I can't use mouse click or control click, I have tried to use the different get collection options and clickbyname, or index or get object. I'm just struggling. 
      Description of object I'm trying to click -- 
      HTML Code looks like <a ng-click.. "Click Here" it appears it's just a click able object named "click here" that opens a hidden window by running a script inside the web page. I'm not able to grab the information from the window unless it's open so I have to automate this click somehow. 
       
      I understand it's difficult to assist without having something to look at, I apologize for that sincerely and appreciate and assistance and suggestions. 
    • 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.
×
×
  • Create New...