Jump to content
Sign in to follow this  
jbsoccerbrit

Changing application to write to Notepad.

Recommended Posts

jbsoccerbrit

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
JLogan3o13

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?


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites
jbsoccerbrit

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
l3ill

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
l3ill

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
jbsoccerbrit

Thank you sir, I will check it out for sure :).

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  

  • Similar Content

    • VollachR
      By VollachR
      Hi,
      I'm looking for a way to take a number value from a Row2 of a 2D array and according to this check if files that appear in rows 3-11 in the array exists.
      For example, if the number in Row2 is 5 I need to check for the files in Row 3-6 only, if it is 6 than rows 3-7 and so on.
      I thought on using a FOR loop but I have very little experience with those.
      Can you suggest the best way to do what I need?
      BTW, the files in Rows 3-11 will usually have blank value for any row above the number in Row2 (e.g. Row2 = 5 so Rows3-6 will have values but 8-11 be empty), The values I need are in Column 1 of the array, the name of the key from the INI file that the array was created from is in Column 0.
      Full Example:
      Row2 of Array:
      Col0 = Games# - Col1 = 5
      Rows3-6
      Col0 = Exe2 - Col1 = Path To File
      Col0 = Exe3 - Col1 = Path To File
      Col0 = Exe4 - Col1 = Path To File
      Col0 = Exe5 - Col1 = Path To File
      I need that if Row2 is 5 to check these above for rows if the file exists, if it was 6 then the next row as well and so on up until number 10 in Row2 as it can't go above 10.
      So basically for whatever number in Row2 from 2-10 need to check 1-9 rows from 3-11 to see if the files in Col1 exists and if any of them don't exist it should call a function that shows an error message.
      I'm pretty sure I have the first line of the for look correct:
      For $i = 1 To $aAIO[2][1] Just not sure how to continue from there, also not sure if $i should be equal 1 or 2.
      Help will be appreciated.
    • VollachR
      By VollachR
      Hi,
      I've written a specialty INI file editor for a specific set of INI files related to a bigger script I'm working on.
      I'm trying to create a verification script that checks the ini files structure and format and gives an error if they are not in expected format.
      What I did so far is create a couple of custom arrays, each with the list of Sections expected in the files and I use IniReadSectionNames in order to read the sections from the selected INI file and compare it to the array.
      It works fine, excepts it only gives an error if one or more of the sections in the custom array is missing, if they all exist but there are other additional sections that shouldn't be there it doesn't give an error and continue to open the editor screen.
      Here are the relevant part of my script:
      The Custom Verification Arrays:
      ;Creating Arrays for INI Verification Global $aSettingsVerify[7] $aSettingsVerify[1] = "Conversion" $aSettingsVerify[2] = "AIO" $aSettingsVerify[3] = "Data" $aSettingsVerify[4] = "Redist" $aSettingsVerify[5] = "Split" $aSettingsVerify[6] = "Autorun" Global $aDataVerify[6] $aDataVerify[1] = "Compression" $aDataVerify[2] = "Exclude" $aDataVerify[3] = "LangExclude" $aDataVerify[4] = "PreCommands" $aDataVerify[5] = "PostCommands" The IniReadSectionNames verification part:
      Case $OK If StringInStr($ActiveConfig, "Settings.ini") Then $CheckArray1 = IniReadSectionNames($ActiveConfig) $CheckArray2 = _ArrayCompare($aSettingsVerify, $CheckArray1) $CheckArray3 = UBound($CheckArray2, 1) If $CheckArray3 = 1 Then GUIDelete($ConfigStart) SettingsGUI() EndIf If $CheckArray3 > 1 Then WrongIni() EndIf EndIf If StringInStr($ActiveConfig, "Data") Then $CheckArray1 = IniReadSectionNames($ActiveConfig) $CheckArray2 = _ArrayCompare($aDataVerify, $CheckArray1) $CheckArray3 = UBound($CheckArray2, 1) If $CheckArray3 = 1 Then GUIDelete($ConfigStart) DataGUI() EndIf If $CheckArray3 > 1 Then WrongIni() EndIf EndIf The Function that performs the compare: (Found it in another thread on this forums somewhere by using Google Search)
      ;Compares Imported INI file with the Verification array Func _ArrayCompare(ByRef $a1, ByRef $a2) Local $nOldSize = UBound($a2) Local $a3[$nOldSize], $nNewSize = $nOldSize For $i = 0 To UBound($a1) - 1 For $j = 0 To $nOldSize - 1 If Not $a3[$j] And ($a1[$i] = $a2[$j]) Then $a3[$j] = 1 $nNewSize -= 1 EndIf Next Next Local $a4[$nNewSize], $j = 0 For $i = 0 To $nOldSize - 1 If Not $a3[$i] Then $a4[$j] = $a2[$i] $j += 1 EndIf Next Return $a4 EndFunc ;==>_ArrayCompare  
      Any way to make a check if there are sections other than the ones in the Verification Array and produce an error?
      Thanks
    • nacerbaaziz
      By nacerbaaziz
      Hi guys
      I have a question about the slider  controle
      There is a problem with screen readers, wen we Using a screen reader We usually move between GUI controls using the tab key.
      But when you create a slider , beside to it there are  buttons and check boxes or any other controls, When I move between the GUI controls using the tab key I can not find the slider.
      But if it were alone in the window, I would find it normally.
      Is there a solution to Solve this problem please?
      This is the code i tried
      #include <GUIConstantsEx.au3>
      #include <WindowsConstants.au3>
      #include <MsgBoxConstants.au3>
      #include <SliderConstants.au3>
      main()
      Func main()
          GUICreate("slider", 200, 200, -1, -1)
      GUICtrlCreateGroup("slider", 10, 10, 240, 50)
          Local $idSlider1 = GUICtrlCreateSlider(50, 30, 200, 20, BitOr($TBS_DOWNISLEFT, $TBS_BOTH))
          GUICtrlSetLimit(-1, 100, 0)
      ;GUIStartGroup("")
          Local $idButton = GUICtrlCreatebutton("Value?", 75, 70, 70, 20)
          GUISetState(@SW_SHOW)
          GUICtrlSetData($idSlider1, 10)
      while 1
      switch GUIGetMsg()
      case $GUI_EVENT_CLOSE
      exit
      case $idButton
                  MsgBox($MB_SYSTEMMODAL, "slider1", GUICtrlRead($idSlider1))
      endSwitch
      Wend
      EndFunc
      [Click and drag to move]
       
       
    • VollachR
      By VollachR
      Hi,
      I'm using _FileListToArray to create an array listing .ini files in a specific folder, problem is, I want only the file named Settings.ini and any Files named Data#.ini where # is actually a number, I don't want any other .ini file that may be there even though it shouldn't be there to be included in the array.
      Is it possible to use multiple filters in _FileListToArray? or is there another way to do what I'm looking for?
      My current code:
      $IniList = _FileListToArray(@ScriptDir & "\Settings", "*.ini", 1, False) _ArraySort($IniList, 1, 1) _ArraySort($IniList, 0, 2) $IniOptions = _ArrayToString($IniList, "|", 1)  
      Thank you.
    • VollachR
      By VollachR
      Hi,
      I'm creating a tool to edit some ini files that belong to a program I'm working on...
      Basically everything work fine except I can't find a way to check if the if the WriteIniSection operation was successful...
      For Example, let's say the INI file is by mistake or some other reason Read Only, or the user don't have the right permission to write to the file or the folder it's in... Right now, in such a case The INI file, as expected, won't get updated, but I when I perform an if error or if not error checks I always get the msgbox for the if not error.
      Here's the relevant code part:
       
      IniWriteSection(@ScriptDir & "\Settings\Settings.ini", "Conversion", $aConversion, 1) IniWriteSection(@ScriptDir & "\Settings\Settings.ini", "AIO", $aAIO, 1) IniWriteSection(@ScriptDir & "\Settings\Settings.ini", "Data", $aData, 1) IniWriteSection(@ScriptDir & "\Settings\Settings.ini", "Redist", $aRedist, 1) IniWriteSection(@ScriptDir & "\Settings\Settings.ini", "Split", $aSplit, 1) IniWriteSection(@ScriptDir & "\Settings\Settings.ini", "Autorun", $aAutorun, 1) If Not @error Then MsgBox($MB_ICONINFORMATION, "Success", "Settings.ini Saved Successfully") Else If @error Then MsgBox($MB_ICONERROR, "Failure", "Settings.ini Could Not Be Saved!" & @CRLF & @CRLF & "Please Check If The File Is ReadOnly And That You Have Permission To Change It Or Its Location") EndIf EndIf  
      How can I perform a check to see if the ini file was written to successfully?
      Thanks.
×