david1337

add/remove from txt file inside GUI

30 posts in this topic

#1 ·  Posted (edited)

Hey guys

I need help to get further with this script :)

 

Test.txt contains lines like this:

_______________

Line1
Line2
Line3

_______________

I have managed to view the content of a txt file in the left side of a GUI like this:

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



Global $file = FileRead("Test.txt")


GUICreate("", 800, 800, 192, 124)
$control = GUICtrlCreateEdit($file, 0, 0, 400, 800, $ES_AUTOVSCROLL + $WS_VSCROLL + $ES_READONLY)
GUICtrlSetFont(-1, 14, 400, 0, "@Arial Unicode MS")
GUICtrlSetBkColor(-1, 0xFFFFFF)
GUICtrlSetState($control, $GUI_FOCUS) ;Makes sure that text is not highlighted by default
GUISetState(@SW_SHOW)


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd

 

Okay so is it possible to make each line become a clickable item?
Say I want to delete Line2, then I highlight it and click a "remove" button.

Also an "add" button would be needed to add new lines

On Case $GUI_EVENT_CLOSE the changes should be saved to Test.txt (Or with a save button)

 

Is this possible?

I hope you can help me :-)


 

Edited by david1337

Share this post


Link to post
Share on other sites



Can anyone get me in the right direction? :-)

Share this post


Link to post
Share on other sites

david1337,

Use a ListView rather than an Edit and my GUIListViewEx UDF will allow you to delete and add lines easily. Give it a try and see how you get on - the link is in my sig.

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Hi Melba

Thanks for you reply!

How do I make the list vertical, with one item for each line, like I did with GUICtrlCreateEdit? Can't seem to figure this out :S

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

david1337,

Split the text to be read into an array (FileReadToArray or StringSplit) and then add each element (line) to the ListView using GUICtrlCreateListViewItem. The UDF will then let you add/delete lines very easily.

M23

Edit: A simple example:

#include <GUIConstantsEx.au3>

#include <GUIListViewEx.au3>

; Simulate reading the file into an array
Global $aLines = ["Line1", "Line2", "Line3"]

$hGUI = GUICreate("Test", 500, 500)

$cLV = GUICtrlCreateListView(" ", 10, 10, 300, 300)
_GUICtrlListView_SetColumnWidth($cLV, 0, 290)

$cInsert = GUICtrlCreateButton("Insert Line", 400, 10, 80, 30)
$cDelete = GUICtrlCreateButton("Delete Line", 400, 50, 80, 30)

GUISetState()

; Intialise ListView
$iLV_Index = _GUIListViewEx_Init($cLV)
; Insert lines
_GUIListViewEx_Insert($aLines, True)
; Register required messages
_GUIListViewEx_MsgRegister(True, False, False, False)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $cInsert
            _GUIListViewEx_Insert("New line")
        Case $cDelete
            _GUIListViewEx_Delete()
    EndSwitch
WEnd

 

Edited by Melba23
Amended code slightly

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Hi Melba

Thank you, that worked like a charm.

The only thing I have problems with now is to save the file with the edited content.

My guess would be something like using a _GUIListViewEx_ReturnArray to view the state of the array, edited or not. (In the below script I try to show this in a msgbox)
Then use a filewrite with the new content.

Only problem is, I can't get the _GUIListViewEx_ReturnArray to show the valid data - I tried following your GUIListViewEx Guide, and I think that I'm close :)

 

 

#include <GUIConstantsEx.au3>
#include <GUIListViewEx.au3>


Global $FileToArray = FileReadToArray("test.txt")


$hGUI = GUICreate("Test Text File", 800, 800)

$cLV = GUICtrlCreateListView("[Headline]", 10, 10, 400, 775)
GUICtrlSetFont(-1, 12, 800, 0, "@Arial Unicode MS")
_GUICtrlListView_SetColumnWidth($cLV, 0, 378)

$cInsert = GUICtrlCreateButton("Add User", 425, 10, 80, 30)
$cDelete = GUICtrlCreateButton("Remove User", 425, 50, 80, 30)

GUISetState()

; Intialise ListView
$iLV_Index = _GUIListViewEx_Init($cLV)
; Insert lines
_GUIListViewEx_Insert($FileToArray, True)
; Register required messages
_GUIListViewEx_MsgRegister(True, False, False, False)

While 1
    Switch GUIGetMsg()
    Case $GUI_EVENT_CLOSE

;An attemp to show the content of the Array after I edited it
$updated = _GUIListViewEx_ReturnArray
MsgBox(0,"",$updated)

            Exit

        Case $cInsert
            _GUIListViewEx_Insert("New line")
        Case $cDelete
            _GUIListViewEx_Delete()
    EndSwitch
 WEnd

 

Share this post


Link to post
Share on other sites

david1337,

Using MsgBox to display an array? This works better:

Case $GUI_EVENT_CLOSE

            $aContent = _GUIListViewEx_ReturnArray($iLV_Index)
            _ArrayDisplay($aContent, "", Default, 8)

            Exit

M23

1 person likes this

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Uhm just ignore that I used MsgBox :) Had tried so many things that I mixed up my array with a normal list.

Anyway, thanks for your help! I got it working now.
GUIListViewEx is an indispensable UDF!

 

#include <GUIConstantsEx.au3>
#include <GUIListViewEx.au3>
#include <File.au3>

Global $File = "test.txt"
Global $FileToArray = FileReadToArray("test.txt")


$hGUI = GUICreate("Test Text File", 800, 800)

$cLV = GUICtrlCreateListView("[Headline]", 10, 10, 400, 775)
GUICtrlSetFont(-1, 12, 800, 0, "@Arial Unicode MS")
_GUICtrlListView_SetColumnWidth($cLV, 0, 378)

$cInsert = GUICtrlCreateButton("Add Item", 425, 10, 80, 30)
$cDelete = GUICtrlCreateButton("Remove Item", 425, 50, 80, 30)

GUISetState()

; Intialise ListView
$iLV_Index = _GUIListViewEx_Init($cLV)
; Insert lines
_GUIListViewEx_Insert($FileToArray, True)
; Register required messages
_GUIListViewEx_MsgRegister(True, False, False, False)

While 1
    Switch GUIGetMsg()
    Case $GUI_EVENT_CLOSE

            $aContent = _GUIListViewEx_ReturnArray($iLV_Index)
            _FileWriteFromArray($File,$aContent)

            Exit

        Case $cInsert
            _GUIListViewEx_Insert("New line")
        Case $cDelete
            _GUIListViewEx_Delete()
    EndSwitch
 WEnd

 

Edited by david1337

Share this post


Link to post
Share on other sites

david1337,

Glad you like the UDF - it is a pretty complex beast to master, but does have a lot of functionality.

M23

1 person likes this

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

Hi Melba

I need your help again :> (or some other genius) :D
When the OK button is clicked it writes the input from $ReadinputboxUsername into my text file, which works as expected.
Then it exits the loop, and goes back to the main GUI.

Is it possible to update my ListView when the OK button in the childGUI is clicked? In other words: It has to read and show the newly updated content of the text file.

 

;______________________________________________
#include <GUIConstantsEx.au3>
#include <GUIListViewEx.au3>
#include <File.au3>
#include <AD.au3>
#include <EditConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <MsgBoxConstants.au3>
;______________________________________________


Global $MainGUI_MyGUI
Global $File = "test.txt"
Global $FileToArray = FileReadToArray("test.txt")



Call ("MainGUI_MyGUI")



Func MainGUI_MyGUI()
    Local $cAddUser

    $MainGUI_MyGUI = GUICreate("My GUI", 800, 800, -1, -1)

    $cLV = GUICtrlCreateListView("[Users]", 10, 10, 400, 775)
GUICtrlSetFont(-1, 12, 800, 0, "@Arial Unicode MS")
_GUICtrlListView_SetColumnWidth($cLV, 0, 378)

$cAddUser = GUICtrlCreateButton("Add User", 425, 10, 80, 30)
$cRemoveUser = GUICtrlCreateButton("Remove User", 425, 50, 80, 30)


GUISetState(@SW_SHOW, $MainGUI_MyGUI)



; Intialise ListView
$iLV_Index = _GUIListViewEx_Init($cLV)
; Insert lines
_GUIListViewEx_Insert($FileToArray, True)
; Register required messages
_GUIListViewEx_MsgRegister(True, False, False, False)


    While 1
        Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE

            $aContent = _GUIListViewEx_ReturnArray($iLV_Index)
            _FileWriteFromArray($File,$aContent)
                ExitLoop

            Case $cAddUser
                GUISetState(@SW_DISABLE, $MainGUI_MyGUI)
                $ChildGUI_AddUser = ChildGUI_AddUser()
                GUISetState(@SW_ENABLE, $MainGUI_MyGUI)
                GUIDelete($ChildGUI_AddUser)
 ;               WinActivate($MainGUI_MyGUI) ; <<<<< Activate the ParentGUI again.


         Case $cRemoveUser
            _GUIListViewEx_Delete()

        EndSwitch
    WEnd
EndFunc   ;==>Main










Func ChildGUI_AddUser()

    $ChildGUI_AddUser = GUICreate("Find User", 615, 229, -1, -1, -1, -1, $MainGUI_MyGUI)


$inputboxUsername = GUICtrlCreateInput("", 192, 16, 233, 21)
$Check = GUICtrlCreateButton("Check", 440, 16, 41, 25)
$Cancel = GUICtrlCreateButton("Cancel", 520, 160, 81, 65)
$OK = GUICtrlCreateButton("OK", 426, 161, 81, 65)

    GUISetState()

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE

ExitLoop

        Case $Check
           $ReadinputboxUsername = GUICtrlRead($inputboxUsername)
           _AD_Open()
           $fullname = _AD_GetObjectAttribute($ReadinputboxUsername, "name")
           _AD_Close()
           $FullNameLabel = GUICtrlCreateLabel($fullname, 150, 64, 200, 100)



        Case $Cancel
        ExitLoop

        Case $OK
           If Not IsDeclared("ReadinputboxUsername") Then
              MsgBox(0,"Error", "No user is chosen")

           Else
         _FileWriteToLine($File, 1, $ReadinputboxUsername, 0)
         ExitLoop


           EndIf




        EndSwitch
    WEnd
    Return $ChildGUI_AddUser


EndFunc   ;==>ChildGUI_AddUser

 

Edited by david1337

Share this post


Link to post
Share on other sites

I3iII

Thanks for your answer, but that didn't do the trick I'm afraid :(

Share this post


Link to post
Share on other sites

Well you are going to have to rewrite some of your code for this to work.

 

I suggest making your own function with the FileReadToArray in it and calling it separately when needed (at the beginning, when you click ok... etc) to repopulate (update) your listview

Share this post


Link to post
Share on other sites

Hmm can't make it work properly - will have to give it some more work.

Share this post


Link to post
Share on other sites

#15 ·  Posted (edited)

I see what you mean...

Try This:

Spoiler
#include <GUIConstantsEx.au3>
#include <GUIListViewEx.au3>
#include <File.au3>
#include <AD.au3>
#include <EditConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <MsgBoxConstants.au3>

Global $MainGUI_MyGUI
Global $File = "test.txt"
Global $FileToArray = FileReadToArray("test.txt")

Call("MainGUI_MyGUI")

Func MainGUI_MyGUI()
    Local $cAddUser

    $MainGUI_MyGUI = GUICreate("My GUI", 800, 800, -1, -1)

    $cLV = GUICtrlCreateListView("[Users]", 10, 10, 400, 775)
    GUICtrlSetFont(-1, 12, 800, 0, "@Arial Unicode MS")
    _GUICtrlListView_SetColumnWidth($cLV, 0, 378)

    $cAddUser = GUICtrlCreateButton("Add User", 425, 10, 80, 30)
    $cRemoveUser = GUICtrlCreateButton("Remove User", 425, 50, 80, 30)

    GUISetState(@SW_SHOW, $MainGUI_MyGUI)

    ; Intialise ListView
    $iLV_Index = _GUIListViewEx_Init($cLV)
    ; Insert lines
    _GUIListViewEx_Insert($FileToArray, True)
    ; Register required messages
    _GUIListViewEx_MsgRegister(True, False, False, False)

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE

                $aContent = _GUIListViewEx_ReturnArray($iLV_Index)
                _FileWriteFromArray($File, $aContent)
                ExitLoop

            Case $cAddUser
                GUISetState(@SW_DISABLE, $MainGUI_MyGUI)
                $ChildGUI_AddUser = ChildGUI_AddUser()
                GUISetState(@SW_ENABLE, $MainGUI_MyGUI)
                GUIDelete($ChildGUI_AddUser)
                ;               WinActivate($MainGUI_MyGUI) ; <<<<< Activate the ParentGUI again.

            Case $cRemoveUser
                _GUIListViewEx_Delete()

        EndSwitch
    WEnd
EndFunc   ;==>MainGUI_MyGUI

Func ChildGUI_AddUser()

    $ChildGUI_AddUser = GUICreate("Find User", 615, 229, -1, -1, -1, -1, $MainGUI_MyGUI)
    $inputboxUsername = GUICtrlCreateInput("", 192, 16, 233, 21)
    $Check = GUICtrlCreateButton("Check", 440, 16, 41, 25)
    $Cancel = GUICtrlCreateButton("Cancel", 520, 160, 81, 65)
    $OK = GUICtrlCreateButton("OK", 426, 161, 81, 65)

    GUISetState()

    While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $Check
                $ReadinputboxUsername = GUICtrlRead($inputboxUsername)
                _AD_Open()
                $fullname = _AD_GetObjectAttribute($ReadinputboxUsername, "name")
                _AD_Close()
                $FullNameLabel = GUICtrlCreateLabel($fullname, 150, 64, 200, 100)
            Case $Cancel
                ExitLoop
            Case $OK
                If Not IsDeclared("ReadinputboxUsername") Then
                    MsgBox(0, "Error", "No user is chosen")
                Else
                    _FileWriteToLine($File, 1, $ReadinputboxUsername, 0)
                    _GUIListViewEx_Insert($ReadinputboxUsername) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ADDED LINE
                    ExitLoop
                EndIf

        EndSwitch
    WEnd
    Return $ChildGUI_AddUser

EndFunc   ;==>ChildGUI_AddUser

 

 

Edited by l3ill
1 person likes this

Share this post


Link to post
Share on other sites

I3iII

Thanks mate, that was a big help! :) So simple!

And since I wanted to write to the top row, I used:

_GUIListViewEx_InsertSpec( 1, $ReadinputboxUsername, $ReadinputboxUsername)

And now this became unnecessary:

_FileWriteToLine($File, 1, $ReadinputboxUsername, 0)

Since I use _FileWriteFromArray on exit.

Share this post


Link to post
Share on other sites

Yeah, I guess that the example needs a little polish -  anything specific? :P

Share this post


Link to post
Share on other sites

#19 ·  Posted (edited)

No worries.  If you are interested see my last code post (15). ( Delete (unnecessary) empty CR and run Tidy )

I understand most people dont clean up until there close to finishing up.

Just me being fastidious (anal)  o:)

Good luck with your project !

Bill

Edited by l3ill
1 person likes this

Share this post


Link to post
Share on other sites

Haha omg I wish that I could double like that post :D

Thank you!

David

 

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

  • Similar Content

    • nacerbaaziz
      By nacerbaaziz
      Hello my friends
      I am a totally blind young man
      for easier to read books and articles Among the blind
      i has programmed a tool
      This tool converts text to audio with the possibility to save it into a wav or mp3 file
      It is also compatible with all persons, whether blind or ordinary
      I have completed the work of this tool and want to take your opinion
      i Especially published here for anyone looking about how to convert text to speech, I will put this tool open source for you
      I want to know what your think about it
      and if it need any other additions?
      Note :
      This tool converts texts to audio using sapi 5 voices
      so i was also puted a hot keys to control the tool
      Now I put this project to you for public benefit and I am ready to answer any question.
      Apology :
      I am an Arab youth from Algeria
      I do not mastered English very well
      So I apologize to you if there are written mistakes
      With my greetings and best wishes
      My texts to audio converter.zip
    • FrancescoDiMuro
      By FrancescoDiMuro
      Good morning guys
      I was trying to not open another post, writing here my little issue, but seems that no one cares about, and so, I'm opening another post
      What I'm trying to do, is detect the event close sent from the virtual keyboard.
      Why?
      Because, I have an application which, when I set the focus on a textbox, if the virtual keyboard does not exist, then it is created, else, it's not created
      But, everytime I try to close the virtual keyboard, the focus remains on the textbox, and another $EN_FOCUS event it's launched and detected from my WM_COMMAND, and so, the virtual keyboard is opened again. 
      How can I solve this little "issue"? 
      I was trying to detect the event sent from the virtual keyboard, storing the handle of it in a variable, and setting:
      GUISetOnEvent($GUI_EVENT_CLOSE, "CloseVK", $hVirtualKeyboard) without any result.
      Can someone please help me?
      Thanks  
      EDIT:
      Here I'd like to see @Melba23, @water, @Danyfirex...
       
    • zetaimmersion
      By zetaimmersion
      I have 2 items (a field box and a bypass checkbox). every time the box is checked i need the field to become writable. unchecked is read only displaying some text.
      this is as far as i got as I am stuck at making it read/write toggle
      #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <EditConstants.au3> #include <WindowsConstants.au3> $hGUI = GUICreate("Test", 500, 500) Global $hCombo = GUICtrlCreateInput("", 10, 10, 200, 20, BitOR($ES_AUTOHSCROLL,$ES_READONLY)) GUICtrlSetBkColor($hCombo,0xe7e5e5) Global $cbox = GUICtrlCreateCheckbox ("", 40,50,10,20) GUICtrlSetState($cbox, $GUI_Unchecked) GUISetState() Global $sCurrCombo = "" While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $cbox If GUICtrlRead($cbox) <> $sCurrCombo Then $sCurrCombo = GUICtrlRead($cbox) GUICtrlSetStyle ($hCombo, $SS_LEFTNOWORDWRAP) GUICtrlSetBkColor($hCombo,0xFFFFFF) MsgBox(0, "Choice", "PLease enter the text") EndIf EndSwitch WEnd  
    • dascondor
      By dascondor
      So I having issues with this GUI/Listview. My main GUI works like it needs to but the ListView GUIs don't. The exit buttons do not work on them and om have a hard time getting them to work. And I'm trying to make the  listview GUI resizeable. But I'm not sure how to fix either of these issues any thoughts.
      #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <File.au3> #include <ScreenCapture.au3> #include <MsgBoxConstants.au3> #include <WinAPIFiles.au3> #include <Array.au3> #include <GuiListView.au3> #include <GuiImageList.au3> #include <ListviewConstants.au3> #include 'MultiPing.au3' Opt("GUIOnEventMode", 1) #Region ;Declares ; Reads text file for the base list of IP's Global $aBase_IPlist = _FileReadToArray_mod(".\IP_List.txt") Global $replace2 = "Second" Global $replace3 = "Thrid" ;Global $userdata1 = GUICtrlRead($data1) ;Global $userdata2 = GUICtrlRead($data2) Global $savefolder = "C:\Users\" Global $paths = "\Desktop\PingChecks" Global $1stpaths = "\~~~Store" Global $2ndpaths = "~~~" Global $results = FileExists($savefolder & @UserName & $paths) ;Global $foldercheck = FileExists($savefolder & @UserName & $paths & $1stpaths & $userdata1 & $userdata2 & $2ndpaths) ;Global $savefile = "C:\Users\" & @UserName & "\Desktop\PingChecks\~~~Store" & $userdata1 & $userdata2 & "~~~\" #EndRegion ;Declares #Region ### START Koda GUI section ### Form= $IPMonkey = GUICreate("IP Monkey", 573, 254, -1, -1) GUISetIcon("C:\Users\Dlex\Pictures\monkeyicon.ico", -1) GUISetFont(16, 800, 0, "Arial") GUISetBkColor(0xFFFFFF) GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents") GUISetOnEvent($GUI_EVENT_MINIMIZE, "SpecialEvents") GUISetOnEvent($GUI_EVENT_MAXIMIZE, "SpecialEvents") GUISetOnEvent($GUI_EVENT_RESTORE, "SpecialEvents") $data1 = GUICtrlCreateInput("1", 184, 120, 89, 32, BitOR($GUI_SS_DEFAULT_INPUT, $ES_CENTER)) GUICtrlSetColor(-1, 0x000000) $data2 = GUICtrlCreateInput("23", 280, 120, 89, 32, BitOR($GUI_SS_DEFAULT_INPUT, $ES_CENTER)) GUICtrlSetColor(-1, 0x000000) $GOButton = GUICtrlCreateButton("GO", 80, 192, 75, 25) GUICtrlSetFont(-1, 10, 800, 0, "Arial") GUICtrlSetColor(-1, 0x000000) GUICtrlSetBkColor(-1, 0x00FF00) GUICtrlSetTip(-1, "Runs A Live Continuous Ping" & @CRLF & _ "Until Told Other Wise") GUICtrlSetOnEvent(-1, "GOButtonClick") $quickscan = GUICtrlCreateButton("Quick Scan", 224, 192, 107, 25) GUICtrlSetFont(-1, 12, 800, 0, "Arial") GUICtrlSetColor(-1, 0x000000) GUICtrlSetBkColor(-1, 0xFFFF00) GUICtrlSetOnEvent(-1, "quickscanClick") GUICtrlSetTip(-1, "Quickly Scans, Then Saves" & @CRLF & _ "Results In Your 'PingChecks' " & @CRLF & _ "Folder Under Your Store Number Folder") Global $exitbutton = GUICtrlCreateButton("Exit", 416, 192, 75, 25) GUICtrlSetFont(-1, 12, 800, 0, "Arial") GUICtrlSetColor(-1, 0x000000) GUICtrlSetBkColor(-1, 0xFF0000) GUICtrlSetTip(-1, "What Do You Think This Button Does?") GUICtrlSetOnEvent(-1, "exitbuttonClick") $titlebar = GUICtrlCreateLabel("IP Monkey", 16, 120, 107, 28) GUICtrlSetColor(-1, 0x000000) $Pic1 = GUICtrlCreatePic("C:\Users\Dlex\Pictures\monkeyicon-0.jpg", 16, 16, 100, 100) GUICtrlSetOnEvent(-1, "Pic1Click") $infobutton = GUICtrlCreateButton("?", 536, 8, 27, 25) GUICtrlSetColor(-1, 0x000000) GUICtrlSetBkColor(-1, 0xFF8000) GUICtrlSetTip(-1, "Unsure what to do?" & @CRLF & _ "This will get give you " & @CRLF & _ "the help for IP Monkey") GUICtrlSetOnEvent(-1, "infobuttonClick") $Whatstorelabel = GUICtrlCreateLabel("What Store?", 208, 56, 130, 28) GUICtrlSetColor(-1, 0x000000) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### #Region ;ping gui ; ------ pinger GUI ------------------- Global $StopPing = 0 Local $Win_X = 1200, $Win_Y = 880 ; dimension of window Global $PingGui = GUICreate("IP Monkey", $Win_X, $Win_Y, -1, -1) GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents") Global $listview = GUICtrlCreateListView("", 10, 10, $Win_X - 20, $Win_Y - 40) GUICtrlSetFont(-1, 8) $button1 = GUICtrlCreateLabel("Hit Exit To Quit", 10, $Win_Y - 25, $Win_X - 20, 20, -1,$ES_CENTER) GUICtrlSetFont(-1, 10, 800) GUICtrlSetTip(-1, "exit") GUICtrlSetOnEvent(-1, 'SpecialEvents') GUICtrlSetStyle($listview, $LVS_ICON) ; + $LVS_NOLABELWRAP) GUISetState(@SW_HIDE) ; hidden at startup ; --------- end of pinger gui ------------- #EndRegion ;ping gui ; Generate colored square images $hImage = _GUIImageList_Create(30, 30) _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($listview, 0xFFFF00, 30, 30)) ; yellow _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($listview, 0xFF0000, 30, 30)) ; red _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($listview, 0x00FF00, 30, 30)) ; green _GUICtrlListView_SetImageList($listview, $hImage, 0) While 1 Sleep(100) WEnd Func exitbuttonClick() MsgBox(0,'0','0') Exit EndFunc ;==>exitbuttonClick Func GOButtonClick() $userdata1 = GUICtrlRead($data1) $userdata2 = GUICtrlRead($data2) ; pass the wanted new octet replace_And_Go($userdata1, $userdata2) ; generate a list of new IP and Go EndFunc ;==>GOButtonClick Func infobuttonClick() EndFunc ;==>infobuttonClick Func Pic1Click() EndFunc ;==>Pic1Click Func quickscanClick() $userdata1 = GUICtrlRead($data1) $userdata2 = GUICtrlRead($data2) replace_And_Go2($userdata1, $userdata2) EndFunc ;==>quickscanClick Func SpecialEvents() Select Case @GUI_CtrlId = $GUI_EVENT_CLOSE _button1() Case @GUI_CtrlId = $GUI_EVENT_MINIMIZE Case @GUI_CtrlId = $GUI_EVENT_RESTORE Case @GUI_CtrlId = $GUI_EVENT_MAXIMIZE EndSelect EndFunc ;==>SpecialEvents #Region ; Main_GO/Replace_and_GO #cs ############################## second script ############################################# ; this is to ping continuously a list of IP addresses, get and display ping result "live" ; it simulates the dos "ping -t" command but performed simultaneously on many IP ; presenting the results in a ListView highlighting not responding devices with a red box #ce Func replace_And_Go($s_2, $s_3) ; Create a new array wit a new list of IP according to passed second and third octet Local $aNew_IPlist = $aBase_IPlist For $i = 0 To UBound($aNew_IPlist) - 1 $aNew_IPlist[$i][1] = StringReplace(StringReplace($aBase_IPlist[$i][1], $replace2, $s_2), $replace3, $s_3) Next GUISetState(@SW_HIDE, $IPMonkey) GUISetState(@SW_SHOW, $PingGui) ; pass the new list to the pinger Main_GO($aNew_IPlist) GUISetState(@SW_HIDE, $PingGui) GUISetState(@SW_SHOW, $IPMonkey) EndFunc ;==>replace_And_Go Func Main_GO($IPlist) HotKeySet("{esc}", "exitbuttonClick") $StopPing = 0 ; $IPlist = _FileReadToArray_mod(".\IP_List.txt") ; Reads text file for list of IP's ; ; the above command, it loads in the $IPlist array the values contained in the file IP_List.txt ; values in the file should be separated by a semicolon, something like in the following example: ; ; hostname1;192.168.0.1 ; hostname2;192.168.0.5 ; hostnameX;10.59.7.200 ; etc.... ; ; if values in the file are not separated by a semicolon, but another char is used, for example a comma, ; then just pass it as second parameter of the function: $IPlist = _FileReadToArray_mod(".\IP_List.txt", ",") ; _GUICtrlListView_BeginUpdate($listview) _GUICtrlListView_DeleteAllItems($listview) _GUICtrlListView_AddArray($listview, $IPlist) ; fill ListView _GUICtrlListView_EndUpdate($listview) While Not $StopPing ; 1 ; continuously ping addresses of the previously loaded file (IP_List.txt) Sleep(10) ; ; $IPlist is the array loaded with all the IP to be pinged (a 2d array in this case) ; | ; | 1 means the IP are in the second column of the $IPlist array (first colun is nr. 0) ; | | ; | | +--> 0 means return back an array loaded with results from all pinged addresses (responding and not responding) ; | | | if you use 1 then only responding addresses are loaded in the returned array [default] ; | | | if you use 2 then only NOT responding addresses are loaded in the returned array ; | | | In this case we do not need an array to be returned, we only need to perform all pings and pass results ; | | | directly (on the fly) to the "_refresh" callback function that will refresh the listview ; | | | ; | | | 0 means NO lookup name resolution must be performed ; | | | | ; | | | | +--> this is the callback function to be called for each pinged address each time the ping has finished ; | | | | | (see the MultiPing.au3 file for info on all passed params) ; | | | | | 6 parameters are passed to this function, but only 2 are used by the called function in this case: ; | | | | | [4] roundtrip of the responding ping or -1 if IP is down ; | | | | | [5] Index (position) of this IP within the caller's passed array ; | | | | | ; v v v v v _nPing($IPlist, 1, 0, 0, "_refresh") WEnd EndFunc ;==>Main_GO #EndRegion ; Main_GO/Replace_and_GO #Region ; QuickScan/Replace_and_GO2 Func replace_And_Go2($s_2, $s_3) ; Create a new array wit a new list of IP according to passed second and third octet Local $aNew_IPlist = $aBase_IPlist For $i = 0 To UBound($aNew_IPlist) - 1 $aNew_IPlist[$i][1] = StringReplace(StringReplace($aBase_IPlist[$i][1], $replace2, $s_2), $replace3, $s_3) Next GUISetState(@SW_HIDE, $IPMonkey) GUISetState(@SW_SHOW, $PingGui) ; pass the new list to the pinger QuickRun($aNew_IPlist) GUISetState(@SW_HIDE, $PingGui) GUISetState(@SW_SHOW, $IPMonkey) EndFunc ;==>replace_And_Go2 Func QuickRun($IPlist) $userdata1 = GUICtrlRead($data1) $userdata2 = GUICtrlRead($data2) HotKeySet("{esc}", "_button1") Local $Win_X = 1200, $Win_Y = 880 ; dimension of window $PingGui = GUICreate("IP Monkey" & "~~~" & @UserName & "~~~" & "Store" & $userdata1 & $userdata2 & "~~~" & @MON & "." & @MDAY & "." & @YEAR & "~~~" & @HOUR & "." & @MIN, $Win_X, $Win_Y, -1, -1) GUISetOnEvent($GUI_EVENT_CLOSE, "_button1", $PingGui) $listview = GUICtrlCreateListView("", 10, 10, $Win_X - 20, $Win_Y - 40) GUICtrlSetFont(-1, 8) GUICtrlSetStyle($listview, $LVS_ICON) ; + $LVS_NOLABELWRAP) ; Generate colored square images $hImage = _GUIImageList_Create(30, 30) _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($listview, 0xFFFF00, 30, 30)) ; yellow _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($listview, 0xFF0000, 30, 30)) ; red _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($listview, 0x00FF00, 30, 30)) ; green _GUICtrlListView_SetImageList($listview, $hImage, 0) $button1 = GUICtrlCreateButton("Exit", 10, $Win_Y - 25, $Win_X - 20, 20) GUICtrlSetTip(-1, "End of program") GUICtrlSetOnEvent(-1, "exitbuttonClick") GUISetState(@SW_SHOW) ;~ $IPlist = _FileReadToArray_mod(".\IP_List.txt") ; Reads text file for list of IP's _GUICtrlListView_BeginUpdate($listview) _GUICtrlListView_AddArray($listview, $IPlist) ; fill ListView _GUICtrlListView_EndUpdate($listview) ;While 1 ; perform Pings and update ListView by the "_refresh" callback function $aFinalResult = _nPing($IPlist, 1, 0, 0, "_refresh") ;~ _ArrayDisplay($aFinalResult) ;DirCheck() EndFunc ;==>QuickRun #EndRegion ; QuickScan/Replace_and_GO2 #Region ; Misc Funcs (network) Func _refresh($Params) ; this receive ping results and displays them in the ListView _GUICtrlListView_SetItemImage($listview, $Params[5], 0) ; set colour to Yellow Sleep(50) ; a little wait If $Params[4] = -1 Then ; Device not responding to ping _GUICtrlListView_SetItemImage($listview, $Params[5], 1) ; set colour to RED _GUICtrlListView_EnsureVisible($listview, $Params[5]) ; Position view to this item Else ; Device responds to ping _GUICtrlListView_SetItemImage($listview, $Params[5], 2) ; set colour to GREEN EndIf EndFunc ;==>_refresh Func _button1() ; Button 1 clicked ;~ $StopPing = 1 Exit EndFunc ;==>_button1 #EndRegion ; Misc Funcs (network)  
      MultiPing.au3
      IP_List.txt
    • jannikrendl
      By jannikrendl
      Hey,
      I'd like to create a gui wich records the total runtime of the script. 
      It should tell the hours,minutes and seconds (like this: Running since 00:00:00)
      This is what I have right now:
      Local $iTimer, $hGUI, $cLabel $iTimer = TimerInit() $hGUI = GUICreate("") $cLabel = GUICtrlCreateLabel("",300,380,100,20) GUISetState() AdlibRegister("_UpdateLabel",1000) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case -3 Exit EndSwitch Wend Func _UpdateLabel() $iTimerDiff = TimerDiff($iTimer) GUICtrlSetData($cLabel,"Running Since " & Round($iTimerDiff/1000,0) & " sec.") EndFunc Thanks in advance