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

    • houser747
      By houser747
      I have previously used _IEFormElementGetObjByName and _IEFormElementSetValue to enter text into a search box on a form and then submit the form.
      I am now trying to enter text into a search box which is not part of a form. 
      Here is the HTML from the website that i'm trying to enter the data on and then submit the search.
      <div class="row">
          <div class="form-group col-xs-12">
              <span id="FullWidthWithSubmenuContent_FullWidthContent_MainContent_AircraftRegistry_lblSearchText" for="input-search">Registreringsbeteckning</span>
              <div class="input-group col-xs-12">
                  <span id="FullWidthWithSubmenuContent_FullWidthContent_MainContent_AircraftRegistry_preSearchText" class="input-group-addon">SE -</span>
                  <input name="ctl00$FullWidthWithSubmenuContent$FullWidthContent$MainContent$AircraftRegistry$txtSearchText" type="text" value="DTH" id="FullWidthWithSubmenuContent_FullWidthContent_MainContent_AircraftRegistry_txtSearchText" class="form-control" />
              </div>
          </div>
      </div>
      <div class="row">
          <div class="form-group col-xs-12">
              <label class="sr-only" for="">Sök</label>
              <input type="submit" name="ctl00$FullWidthWithSubmenuContent$FullWidthContent$MainContent$AircraftRegistry$btnSearch" value="Sök" id="FullWidthWithSubmenuContent_FullWidthContent_MainContent_AircraftRegistry_btnSearch" class="btn btn-primary ladda-button" data-style="expand-right" />
          </div>
      </div>
      Many thanks in advance
      cheers
      Roger
    • kawliga751
      By kawliga751
      I have a workplace GUI that has a search field function that pulls up customer records to allow changes. I am attempting to 1)LOGIN 2)Enter Search field, enter a number and then {ENTER} 3)change specific field once customer record loads. I have very limited experience in GUI manipulation but I am able to login using the below:
      #include <IE.au3> Const $navOpenInNewTab = 0x0800 Dim $oIE = _IECreate('http://asag.xxxxxxx.com/ASAG/index.htm') Call ("RacksheetSignIn") Func RacksheetSignIn () Local $username = _IEGetObjByName ($oIE,"uname") Local $password = _IEGetObjByName ($oIE,"pword") $oIE.Navigate2('http://asag.xxxxxxx.com/apps/RackSheets/LogInSAG/login.asp',2048) _IEFormElementSetValue ($username, "xxxxxxx") _IEFormElementSetValue ($password, "xxxxxxx") Send('{Enter}') EndFunc However I can't seem to use the _IEGetObjByName or Mouseclick to focus on the search field to allow me to enter my search criteria. When I "inspect element" in the Search field I get the attached:
       
      Any help would be MUCH appreciated
       
       
       

    • Jibberish
      By Jibberish
      I am having difficulties getting updated results from GUICtrlCreateInput. I wrote a small script to demonstrate what I am trying to do.
      This script reads a text file into an array and displays the Name and Number from the text file.
      The user can check a name and change the number, and the results are displayed in _ArrayDisplay.
      Only the Checked names are displayed in their original position. This is necessary for future
      plumbing.
      The problem with this script is the original number is returned, not the changed number. I cannot
      figure out how to get the updated number to be displayed.
      ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ; ; This script reads a text file into an array and displays the Name and Number from the text file. ; The user can check a name and change the number, and the results are displayed in _ArrayDisplay. ; Only the Checked names are displayed in their original position. This is necessary for future ; plumbing. ; ; The problem with this script is the original number is returned, not the changed number. I cannot ; figure out how to get the updated number to be displayed. ; ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #include-once #include <MsgBoxConstants.au3> #include <array.au3> #include <Date.au3> #include <WinAPIFiles.au3> #include <AutoItConstants.au3> #include <Misc.au3> #include <File.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> Local $iMax = 6 ;Default number of Videos - 1 for the array counter Dim $aTextFile[$iMax][2] ; [start with 5 entries][Name, Number] Don't get confused! [Row][Column] Local $i = 0 Local $iLeft = 30 Local $iTop = 30 Local $sName Local $sNumber Local $aArray Local $iMaxCol = 5 Local $iRow = 0 Local $iCol = 0 Local $aNumberCount[$iMaxCol][2] $aArray1 = ReadFile() $aNamesNumbers = DisplayNames($aArray1) _ArrayDisplay($aNamesNumbers) ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ; ; ReadFile() places the contents of the NameNumber.txt file in an array ; ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Func ReadFile() Local $sFileData = @ScriptDir & "\NameNumber.txt" Local $iStrReturn = 0 Local $aArrayFile Local $aTextFile[$iMaxCol][2] Local $aName Local $sCheckBox1 Const $iL = 10 ; Count from Left for GUI so all buttons line up Local $sFill Local $iA = 0, $iN = 0 ; Put the Names into an Array _FileReadToArray($sFileData, $aArrayFile) For $iA = 0 To $aArrayFile[0] ; Step through the array looking for Names If StringInStr($aArrayFile[$iA], "Name:") Then $aName = StringSplit($aArrayFile[$iA],":") $sFill = $aName[2] If UBound($aTextFile) <= $iRow Then ; Resize the array when $iRow is equal to the element count in the array to prevent subscript error ReDim $aTextFile[UBound($aTextFile) + 1][$iMaxCol] EndIf $aTextFile[$iRow][$iCol] = $sFill $iRow += 1 EndIf Next $iCol = 1 $iRow = 0 $sFill = "" For $iA = 1 To $aArrayFile[0] ; Step through the array looking for Numbers If StringInStr($aArrayFile[$iA], "Number:") Then $aName = StringSplit($aArrayFile[$iA],":") $sFill = $aName[2] If UBound($aTextFile) <= $iRow Then ; Resize the array when $iRow is equal to the element count in the array to prevent subscript error ReDim $aTextFile[UBound($aTextFile) + 1][$iMaxCol] EndIf $aTextFile[$iRow][$iCol] = $sFill $iRow += 1 EndIf Next Return $aTextFile EndFunc ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ; ; Display the Name and Number ; ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Func DisplayNames($aArray1) Local $aName[$iMax] Local $aNumbers[$iMax] $iMMCount = UBound($aArray1) $iMMCount -=1 Local $iWidth = 300 Local $iLength = 300;$iMMCount * 30 GUISetFont(12) $hGUI = GUICreate("Edit / Update Number Test", $iWidth, $iLength, -1, -1) GUICtrlCreateLabel(" Name Number",1,5) ;$iTop += 30 ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ; ; Display Name with a Checkbox. Only Checked Names should be saved. ; ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ For $i = 0 to $iMMCount Step 1 $sNameText = $aArray1[$i][0] $iNameLength = StringLen($sNameText) $aName[$i] = GUICtrlCreateCheckbox($sNameText,$iLeft, $iTop) $iTop += 30 Next ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ; ; Display the number from the text file below each name. Allow the user to change the number and display the ; new number. ; ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ $iLeft = 60 GUIStartGroup() $iTop = 28 For $i = 0 to $iMMCount Step 1 $sNumberText = $aArray1[$i][1] $aNumberCount[$i][1] = $sNumberText $aNumberCount[$i][0] = GUICtrlCreateInput($sNumberText,$iLeft, $iTop, 50,18, $GUI_DOCKAUTO) GUICtrlSetPos($aNumberCount[$i][0],200) $iTop += 30 Next ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ; ; Read the checked names and (possibly updated) number ; ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ $iMMCount = UBound($aNumberCount) $iMMNewCount = $iMMCount - 1 Local $aGUICheckbox[$iMMCount] Local $aCheckedNameNumber[$iMMCount][2] $iLeft = 30 Local $idCloseGUI = GUICtrlCreateButton("Close",$iLeft, $iTop) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $idCloseGUI For $i = 0 To $iMMNewCount Step 1 Switch GUICtrlRead($aName[$i]) Case $GUI_CHECKED $aCheckedNameNumber[$i][0] = $aArray1[$i][0] Case $GUI_UNCHECKED EndSwitch Switch GUICtrlRead($aNumberCount[$i][0]) Case $aCheckedNameNumber[$i][1] = GUICtrlRead($aNumberCount[$i][1]) EndSwitch Next ExitLoop EndSwitch WEnd For $i = 0 to $iMMNewCount step 1 GUICtrlRead($aNumberCount[$i][0]) If $aCheckedNameNumber[$i][0] <> "" Then $aCheckedNameNumber[$i][1] = $aNumberCount[$i][1] EndIf Next GUIDelete($hGUI) Return $aCheckedNameNumber EndFunc This is the text file I am reading. If you want to try this out put the NameNumber.txt file in your script directory. It's attached to the post.
      * This is a dummy file with a Name and Number * The only purpose of this file is to read the updated Number. Name:Taggart Number:916 Name:Mongo Number:90 Name:Hedley Lamarr Number:22 Name:Bart Number:9999 Name:The Waco Kid Number:2244 If I change the number, the original number is displayed at the end, not the updated/modified number. I need the modified number to be displayed.
      Thanks in advance for any assistance!
      Jibberish
      NameNumber.txt
    • FMS
      By FMS
      Hello,
      As I was searching this forum I came along something intresting what was new to me.
      CUI/GUI hybrid.
      Whish sounds very usefull to me to compile it all into 1 script.
      So i was fideling around whit it but couldn't get it to work.
      In the real script (not this simplified version) i got a lot of functions whish i can use whan talking to it by commandline and switches.
      I could not get this to work and hope somebody could give me some pointers on how to make it work.
      Also I was hoping iff somebody could help me whit the /? function?
      (I don't know how to output the help text back to the commandline or the function that can help me do it)
      please advice and thanks in advanced.
      #AutoIt3Wrapper_UseUpx=n #AutoIt3Wrapper_UseX64=n #AutoIt3Wrapper_Change2CUI=y #include <Process.au3> #include <Array.au3> If $CmdLine[0] = 0 Then If _ProcessGetName(ProcessGetParent(@AutoItPID)) = "cmd.exe" Then ;ConsoleWrite("Program was started in CMD" & @CRLF) If Mod($CmdLine[0], 2) <> 0 Then Exit MsgBox(16, $sTitle, "Invalid number of parameters! has to be a multiple of 2!") If $CmdLine[0] = 0 Then Exit MsgBox(16, $sTitle, "No parameters passed!") For $i = 1 To $CmdLine[0] Step 2 If $CmdLine[$i] = "/switch" Then MsgBox(64, "Passed Parameters", "/switch is " & $CmdLine[$i+1]) If $CmdLine[$i] = "/?" Then MsgBox(64, "Passed Parameters", "/? " ) Next _ArrayDisplay($CmdLine) Else #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> $Form1 = GUICreate("Form1", 239, 65, 192, 124) $Button1 = GUICtrlCreateButton("Button1", 32, 24, 75, 25) $Button2 = GUICtrlCreateButton("Button2", 120, 24, 75, 25) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 button1() Case $button2 button2() EndSwitch WEnd EndIf EndIf Exit Func button1() MsgBox(16, "title", "button1()!") EndFunc Func button2() MsgBox(16, "title", "button1()!") EndFunc Func ProcessGetParent($i_PID) ;get PID from parent process done by SmOke_N Local $TH32CS_SNAPPROCESS = 0x00000002 Local $a_tool_help = DllCall("Kernel32.dll", "long", "CreateToolhelp32Snapshot", "int", $TH32CS_SNAPPROCESS, "int", 0) If IsArray($a_tool_help) = 0 Or $a_tool_help[0] = -1 Then Return SetError(1, 0, $i_PID) Local $tagPROCESSENTRY32 = _ DllStructCreate( _ "dword dwsize;" & _ "dword cntUsage;" & _ "dword th32ProcessID;" & _ "uint th32DefaultHeapID;" & _ "dword th32ModuleID;" & _ "dword cntThreads;" & _ "dword th32ParentProcessID;" & _ "long pcPriClassBase;" & _ "dword dwFlags;" & _ "char szExeFile[260]" _ ) DllStructSetData($tagPROCESSENTRY32, 1, DllStructGetSize($tagPROCESSENTRY32)) Local $p_PROCESSENTRY32 = DllStructGetPtr($tagPROCESSENTRY32) Local $a_pfirst = DllCall("Kernel32.dll", "int", "Process32First", "long", $a_tool_help[0], "ptr", $p_PROCESSENTRY32) If IsArray($a_pfirst) = 0 Then Return SetError(2, 0, $i_PID) Local $a_pnext, $i_return = 0 If DllStructGetData($tagPROCESSENTRY32, "th32ProcessID") = $i_PID Then $i_return = DllStructGetData($tagPROCESSENTRY32, "th32ParentProcessID") DllCall("Kernel32.dll", "int", "CloseHandle", "long", $a_tool_help[0]) If $i_return Then Return $i_return Return $i_PID EndIf While @error = 0 $a_pnext = DllCall("Kernel32.dll", "int", "Process32Next", "long", $a_tool_help[0], "ptr", $p_PROCESSENTRY32) If DllStructGetData($tagPROCESSENTRY32, "th32ProcessID") = $i_PID Then $i_return = DllStructGetData($tagPROCESSENTRY32, "th32ParentProcessID") If $i_return Then ExitLoop $i_return = $i_PID ExitLoop EndIf WEnd DllCall("Kernel32.dll", "int", "CloseHandle", "long", $a_tool_help[0]) Return $i_return EndFunc ;==>ProcessGetParent  
    • FrancescoDiMuro
      By FrancescoDiMuro
      Good morning
      I'm working on a little project, and I was wondering if there's a way ( sure there is ) to insert data to a ComboBox control everytime the user insert some text in the ComboBox which is not in the ComboBox data. I'll try to explain with an example:
      - Form with some data ( ComboBox is empty );
      - User prompt something in the ComboBox: if what the user prompts is not in the ComboBox values ( at the moment empty ), then insert the value in the ComboBox values, in order to have, next time the user prompts the form, the value that he entered.
      More pratical example:
      - First call of the form, ComboBox empty;
      - I prompt "A" in the ComboBox;
      - Second call, in the ComboBox I should see "A";
      - I prompt "B" in the ComboBox;
      - Third call, I should see "A"
                                                 "B";
      - And so on...
      Everytime the form is called, I re-create it, so I think I can't use _GUICtrlComboBox_AddStrings().
      I tried with
      Global $strCboStrings = "" ; When the user prompt the form, the code below is executed. ; I.E. : User prompt "A", after the if I should have "A"; ; In the second call, If I write "B", I should see "A" ; "B"; ; If I write "A" again, in the combobox values should not be any changes. If Not StringInStr($strCboStrings, GUICtrlRead($cboVoiceCategory)) <> 0 Then $strCboStrings &= $strCboStrings & "|" & GUICtrlRead($cboVoiceCategory) EndIf Any suggestion?
      Thanks