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

    • czardas
      Row Sum (Σ) Formula Validation
      By czardas
      Much work still needs to be done on my current project, but design concepts often benefit more from early criticism. Although there may be nothing particularly innovative about this project, user experience is everything. I would like you to look at the behaviour of the controls on this GUI. Unless you type something really awful, it allows you to finish typing the formula before testing the input. When typing into an edit control, pressing the enter key activates the okay button.
      The program itself, mainly consists of a listview control, which you can't see - just imagine it looks like a stone age version of Excel with a nice paint job, but no bells or whistles. What Row Sum (Σ) is intended to do is loop through all the rows, calculate a sum and print the output in a newly created column. The user is prompted to type a formula into the following GUI. Please try to figure it out, and break it any way you can.
      #include <GUIConstants.au3> #include <GuiEdit.au3> #include <Misc.au3> Global $g_iAvailableCols = 24 ; arbitary dev variable [column count will eventually be read from a listview control] ; missing several thousand lines of code... Formula() ; caution about including columns containing empty fields in the formula ; empty fields are treated as zero ; with addition and subtraction there is never any problem ; multiplication by an empty field (or by zero) returns zero ; division by an empty field (or by zero) returns an empty field [unless - see exception] ; use of the power operator is limited to rows in which all referenced fields contain numbers ; imaginary roots of negative numbers return an empty field [unless - see exception] ; exception: infinity (or an imaginary number) to the power of zero returns a meaningless number Func FormulaSyntax() MsgBox(BitOR(64, 8192), "Row Sum (" & ChrW(0x03A3) & ") : Syntax To Use", _ ; $MB_ICONINFORMATION, $MB_TASKMODAL " mathematical operators :" & @TAB & "+ - * / ^" & @CRLF & _ " column numbers :" & @TAB & @TAB & "c1, c2, c3 etc..." & @CRLF & _ " decimal digits :" & @TAB & @TAB & "0 to 9 and ." & @CRLF & _ " parenthesis :" & @TAB & @TAB & "( )" & @CRLF & _ " minus sign :" & @TAB & @TAB & "-1, -c2, -(c3) etc..." & @CRLF & _ " example :" & @TAB & @TAB & @TAB & "c1 +c2 -c3") EndFunc ;==> FormulaSyntax Func Formula() ; ($hParent, $idListView, $hListView) ; [missing parent window] Local $sTitle = "Row Sum (" & ChrW(0x03A3) & ")", _ $iStyle = BitOR($WS_CAPTION, $WS_POPUP, $WS_SYSMENU), _ $iExStyle = BitOR($WS_EX_MDICHILD, $WS_EX_TOOLWINDOW, $WS_EX_TOPMOST) Local $hChild = GUICreate($sTitle, 334 +25, 105 +1, Default + 100, Default + 100); , $iStyle, $iExStyle, $hParent) Local $hLabel = GUICtrlCreateLabel("Formula :", 8, 8, 55, 18) GUICtrlSetFont(-1, 10) Local $hSyntax = GUICtrlCreateButton("???", 72, 7, 40, 20) Local $hLabel = GUICtrlCreateLabel("Header :", 127, 8, 49, 18) GUICtrlSetFont(-1, 10) Local $hHeader = GUICtrlCreateInput("", 182, 7, 170, 20) GUICtrlSetFont(-1, 10) Local $hInput = GUICtrlCreateInput("", 7, 33, 320 +25, 40, BitOR($WS_TABSTOP, $ES_MULTILINE)) GUICtrlSetFont(-1, 10) Local $hCheckBox = GUICtrlCreateCheckbox(" Round to", 7, 79, 75, 20) GUICtrlSetFont(-1, 10) Local $hPlaces = GUICtrlCreateInput("2", 86, 79 +1, 20, 20, BitOR($WS_TABSTOP, $ES_CENTER, $ES_NUMBER)) GUICtrlCreateLabel("decimal places", 114 -2, 79 +2, 92, 18) GUICtrlSetFont(-1, 10) Local $hCancel = GUICtrlCreateButton("Cancel", 210, 79 +1, 66, 20) Local $hOkay = GUICtrlCreateButton("OK", 285, 79 +1, 66, 20) GUISetState(@SW_SHOW) Local $sInput = "", $aArray, $iError = 0, $iCols = $g_iAvailableCols ; $iCols = _GUICtrlListView_GetColumnCount($hListView), _ ; >>> CHANGE THIS LATER ;$iRows = _GUICtrlListView_GetItemCount($hListView), $aColOrder = _GUICtrlListView_GetColumnOrderArray($hListView) Local $vTemp, $msg2, $iPlaces = '2' While 1 $msg2 = GUIGetMsg() If $msg2 = $hCancel Or $msg2 = $GUI_EVENT_CLOSE Then ExitLoop If $msg2 = $hSyntax Then FormulaSyntax() ContinueLoop EndIf $vTemp = GUICtrlRead($hPlaces) If $vTemp <> $iPlaces Then If $vTemp > 14 Then GUICtrlSetData($hPlaces, 14) $iPlaces = 14 _GUICtrlEdit_SetSel($hPlaces, 0, -1) ElseIf Not $vTemp Then GUICtrlSetData($hPlaces ,'0') $iPlaces = '0' _GUICtrlEdit_SetSel($hPlaces, 0, -1) EndIf EndIf If BitAND(GUICtrlRead($hCheckBox), $GUI_CHECKED) == $GUI_CHECKED _ And BitAND(GUICtrlGetState($hPlaces), $GUI_DISABLE) == $GUI_DISABLE Then GUICtrlSetState($hPlaces, $GUI_ENABLE) ElseIf BitAND(GUICtrlRead($hCheckBox), $GUI_CHECKED) <> $GUI_CHECKED _ And BitAND(GUICtrlGetState($hPlaces), $GUI_ENABLE) == $GUI_ENABLE Then GUICtrlSetState($hPlaces, $GUI_DISABLE) EndIf $sFormula = GUICtrlRead($hInput) If $sFormula <> $sInput Then If StringRegExp($sFormula, '[^ ]') Then ; spaces between components are ignored If Not ValidSyntax($sFormula, $iCols) Then If @extended < 5 Then If $iError = 0 Then GUICtrlSetBkColor($hInput, 0xFFA090) $iError = 1 ElseIf $iError Then GUICtrlSetBkColor($hInput, 0xFFFFFF) $iError = 0 EndIf ElseIf $iError Then GUICtrlSetBkColor($hInput, 0xFFFFFF) $iError = 0 EndIf ElseIf $iError Then GUICtrlSetBkColor($hInput, 0xFFFFFF) $iError = 0 EndIf $sInput = $sFormula EndIf ; BitAND(WinGetState($hChild), $WIN_STATE_ACTIVE) = 8 If $msg2 = $hOkay Or (_IsPressed("0D") And BitAND(WinGetState($hChild), 8) = 8 And (ControlGetFocus($hChild) = "Edit2" Or ControlGetFocus($hChild) = "Edit1")) Then $sFormula = GUICtrlRead($hInput) ; If StringRegExp($sFormula, '[^ ]') And ValidSyntax($sFormula, $iCols) Then ; missing formula execution code MsgBox(0, "VALID SYNTAX", "Well done, your formula can safely be executed, but" & @CRLF & "can't find parent window.") ExitLoop Else Switch @extended Case 1 $vTemp = "The formula contains illegal characters." Case 2 $vTemp = "No such column exists." Case 3 $vTemp = "The formula contains a syntax error." Case 4 $vTemp = "The formula is missing opening parenthesis." Case 5 $vTemp = "The formula is unterminated" case 6 $vTemp = "The formula is missing closing parenthesis." EndSwitch MsgBox(262160, "uh-uh!", StringRegExp($sFormula, '[^ ]') ? $vTemp : "Please enter a formula.") While _IsPressed("0D") Sleep(50) WEnd ;$iError = 1 EndIf EndIf WEnd GUIDelete($hChild) EndFunc ; formula Func ValidSyntax($sFormula, $iMax) ; [currently requires external check that string <> ""] ; quick test for accepted characters If StringRegExp($sFormula, '(?i)[^c \d\.\+\-\*/\^\(\)]') Then Return SetExtended(1, False) ; illegal characters If StringRegExp($sFormula, '(?i)\.\D|c[0\D]|\d\s+[\.\d]') Then Return SetExtended(3, False) ; syntax $sFormula = StringStripWS($sFormula, 8) ; strip all spaces ; split to separate formula components Local $aFormula = StringRegExp($sFormula, '(?i)\-?c\d+|\-?c|\-?\d*\.\d*|\-?\d+|\-\(|[\+\-\*/\^\(\)]|.+', 3), _ ; create array [ADDED] ==> |.+ $iLast, $sTest, $sExpect = '(?i)\-?\(|\-?c\d+|\-?c|\-?\d*\.\d*|\-?\d+|\-', _ ; valid first component $iBracket = 0, $bSyntax = False, $bNoSuch = False, $bTermination = False ; error tracking variables For $i = 0 To UBound($aFormula) -1 If Not StringRegExp($aFormula[$i], $sExpect) Then ; unexpected code sequence $bSyntax = True ExitLoop EndIf If StringRegExp($aFormula[$i], '(?i)\-?c\d+') Then ; column number $sTest = StringRegExpReplace($aFormula[$i], '(?i)[\-c]+', '') If $sTest > $iMax Or $sTest == 0 Then ; no such column exists $bNoSuch = True ExitLoop EndIf $sExpect = '[\+\-\*/\^\)]' ; operators / closing brackets ElseIf StringRegExp($aFormula[$i], '\-?\d*\.\d*') Then ; decimal If $aFormula[$i] == '.' Or $aFormula[$i] == '-.' Then If $i = UBound($aFormula) -1 Then $bTermination = True ExitLoop EndIf $bSyntax = True ; badly formated decimal ExitLoop EndIf $sExpect = '[\+\-\*/\^\)]' ; as above ElseIf StringRegExp($aFormula[$i], '\-?\d+') Then ; integer $sExpect = '[\+\-\*/\^\)]' ElseIf StringRegExp($aFormula[$i], '\A[\+\-\*/\^]\z') Then ; operator $iLast = UBound($aFormula) -1 If $i = $iLast Or ($i = $iLast -1 And $aFormula[$iLast] == '-') Then $bTermination = True ExitLoop EndIf $sExpect = '(?i)\-?\(|\-?c\d+|\-?c|\-?\d*\.\d*|\-?\d+' ElseIf $aFormula[$i] == '(' Or $aFormula[$i] == '-(' Then ; opening bracket $iBracket += 1 $sExpect = '(?i)\-?\(|\-?c\d+|\-?c|\-?\d*\.\d*|\-?\d+|\-' ElseIf $aFormula[$i] == ')' Then ; closing bracket $iBracket -= 1 $sExpect = '[\+\-\*/\^\)]' ElseIf $aFormula[$i] = 'c' Or $aFormula[$i] = '-c' Then ; unterminated column number If $i = UBound($aFormula) -1 Then $bTermination = True Else $bSyntax = True ExitLoop EndIf Else ; unexpected exception [this should never happen] $bSyntax = True ExitLoop EndIf If $iBracket < 0 Then ExitLoop ; closing (unopened) parenthesis error ; [formula looks okay so far] Next ; better to be a bit wordy [for clarity] If $bNoSuch Then Return SetExtended(2, False) ; no such column exists If $bSyntax Then Return SetExtended(3, False) ; syntax error If $iBracket < 0 Then Return SetExtended(4, False) ; missing opening parenthesis If $bTermination Then Return SetExtended(5, False) ; formula may not terminate with operator or c If $iBracket > 0 Then Return SetExtended(6, False) ; missing closing parenthesis ; ConsoleWrite('valid' & @LF) Return True ; formula is correct EndFunc ;==> ValidSyntax  
    • Morthawt
      Utilising existing GUI code in koda.
      By Morthawt
      I have a program I made long ago for something but I never saved the koda file so it would make it a complete pain for me to visually tweak anything because as far as I am aware, I would have to design an entirely new GUI.
      Would it be possible for you guys at AutoIt to add functionality to Koda so that you can take an existing GUI section, with while loop and cases and all and then koda would literally build it ready for tweaking and where existing things still exist and have been tweaked, it would tweak such details and keep all the existing case information and added formatting things that were manually tweaked etc?
      This would be really amazing and I feel that other people would benefit from it. I can't be the only person who makes a GUI, doesn't save it and then has no problems making minor tweaks in-code but struggles like hell to go rearranging things perfectly. That is where using a GUI (koda) to make and arrange a GUI you are making, makes everything easy and pleasure to deal with.
      tldr;
      Example:
      A friend gives me his code and wants help. The GUI is just a mess, but trying to do all the alignment and positioning all by digits in code would be a pain. I cannot just hallucinate where everything is based on pixel locations and sizes. So I would take the entire GUI chunk of code, all the form/controls/formatting functions/while loop/switch/case in it's entirety and paste it into an area of Koda and press a button. Koda would then build the GUI on the screen, placing all the controls and formatting them with the instructions that may have been added and keeps the case information as-is. Then when you make your alterations in Koda, you go to export it and it makes an entirely new export that re-makes (from scratch as if you had made this GUI from scratch) all the code for controls, size, placement etc and then also adds all the existing case code back as part of the code you then send (or manually copy/paste as I do) to Scite editor.
      Is there any chance this could be implemented? I think this could help a lot of people with their own scripts and others'.
    • Miliardsto
      Buttons and labels in tabs
      By Miliardsto
      Hello I got problem with my form cause i got some buttons, labels, inputs and now i want organize this in tabs.
      There is a problem, when i put new tab this tab is on bottom and this is above my buttons or button is show on whole form , not only in one tab.
      How to deal with it
    • ruslanas402
      Open webpages by checking boxes
      By ruslanas402
      Hello everyone, don't even know how to ask.  My code is:
      #include <String.au3> #include <IE.au3> #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> $Form1 = GUICreate("Form1", 700, 500, 192, 124) $Button1 = GUICtrlCreateButton("View", 576, 24, 89, 41) Global $oIE = _IECreate("https://www.youtube.com/playlist?list=PL4Jcq5zn02jKpjX0nqI1_fS7mEEb5tw6z", 1, 1, 0) Sleep(1000) Global $sHTML = _IEDocReadHTML($oIE) $FirstChunks = _StringBetween($sHTML, 'pl-video-title-link yt-uix-tile-link yt-uix-sessionlink', '<div class="pl-video-owner') $x = 16 For $a In $FirstChunks $actualdata = _StringBetween($a, '">', '</a>') ;$actualdata2 = _StringBetween($a, 'href="', '&amp;') $Checkbox1 = GUICtrlCreateCheckbox($actualdata[0], 24, $x, 500, 17) $x = $x + 20 Next GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Somehow I need to open webpages where checkbox is checked by presing button view, I think I need somehow asign $actualdata with $actualdata2. Any ideas would be very appreciated
    • rm4453
      Custom Stream GUI Using Autoit Gui Wrap
      By rm4453
      Hey guys! I need to find a way to wrap an autoit gui around a game. I am planning on making a custom gui overlay for interacting with my stream, which will allow me to run giveaways and stuff like that. But I need to find a way to force the steam games to run inside my autoit gui... I have the following code so far credit to those I took code from and modified to suite my needs "can't remember who u are pls post if i owe ty to u" If I select notepad and launch it then it works great! and the notepad window is wrapped inside my gui. However if I try it with teamfortress 2 it won't work...
       
      #include <Array.au3> #include <File.au3> #include <WinAPI.au3> #include <GUIConstants.au3> Local $msg, $hwnd, $WinHwnd ;===> UDV Start $pid = 0 $Hidden = 0 $exe = 0 $sDrive = 0 $sDir = 0 $sFileName = 0 $sExtension = 0 ;===> UDV End $hwnd = GUICreate("hello") $Open = GUICtrlCreateButton("Launch Game", 10, 30, 75, 25) $Select = GUICtrlCreateButton("Select Game", 10,60,75,25) GUISetState() ;===> UDF START Func _GetWinHwnd($pid) $aWinlist = WinList() For $i = 1 To $aWinlist[0][0] If $pid = WinGetProcess($aWinlist[$i][0]) Then Return $aWinlist[$i][0] Next EndFunc ;==>_GetWinHwnd Func _SetParentWindow($pid) $WinInfo = _GetWinHwnd($pid) $WinHwnd = ControlGetHandle($WinInfo, "", "") _WinAPI_SetParent($WinHwnd, $hwnd) _WinAPI_SetWindowLong($WinHwnd, $GWL_STYLE, $WS_POPUP + $WS_VISIBLE) WinMove($WinHwnd, "", 0, 0) EndFunc ;==>_SetParentWindow Func RedrawGui($RedrawMe) If ProcessExists($pid) And $Hidden = 0 Then GUICtrlSetState($RedrawMe, @SW_HIDE) $Hidden = 1 sleep(50) _WinAPI_RedrawWindow($pid) Sleep(50) ElseIf $Hidden = 1 And Not ProcessExists($pid) Then GUICtrlSetState($RedrawMe, @SW_SHOW) $Hidden = 0 EndIf EndFunc ;===> UDF END While 1 $msg = GUIGetMsg() Switch $msg Case $GUI_EVENT_CLOSE If ProcessExists($pid) Then ProcessClose($pid) GUICtrlSetState($Open, @SW_SHOW) Else Exit EndIf Case $Open GUICtrlSetState($Open, @SW_HIDE) Sleep(100) $pid = Run('"' & $exe & '" -game tf -steam') #cs This RUN CMD is custom made for testing with TF2 change to just $exe to select any exe you want to test with -game tf specifies to launch tf2 and -steam gets rid of insecure mode error #ce RedrawGui($Open) ProcessWait($pid) Sleep(5500) _GetWinHwnd($pid) _SetParentWindow($pid) Case $Select $exe = FileOpenDialog("Please select your game!", @ScriptDir, "Executable File (*.exe)", "1", "Process Selection") Sleep(50) FileChangeDir(@ScriptDir) _PathSplit($exe, $sDrive, $sDir, $sFileName, $sExtension) EndSwitch WEnd