LisHawj

Append to Edit box - Please assist.

3 posts in this topic

Hi everyone,

I am very new to scripting and picked up AutoIT scripting 8 days ago.  This is my very first adventure into scripting and have hit the Help File really hard, but there are many concepts that are very foreign to me.  Still I have manage to understand small tidbits here and there, but require some guidance with the script I wrote below.  Every hour throughout the day I receive an updated file "pcnames.txt" and I would like to read that file and set the data into the edit box.  Since I am new at this I must be going it at wrong because it works the first time around but then it does not append new data. Instead the second run overwrites the data in the edit box.  I would like to humbly ask for your advices or guidance.

 

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
Global $Form1 = GUICreate("Form1", 615, 438, 192, 124)
Global $Label1 = GUICtrlCreateLabel("Terminal 1 Output:", 40, 24, 91, 17)
Global $Edit1 = GUICtrlCreateEdit("", 40, 48, 553, 377)
GUICtrlSetData(-1, "")
Global $Button1 = GUICtrlCreateButton("START", 256, 16, 75, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###


While 1
 $nMsg = GUIGetMsg()
 Switch $nMsg
  Case $GUI_EVENT_CLOSE
   Exit
  Case $Button1
   Call("Test")
 EndSwitch
WEnd

Func Test()
 While 1
  $data = FileRead("C:\Reports\pcname.txt")
  ;MsgBox(0, "Result", $data)
  GUICtrlSetData($Edit1, $data & @CRLF)
  FileDelete("C:\Reports\pcnames.txt")
  Sleep(60 * 60 * 1000)
 WEnd
EndFunc   ;==>Test

 

Share this post


Link to post
Share on other sites



Something like this? I have also changed you logic a little to ensure your gui remains responsive and the Func Test() is called by an adlib.

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
Global $Form1 = GUICreate("Form1", 615, 438, 192, 124)
Global $Label1 = GUICtrlCreateLabel("Terminal 1 Output:", 40, 24, 91, 17)
Global $Edit1 = GUICtrlCreateEdit("", 40, 48, 553, 377)
GUICtrlSetData(-1, "")
Global $Button1 = GUICtrlCreateButton("START", 256, 16, 75, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###


While 1
 $nMsg = GUIGetMsg()
 Switch $nMsg
  Case $GUI_EVENT_CLOSE
   Exit
  Case $Button1
   ; enable updating Edit control
   AdlibRegister("Test",60 * 60 * 1000)
 EndSwitch
WEnd

Func Test()
  ;MsgBox(0, "Result", $data)
  $data = GUICtrlRead($Edit1) & @CRLF
  ; append new data to current data
  $data &= FileRead("C:\Reports\pcname.txt")
  GUICtrlSetData($Edit1, $data & @CRLF)
  FileDelete("C:\Reports\pcnames.txt")
EndFunc   ;==>Test

Jos

1 person likes this

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Thank you very much Jos.  I have to adjust the timer for AdlibRegister but now the script works as intended.  Again, thank you very much for your guidance and help.

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