Jump to content

GUI Delete tab not deleting elements correctly


Recommended Posts

I'm trying to solve 2 issues here and I'm pretty sure the two hinge on the same issue... the index that is assigned to them..

I'm trying to make it so when you delete a tab, the tab and its elements are removed, but in my script, the tab is removed, but the elements from the page that was deleted remain. I tried deleting the elements by the index, but when I do, the elements completely disappear.

The other problem I'm trying to solve is that when I perform a second search (enter a parameter and hit enter) the script just crashes. I added a check to the script to make sure the guitab is created and if it is, count the number of tabs so I can increase the index by the count of the tabs, but that isn't work either. Anyone dealt with anything like this before?

#include <GUITab.au3>
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <Array.au3>
#include <GUIListView.au3>


;Begin Main Gui
Global $Home = GUICreate("Welcome", 635, 477, 192, 114, $WS_MAXIMIZEBOX)

;Menus
$MenuFile = GUICtrlCreateMenu("File")
$Start = GUICtrlCreateMenuItem("Start", $MenuFile)
GUICtrlCreateMenuItem("", $MenuFile) ; Create a separator line
$ExitMenu = GUICtrlCreateMenuItem("Exit", $MenuFile)
GUISetState(@SW_SHOW)
WinSetState($Home, '', @SW_MAXIMIZE)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE, $ExitMenu
            Exit
        Case $Start
            Example()
    EndSwitch
WEnd

Func Example()
    local $idDeleteTab, $tabs, $buildtab=0
    $MainForm = GUICreate("Test", 925, 327, 192, 114, -1, $WS_EX_MDICHILD, $Home)
    $TypeLabel = GUICtrlCreateLabel("Search Type", 8, 8, 65, 17)
    $SearchInput = GUICtrlCreateCombo("", 16, 26, 257, 25)
    GUICtrlSetData(-1, "Name|ID")
    $InputValLabel = GUICtrlCreateLabel("Input Value", 8, 56, 58, 17)
    $InputVal = GUICtrlCreateInput("", 16, 80, 257, 21)
    $StartSearch = GUICtrlCreateButton("Search", 8, 284, 75, 25)
    $aLabel = GUICtrlCreateLabel("Date", 8, 112, 84, 17)
    $aInput = GUICtrlCreateDate("", 19, 132, 259, 21, (0x00))
    $aReportBox = GUICtrlCreateCheckbox("Generate report", 11, 168, 169, 17)
    GUICtrlSetState(-1, $GUI_HIDE)
    $MarkDead = GUICtrlCreateCheckbox("Mark Dead", 11, 192, 169, 17)
    GUICtrlSetState(-1, $GUI_HIDE)
    $UserOutput = GUICtrlCreateButton("Output", 188, 284, 75, 25)
    GUICtrlSetState($UserOutput, $GUI_HIDE)
    $bEnterDummy = GUICtrlCreateDummy()
    Local $bAccelKeys[1][2] = [["{ENTER}", $bEnterDummy]]
    GUISetAccelerators($bAccelKeys)

    GUISetState(@SW_SHOW)

    While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE, $ExitMenu
                GUIDelete($MainForm)
                ExitLoop
            Case $StartSearch, $bEnterDummy
                If GUICtrlRead($InputVal) = "" Then
                    MsgBox(0, "ERROR", "You must input a parameter")
                Else
                    SplashTextOn("Processing...", "Processing" & @CRLF & @CRLF & "Please wait", 200, 150, Default, Default, 1, Default, 25)
                    $type = GUICtrlRead($SearchInput)
                    $Parameter = GUICtrlRead($InputVal)
                    GUICtrlSetData($InputVal, "")
                    Local $IDs[2][2] = [["1", "A"], ["2", "B"]]
                    SplashOff()
                    If UBound($IDs) > 0 Then
                        SplashTextOn("Processing...", "Processing" & @CRLF & @CRLF & "Please wait", 200, 150, Default, Default, 1, Default, 25)
                        $AcctResults = GUICreate("", 620, 344, 294, 0, $WS_CHILD, -1, $MainForm)
                        If $buildtab=0 then
                            $Tabs=GUICtrlCreateTab(0, 10, 609, 300)
                            $buildtab=1
                            $nTabCount=0
                        Else
                            $nTabCount=_GUICtrlTab_GetItemCount($Tabs)
                        EndIf
                        Local $ResultList[UBound($IDs)+$nTabCount]
                        Local $Tab[UBound($IDs)+$nTabCount]
                        local $NameLabel[UBound($IDs)+$nTabCount]
                        $idContextmenu = GUICtrlCreateContextMenu($Tabs)
                        $idDeleteTab = GUICtrlCreateMenuItem("Delete Current Tab", $idContextmenu)

                        ;Loop for each Result
                        For $p = 0+$nTabCount To UBound($IDs)+$nTabCount - 1
                            Local $Fullresult[3][7] = [[Random(1, 10), "Tester", "123456", GUICtrlRead($aInput), '', '', ''], ["Hello", "There", "My", "Fine", "Friend", "", ""], ["GoodBye", "There", "My", "Hated", "Enemy", "", ""]]
                            $Tab[$p+$nTabCount] = GUICtrlCreateTabItem($Fullresult[0][0])
                            $ResultList[$p+$nTabCount] = GUICtrlCreateListView("", 7, 128, 594, 174,$LVS_EDITLABELS)
                            _GUICtrlListView_AddColumn($ResultList[$p+$nTabCount], 'Col0')
                            _GUICtrlListView_AddColumn($ResultList[$p+$nTabCount], 'Col1')
                            _GUICtrlListView_AddColumn($ResultList[$p+$nTabCount], 'Col2')
                            _GUICtrlListView_AddColumn($ResultList[$p+$nTabCount], 'Col3')
                            _GUICtrlListView_AddColumn($ResultList[$p+$nTabCount], 'Col4')
                            _GUICtrlListView_AddColumn($ResultList[$p+$nTabCount], 'Col5')
                            _GUICtrlListView_AddColumn($ResultList[$p+$nTabCount], 'Col6')
                            $NameLabel[$p+$nTabCount] = GUICtrlCreateLabel($Fullresult[0][0], 8, 67, 260, 17)
                            Local $aWriter = $Fullresult
                            _ArrayDelete($aWriter, 0)
                            _GUICtrlListView_AddArray($ResultList[$p], $aWriter)
                            GUICtrlCreateTabItem("")
                        Next
                        Hide(1, $aLabel, $aInput, $UserOutput, $aReportBox, $MarkDead)
                        SplashOff()
                        GUISetState(@SW_SHOW)
                        While 2
                            ExitLoop
                        WEnd
                    EndIf
                EndIf
            Case $idDeleteTab
                If $tabs Then
                    _GUICtrlTab_DeleteItem($Tabs,GUICtrlRead($tabs))
                EndIf
        EndSwitch
    WEnd
EndFunc   ;==>Example

Func Hide($toggle, $aLabel, $aInput, $UserOutput, $aReportBox, $MarkDead)
    GUICtrlSetState($aLabel, $toggle = 1 ? $GUI_SHOW : $GUI_HIDE)
    GUICtrlSetState($aInput, $toggle = 1 ? $GUI_SHOW : $GUI_HIDE)
    GUICtrlSetState($UserOutput, $toggle = 1 ? $GUI_SHOW : $GUI_HIDE)
    GUICtrlSetState($aReportBox, $toggle = 1 ? $GUI_SHOW : $GUI_HIDE)
    GUICtrlSetState($MarkDead, $toggle = 1 ? $GUI_SHOW : $GUI_HIDE)
EndFunc   ;==>Hide
Link to comment
Share on other sites

  • Moderators

Jewtus,

 

in my script, the tab is removed, but the elements from the page that was deleted remain

And why would you expect anything else? AutoIt manages the show/hide of the native controls created within the tab structure, but merely deleting the TabItem does not delete the controls within it. You will have to store the ControlIDs of the controls and delete them yourself as part of the tab deletion code. :)

As to the crash, I get an "array subscript out of bounds" error when I try a second search - so I suggest you check the bounds of the various arrays you are using when creating the tabs. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

And why would you expect anything else? AutoIt manages the show/hide of the native controls created within the tab structure, but merely deleting the TabItem does not delete the controls within it. You will have to store the ControlIDs of the controls and delete them yourself as part of the tab deletion code. :)

I've tried using 

GUICtrlDelete($ResultList[GUICtrlRead($tabs)])
                    GUICtrlDelete($NameLabel[GUICtrlRead($tabs)])

and it deletes the elements, but if I delete the first tab, all the elements disappear. I assume this is because now the tab ID is 0 and the other elements are 1 (if there are two tabs). Try this code and delete the 2nd tab... it works fine, but if you delete the first tab, everything disappears.

#include <GUITab.au3>
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <Array.au3>
#include <GUIListView.au3>


;Begin Main Gui
Global $Home = GUICreate("Welcome", 635, 477, 192, 114, $WS_MAXIMIZEBOX)

;Menus
$MenuFile = GUICtrlCreateMenu("File")
$Start = GUICtrlCreateMenuItem("Start", $MenuFile)
GUICtrlCreateMenuItem("", $MenuFile) ; Create a separator line
$ExitMenu = GUICtrlCreateMenuItem("Exit", $MenuFile)
GUISetState(@SW_SHOW)
WinSetState($Home, '', @SW_MAXIMIZE)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE, $ExitMenu
            Exit
        Case $Start
            Example()
    EndSwitch
WEnd

Func Example()
    local $idDeleteTab, $tabs, $buildtab=0
    $MainForm = GUICreate("Test", 925, 327, 192, 114, -1, $WS_EX_MDICHILD, $Home)
    $TypeLabel = GUICtrlCreateLabel("Search Type", 8, 8, 65, 17)
    $SearchInput = GUICtrlCreateCombo("", 16, 26, 257, 25)
    GUICtrlSetData(-1, "Name|ID")
    $InputValLabel = GUICtrlCreateLabel("Input Value", 8, 56, 58, 17)
    $InputVal = GUICtrlCreateInput("", 16, 80, 257, 21)
    $StartSearch = GUICtrlCreateButton("Search", 8, 284, 75, 25)
    $aLabel = GUICtrlCreateLabel("Date", 8, 112, 84, 17)
    $aInput = GUICtrlCreateDate("", 19, 132, 259, 21, (0x00))
    $aReportBox = GUICtrlCreateCheckbox("Generate report", 11, 168, 169, 17)
    GUICtrlSetState(-1, $GUI_HIDE)
    $MarkDead = GUICtrlCreateCheckbox("Mark Dead", 11, 192, 169, 17)
    GUICtrlSetState(-1, $GUI_HIDE)
    $UserOutput = GUICtrlCreateButton("Output", 188, 284, 75, 25)
    GUICtrlSetState($UserOutput, $GUI_HIDE)
    $bEnterDummy = GUICtrlCreateDummy()
    Local $bAccelKeys[1][2] = [["{ENTER}", $bEnterDummy]]
    GUISetAccelerators($bAccelKeys)

    GUISetState(@SW_SHOW)

    While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE, $ExitMenu
                GUIDelete($MainForm)
                ExitLoop
            Case $StartSearch, $bEnterDummy
                If GUICtrlRead($InputVal) = "" Then
                    MsgBox(0, "ERROR", "You must input a parameter")
                Else
                    SplashTextOn("Processing...", "Processing" & @CRLF & @CRLF & "Please wait", 200, 150, Default, Default, 1, Default, 25)
                    $type = GUICtrlRead($SearchInput)
                    $Parameter = GUICtrlRead($InputVal)
                    GUICtrlSetData($InputVal, "")
                    Local $IDs[2][2] = [["1", "A"], ["2", "B"]]
                    SplashOff()
                    If UBound($IDs) > 0 Then
                        SplashTextOn("Processing...", "Processing" & @CRLF & @CRLF & "Please wait", 200, 150, Default, Default, 1, Default, 25)
                        $AcctResults = GUICreate("", 620, 344, 294, 0, $WS_CHILD, -1, $MainForm)
                        If $buildtab=0 then
                            $Tabs=GUICtrlCreateTab(0, 10, 609, 300)
                            $buildtab=1
                            $nTabCount=0
                        Else
                            $nTabCount=_GUICtrlTab_GetItemCount($Tabs)
                        EndIf
                        Local $ResultList[UBound($IDs)+$nTabCount]
                        Local $Tab[UBound($IDs)+$nTabCount]
                        local $NameLabel[UBound($IDs)+$nTabCount]
                        $idContextmenu = GUICtrlCreateContextMenu($Tabs)
                        $idDeleteTab = GUICtrlCreateMenuItem("Delete Current Tab", $idContextmenu)

                        ;Loop for each Result
                        For $p = 0+$nTabCount To UBound($IDs)+$nTabCount - 1
                            Local $Fullresult[3][7] = [[Random(1, 10), "Tester", "123456", GUICtrlRead($aInput), '', '', ''], ["Hello", "There", "My", "Fine", "Friend", "", ""], ["GoodBye", "There", "My", "Hated", "Enemy", "", ""]]
                            $Tab[$p+$nTabCount] = GUICtrlCreateTabItem($Fullresult[0][0])
                            $ResultList[$p+$nTabCount] = GUICtrlCreateListView("", 7, 128, 594, 174,$LVS_EDITLABELS)
                            _GUICtrlListView_AddColumn($ResultList[$p+$nTabCount], 'Col0')
                            _GUICtrlListView_AddColumn($ResultList[$p+$nTabCount], 'Col1')
                            _GUICtrlListView_AddColumn($ResultList[$p+$nTabCount], 'Col2')
                            _GUICtrlListView_AddColumn($ResultList[$p+$nTabCount], 'Col3')
                            _GUICtrlListView_AddColumn($ResultList[$p+$nTabCount], 'Col4')
                            _GUICtrlListView_AddColumn($ResultList[$p+$nTabCount], 'Col5')
                            _GUICtrlListView_AddColumn($ResultList[$p+$nTabCount], 'Col6')
                            $NameLabel[$p+$nTabCount] = GUICtrlCreateLabel($Fullresult[0][0], 8, 67, 260, 17)
                            Local $aWriter = $Fullresult
                            _ArrayDelete($aWriter, 0)
                            _GUICtrlListView_AddArray($ResultList[$p], $aWriter)
                            GUICtrlCreateTabItem("")
                        Next
                        Hide(1, $aLabel, $aInput, $UserOutput, $aReportBox, $MarkDead)
                        SplashOff()
                        GUISetState(@SW_SHOW)
                        While 2
                            ExitLoop
                        WEnd
                    EndIf
                EndIf
            Case $idDeleteTab
                If $tabs Then
                    GUICtrlDelete($ResultList[GUICtrlRead($tabs)])
                    GUICtrlDelete($NameLabel[GUICtrlRead($tabs)])
                    _GUICtrlTab_DeleteItem($Tabs,GUICtrlRead($tabs))
                EndIf
        EndSwitch
    WEnd
EndFunc   ;==>Example

Func Hide($toggle, $aLabel, $aInput, $UserOutput, $aReportBox, $MarkDead)
    GUICtrlSetState($aLabel, $toggle = 1 ? $GUI_SHOW : $GUI_HIDE)
    GUICtrlSetState($aInput, $toggle = 1 ? $GUI_SHOW : $GUI_HIDE)
    GUICtrlSetState($UserOutput, $toggle = 1 ? $GUI_SHOW : $GUI_HIDE)
    GUICtrlSetState($aReportBox, $toggle = 1 ? $GUI_SHOW : $GUI_HIDE)
    GUICtrlSetState($MarkDead, $toggle = 1 ? $GUI_SHOW : $GUI_HIDE)
EndFunc   ;==>Hide

I know that crashes due to the bounds but I can't seem to figure it out (maybe its because I'm trying to solve both these issues at once). Once I figure out the deletion, I'll take another look at all my bounds to see what exactly is going on.

Link to comment
Share on other sites

  • Moderators

Jewtus,

maybe its because I'm trying to solve both these issues at once

I was about to suggest writing a simpler script so that you can deal with these issues separately - it looks like you have come to the same conclusion. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

  • Moderators

Jewtus,

My apologies - AutoIt does delete the controls within a tab when you delete the tab: :o

#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>

Global $aTab[1] = [0]

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

$cAdd = GUICtrlCreateButton("Add", 10, 10, 80, 30)
$cDel = GUICtrlCreateButton("Delete", 10, 50, 80, 30)
GUICtrlSetState($cDel, $GUI_DISABLE)

$cTab = GUICtrlCreateTab(100, 10, 300, 300)


GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $cAdd
            GUICtrlSetState($cDel, $GUI_ENABLE)
            $aTab[0] += 1
            ReDim $aTab[$aTab[0] + 1]
            $aTab[$aTab[0]] = GUICtrlCreateTabItem("Tab " & $aTab[0])
            GUICtrlCreateButton("Button " & $aTab[0], 100 + (40 * $aTab[0]), 40 + (40 * $aTab[0]), 80, 30)
            GUICtrlCreateTabItem("")
        Case $cDel
            $iIndex = GUICtrlRead($cTab) + 1
            GUICtrlDelete($aTab[$iIndex])
    EndSwitch
WEnd
So you should be able to do it too. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

Any Idea why these ones wouldn't be deleting then?

I think I figured out how to resolve the other issue (rather than try to handle them all as Ubounds, I just read the tabs and append them to the original array that is passed into the loop), but it seems like when I use _GuiCtrlTab_Destroy($tabs) it doesn't let me recreate the tabs.

#include <GUITab.au3>
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <Array.au3>
#include <GUIListView.au3>


;Begin Main Gui
Global $Home = GUICreate("Welcome", 635, 477, 192, 114, $WS_MAXIMIZEBOX)

;Menus
$MenuFile = GUICtrlCreateMenu("File")
$Start = GUICtrlCreateMenuItem("Start", $MenuFile)
GUICtrlCreateMenuItem("", $MenuFile) ; Create a separator line
$ExitMenu = GUICtrlCreateMenuItem("Exit", $MenuFile)
GUISetState(@SW_SHOW)
WinSetState($Home, '', @SW_MAXIMIZE)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE, $ExitMenu
            Exit
        Case $Start
            Example()
    EndSwitch
WEnd

Func Example()
    local $idDeleteTab, $tabs, $buildtab=0
    $MainForm = GUICreate("Test", 925, 327, 192, 114, -1, $WS_EX_MDICHILD, $Home)
    $TypeLabel = GUICtrlCreateLabel("Search Type", 8, 8, 65, 17)
    $SearchInput = GUICtrlCreateCombo("", 16, 26, 257, 25)
    GUICtrlSetData(-1, "Name|ID")
    $InputValLabel = GUICtrlCreateLabel("Input Value", 8, 56, 58, 17)
    $InputVal = GUICtrlCreateInput("", 16, 80, 257, 21)
    $StartSearch = GUICtrlCreateButton("Search", 8, 284, 75, 25)
    $aLabel = GUICtrlCreateLabel("Date", 8, 112, 84, 17)
    $aInput = GUICtrlCreateDate("", 19, 132, 259, 21, (0x00))
    $aReportBox = GUICtrlCreateCheckbox("Generate report", 11, 168, 169, 17)
    GUICtrlSetState(-1, $GUI_HIDE)
    $MarkDead = GUICtrlCreateCheckbox("Mark Dead", 11, 192, 169, 17)
    GUICtrlSetState(-1, $GUI_HIDE)
    $UserOutput = GUICtrlCreateButton("Output", 188, 284, 75, 25)
    GUICtrlSetState($UserOutput, $GUI_HIDE)
    $bEnterDummy = GUICtrlCreateDummy()
    Local $bAccelKeys[1][2] = [["{ENTER}", $bEnterDummy]]
    GUISetAccelerators($bAccelKeys)

    GUISetState(@SW_SHOW)

    While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE, $ExitMenu
                GUIDelete($MainForm)
                ExitLoop
            Case $StartSearch, $bEnterDummy
                If GUICtrlRead($InputVal) = "" Then
                    MsgBox(0, "ERROR", "You must input a parameter")
                Else
                    SplashTextOn("Processing...", "Processing" & @CRLF & @CRLF & "Please wait", 200, 150, Default, Default, 1, Default, 25)
                    $type = GUICtrlRead($SearchInput)
                    $Parameter = GUICtrlRead($InputVal)
                    GUICtrlSetData($InputVal, "")
                    Local $IDs[2][2] = [["1", "A"], ["2", "B"]]
                    SplashOff()
                    If UBound($IDs) > 0 Then
                        SplashTextOn("Processing...", "Processing" & @CRLF & @CRLF & "Please wait", 200, 150, Default, Default, 1, Default, 25)
                        $AcctResults = GUICreate("", 620, 344, 294, 0, $WS_CHILD, -1, $MainForm)
                        If $buildtab=0 then
                            $Tabs=GUICtrlCreateTab(0, 10, 609, 300)
                            $buildtab=1
                            $nTabCount=0
                        Else
                            $nTabCount=_GUICtrlTab_GetItemCount($Tabs)
                            Local $aListViewAll='',$aIDs=''
                            For $iCountLoop=0 to $nTabCount -1
                                $aSplit=StringSplit(_GUICtrlTab_GetItemText($Tabs,$iCountLoop)," - ",2)
                                $aSplit=_ArrayBlankDeleter($aSplit)
                                _ArrayTranspose($aSplit)
                                If $aIDs='' Then
                                    $aIDs=$aSplit
                                Else
                                    _ArrayConcatenate($aIDs,$aSplit)
                                EndIf
                            Next
                            _ArrayConcatenate($IDs,$aIDs)
                            _ArrayDisplay($IDs)
                            _GUICtrlTab_Destroy($Tabs)
                            $Tabs=GUICtrlCreateTab(0, 10, 609, 300)
                        EndIf
                        Local $ResultList[UBound($IDs)]
                        Local $Tab[UBound($IDs)]
                        local $NameLabel[UBound($IDs)]
                        $idContextmenu = GUICtrlCreateContextMenu($Tabs)
                        $idDeleteTab = GUICtrlCreateMenuItem("Delete Current Tab", $idContextmenu)
                        ;Loop for each Result
                        For $p = 0 To UBound($IDs) - 1
                            Local $Fullresult[3][7] = [[$IDs[$p][0]&'-'&$IDs[$p][1], "Tester", "123456", GUICtrlRead($aInput), '', '', ''], ["Hello", "There", "My", "Fine", "Friend", "", ""], ["GoodBye", "There", "My", "Hated", "Enemy", "", ""]]
                            $Tab[$p] = GUICtrlCreateTabItem($Fullresult[0][0])
                            $ResultList[$p] = GUICtrlCreateListView("", 7, 128, 594, 174,$LVS_EDITLABELS)
                            _GUICtrlListView_AddColumn($ResultList[$p], 'Col0')
                            _GUICtrlListView_AddColumn($ResultList[$p], 'Col1')
                            _GUICtrlListView_AddColumn($ResultList[$p], 'Col2')
                            _GUICtrlListView_AddColumn($ResultList[$p], 'Col3')
                            _GUICtrlListView_AddColumn($ResultList[$p], 'Col4')
                            _GUICtrlListView_AddColumn($ResultList[$p], 'Col5')
                            _GUICtrlListView_AddColumn($ResultList[$p], 'Col6')
                            $NameLabel[$p] = GUICtrlCreateLabel($Fullresult[0][0], 8, 67, 260, 17)
                            Local $aWriter = $Fullresult
                            _ArrayDelete($aWriter, 0)
                            _GUICtrlListView_AddArray($ResultList[$p], $aWriter)
                            GUICtrlCreateTabItem("")
                        Next
                        Hide(1, $aLabel, $aInput, $UserOutput, $aReportBox, $MarkDead)
                        SplashOff()
                        GUISetState(@SW_SHOW)
                        While 2
                            ExitLoop
                        WEnd
                    EndIf
                EndIf
            Case $idDeleteTab
                If $tabs Then
                    _GUICtrlTab_DeleteItem($Tabs,GUICtrlRead($tabs))
                EndIf
        EndSwitch
    WEnd
EndFunc   ;==>Example

Func Hide($toggle, $aLabel, $aInput, $UserOutput, $aReportBox, $MarkDead)
    GUICtrlSetState($aLabel, $toggle = 1 ? $GUI_SHOW : $GUI_HIDE)
    GUICtrlSetState($aInput, $toggle = 1 ? $GUI_SHOW : $GUI_HIDE)
    GUICtrlSetState($UserOutput, $toggle = 1 ? $GUI_SHOW : $GUI_HIDE)
    GUICtrlSetState($aReportBox, $toggle = 1 ? $GUI_SHOW : $GUI_HIDE)
    GUICtrlSetState($MarkDead, $toggle = 1 ? $GUI_SHOW : $GUI_HIDE)
EndFunc   ;==>Hide

Func _ArrayBlankDeleter($arr_2)
    For $i = UBound($arr_2) - 1 To 0 Step -1
        If $arr_2[$i] = "" Then
            _ArrayDelete($arr_2, $i)
        EndIf
    Next
    Return $arr_2
EndFunc
Link to comment
Share on other sites

Hello,

I think deleting and recreating the GUI $AcctResults does what you want?

#include <GUITab.au3>
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <Array.au3>
#include <GUIListView.au3>


;Begin Main Gui
Global $Home = GUICreate("Welcome", 635, 477, 192, 114, $WS_MAXIMIZEBOX)

;Menus
$MenuFile = GUICtrlCreateMenu("File")
$Start = GUICtrlCreateMenuItem("Start", $MenuFile)
GUICtrlCreateMenuItem("", $MenuFile) ; Create a separator line
$ExitMenu = GUICtrlCreateMenuItem("Exit", $MenuFile)
GUISetState(@SW_SHOW)
WinSetState($Home, '', @SW_MAXIMIZE)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE, $ExitMenu
            Exit
        Case $Start
            Example()
    EndSwitch
WEnd

Func Example()
    local $idDeleteTab, $tabs, $buildtab=0
    $MainForm = GUICreate("Test", 925, 327, 192, 114, -1, $WS_EX_MDICHILD, $Home)
    $TypeLabel = GUICtrlCreateLabel("Search Type", 8, 8, 65, 17)
    $SearchInput = GUICtrlCreateCombo("", 16, 26, 257, 25)
    GUICtrlSetData(-1, "Name|ID")
    $InputValLabel = GUICtrlCreateLabel("Input Value", 8, 56, 58, 17)
    $InputVal = GUICtrlCreateInput("", 16, 80, 257, 21)
    $StartSearch = GUICtrlCreateButton("Search", 8, 284, 75, 25)
    $aLabel = GUICtrlCreateLabel("Date", 8, 112, 84, 17)
    $aInput = GUICtrlCreateDate("", 19, 132, 259, 21, (0x00))
    $aReportBox = GUICtrlCreateCheckbox("Generate report", 11, 168, 169, 17)
    GUICtrlSetState(-1, $GUI_HIDE)
    $MarkDead = GUICtrlCreateCheckbox("Mark Dead", 11, 192, 169, 17)
    GUICtrlSetState(-1, $GUI_HIDE)
    $UserOutput = GUICtrlCreateButton("Output", 188, 284, 75, 25)
    GUICtrlSetState($UserOutput, $GUI_HIDE)
    $bEnterDummy = GUICtrlCreateDummy()
    Local $bAccelKeys[1][2] = [["{ENTER}", $bEnterDummy]]
    GUISetAccelerators($bAccelKeys)

    GUISetState(@SW_SHOW)

    While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE, $ExitMenu
                GUIDelete($MainForm)
                ExitLoop
            Case $StartSearch, $bEnterDummy
                If GUICtrlRead($InputVal) = "" Then
                    MsgBox(0, "ERROR", "You must input a parameter")
                Else
                    SplashTextOn("Processing...", "Processing" & @CRLF & @CRLF & "Please wait", 200, 150, Default, Default, 1, Default, 25)
                    $type = GUICtrlRead($SearchInput)
                    $Parameter = GUICtrlRead($InputVal)
                    GUICtrlSetData($InputVal, "")
                    Local $IDs[2][2] = [["1", "A"], ["2", "B"]]
                    SplashOff()
                    If UBound($IDs) > 0 Then
                        SplashTextOn("Processing...", "Processing" & @CRLF & @CRLF & "Please wait", 200, 150, Default, Default, 1, Default, 25)


                        If $buildtab=0 then
                            $AcctResults = GUICreate("", 620, 344, 294, 0, $WS_CHILD, -1, $MainForm)
                            $Tabs=GUICtrlCreateTab(0, 10, 609, 300)
                            $buildtab=1
                            $nTabCount=0
                        Else
                            GUIDelete($AcctResults)
                            $AcctResults = GUICreate("", 620, 344, 294, 0, $WS_CHILD, -1, $MainForm)
                            $Tabs=GUICtrlCreateTab(0, 10, 609, 300)
                            $buildtab=1
                            $nTabCount=0
;~                          $AcctResults = GUICreate("", 620, 344, 294, 0, $WS_CHILD, -1, $MainForm)
;~                             $nTabCount=_GUICtrlTab_GetItemCount($Tabs)
;~                             Local $aListViewAll='',$aIDs=''
;~                             For $iCountLoop=0 to $nTabCount -1
;~                                 $aSplit=StringSplit(_GUICtrlTab_GetItemText($Tabs,$iCountLoop)," - ",2)
;~                                 $aSplit=_ArrayBlankDeleter($aSplit)
;~                                 _ArrayTranspose($aSplit)
;~                                 If $aIDs='' Then
;~                                     $aIDs=$aSplit
;~                                 Else
;~                                     _ArrayConcatenate($aIDs,$aSplit)
;~                                 EndIf
;~                             Next
;~                             _ArrayConcatenate($IDs,$aIDs)
;~                             _ArrayDisplay($IDs)
;~                             _GUICtrlTab_Destroy($Tabs)
;~                             $Tabs=GUICtrlCreateTab(0, 10, 609, 300)
                        EndIf
                        Local $ResultList[UBound($IDs)]
                        Local $Tab[UBound($IDs)]
                        local $NameLabel[UBound($IDs)]
                        $idContextmenu = GUICtrlCreateContextMenu($Tabs)
                        $idDeleteTab = GUICtrlCreateMenuItem("Delete Current Tab", $idContextmenu)
                        ;Loop for each Result
                        For $p = 0 To UBound($IDs) - 1
                            Local $Fullresult[3][7] = [[$IDs[$p][0]&'-'&$IDs[$p][1], "Tester", "123456", GUICtrlRead($aInput), '', '', ''], ["Hello", "There", "My", "Fine", "Friend", "", ""], ["GoodBye", "There", "My", "Hated", "Enemy", "", ""]]
                            $Tab[$p] = GUICtrlCreateTabItem($Fullresult[0][0])
                            $ResultList[$p] = GUICtrlCreateListView("", 7, 128, 594, 174,$LVS_EDITLABELS)
                            _GUICtrlListView_AddColumn($ResultList[$p], 'Col0')
                            _GUICtrlListView_AddColumn($ResultList[$p], 'Col1')
                            _GUICtrlListView_AddColumn($ResultList[$p], 'Col2')
                            _GUICtrlListView_AddColumn($ResultList[$p], 'Col3')
                            _GUICtrlListView_AddColumn($ResultList[$p], 'Col4')
                            _GUICtrlListView_AddColumn($ResultList[$p], 'Col5')
                            _GUICtrlListView_AddColumn($ResultList[$p], 'Col6')
                            $NameLabel[$p] = GUICtrlCreateLabel($Fullresult[0][0], 8, 67, 260, 17)
                            Local $aWriter = $Fullresult
                            _ArrayDelete($aWriter, 0)
                            _GUICtrlListView_AddArray($ResultList[$p], $aWriter)
                            GUICtrlCreateTabItem("")
                        Next
                        Hide(1, $aLabel, $aInput, $UserOutput, $aReportBox, $MarkDead)
                        SplashOff()
                        GUISetState(@SW_SHOW)
                        While 2
                            ExitLoop
                        WEnd
                    EndIf
                EndIf
            Case $idDeleteTab
                If $tabs Then
                    _GUICtrlTab_DeleteItem($Tabs,GUICtrlRead($tabs))
                EndIf
        EndSwitch
    WEnd
EndFunc   ;==>Example

Func Hide($toggle, $aLabel, $aInput, $UserOutput, $aReportBox, $MarkDead)
    GUICtrlSetState($aLabel, $toggle = 1 ? $GUI_SHOW : $GUI_HIDE)
    GUICtrlSetState($aInput, $toggle = 1 ? $GUI_SHOW : $GUI_HIDE)
    GUICtrlSetState($UserOutput, $toggle = 1 ? $GUI_SHOW : $GUI_HIDE)
    GUICtrlSetState($aReportBox, $toggle = 1 ? $GUI_SHOW : $GUI_HIDE)
    GUICtrlSetState($MarkDead, $toggle = 1 ? $GUI_SHOW : $GUI_HIDE)
EndFunc   ;==>Hide

Func _ArrayBlankDeleter($arr_2)
    For $i = UBound($arr_2) - 1 To 0 Step -1
        If $arr_2[$i] = "" Then
            _ArrayDelete($arr_2, $i)
        EndIf
    Next
    Return $arr_2
EndFunc
Link to comment
Share on other sites

 

Hello,

I think deleting and recreating the GUI $AcctResults does what you want?

 

This does actually resolve one of the issues (The ability to resend the search to add tabs). I tweaked my script to match the ordering you had (which makes way more sense to me). I'm going to take a look at the GUI delete tab function with fresh eyes after the weekend to see if I can figure out what is going on there. I'll report back with a modded sample script when its fixes in case anyone wants to use it.

Link to comment
Share on other sites

Fixed it.... The UDF doesn't work with the function I'm using so I went back to the basics... Using 

$nIndex=GUICtrlRead($tabs)
                GUICtrlDelete($Tab[$nIndex])
Fixed the issue.

 

Here is the finished sample:

#include <GUITab.au3>
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <Array.au3>
#include <GUIListView.au3>
 
 
;Begin Main Gui
Global $Home = GUICreate("Welcome", 635, 477, 192, 114, $WS_MAXIMIZEBOX)
 
;Menus
$MenuFile = GUICtrlCreateMenu("File")
$Start = GUICtrlCreateMenuItem("Start", $MenuFile)
GUICtrlCreateMenuItem("", $MenuFile) ; Create a separator line
$ExitMenu = GUICtrlCreateMenuItem("Exit", $MenuFile)
GUISetState(@SW_SHOW)
WinSetState($Home, '', @SW_MAXIMIZE)
 
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE, $ExitMenu
            Exit
        Case $Start
            Example()
    EndSwitch
WEnd
 
Func Example()
    local $idDeleteTab, $tabs, $buildtab=0
    $MainForm = GUICreate("Test", 925, 327, 192, 114, -1, $WS_EX_MDICHILD, $Home)
    $TypeLabel = GUICtrlCreateLabel("Search Type", 8, 8, 65, 17)
    $SearchInput = GUICtrlCreateCombo("", 16, 26, 257, 25)
    GUICtrlSetData(-1, "Name|ID")
    $InputValLabel = GUICtrlCreateLabel("Input Value", 8, 56, 58, 17)
    $InputVal = GUICtrlCreateInput("", 16, 80, 257, 21)
    $StartSearch = GUICtrlCreateButton("Search", 8, 284, 75, 25)
    $aLabel = GUICtrlCreateLabel("Date", 8, 112, 84, 17)
    $aInput = GUICtrlCreateDate("", 19, 132, 259, 21, (0x00))
    $aReportBox = GUICtrlCreateCheckbox("Generate report", 11, 168, 169, 17)
    GUICtrlSetState(-1, $GUI_HIDE)
    $UserOutput = GUICtrlCreateButton("Output", 188, 284, 75, 25)
    GUICtrlSetState($UserOutput, $GUI_HIDE)
    $bEnterDummy = GUICtrlCreateDummy()
    Local $bAccelKeys[1][2] = [["{ENTER}", $bEnterDummy]]
    GUISetAccelerators($bAccelKeys)
 
    GUISetState(@SW_SHOW)
 
    While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE, $ExitMenu
                GUIDelete($MainForm)
                ExitLoop
            Case $StartSearch, $bEnterDummy
                If GUICtrlRead($InputVal) = "" Then
                    MsgBox(0, "ERROR", "You must input a parameter")
                Else
                    SplashTextOn("Processing...", "Processing" & @CRLF & @CRLF & "Please wait", 200, 150, Default, Default, 1, Default, 25)
                    $type = GUICtrlRead($SearchInput)
                    $Parameter = GUICtrlRead($InputVal)
                    GUICtrlSetData($InputVal, "")
                    Local $IDs[2][2] = [["1", "A"], ["2", "B"]]
                    SplashOff()
                    If UBound($IDs) > 0 Then
                        SplashTextOn("Processing...", "Processing" & @CRLF & @CRLF & "Please wait", 200, 150, Default, Default, 1, Default, 25)
 
 
                        If $buildtab=0 then
                            $AcctResults = GUICreate("", 620, 344, 294, 0, $WS_CHILD, -1, $MainForm)
                            $Tabs=GUICtrlCreateTab(0, 10, 609, 300)
                            $buildtab=1
                        Else
                            $nTabCount=_GUICtrlTab_GetItemCount($Tabs)
                            Local $aListViewAll='',$aIDs=''
                            For $iCountLoop=0 to $nTabCount -1
                                $aSplit=StringSplit(_GUICtrlTab_GetItemText($Tabs,$iCountLoop)," - ",2)
                                $aSplit=_ArrayBlankDeleter($aSplit)
                                _ArrayTranspose($aSplit)
                                If $aIDs='' Then
                                    $aIDs=$aSplit
                                Else
                                    _ArrayConcatenate($aIDs,$aSplit)
                                EndIf
                            Next
                            _ArrayConcatenate($IDs,$aIDs)
                            _ArrayDisplay($IDs)
                            GUIDelete($AcctResults)
                            $AcctResults = GUICreate("", 620, 344, 294, 0, $WS_CHILD, -1, $MainForm)
                            $Tabs=GUICtrlCreateTab(0, 10, 609, 300)
                            $buildtab=1
                        EndIf
                        Local $ResultList[UBound($IDs)]
                        Local $Tab[UBound($IDs)]
                        local $NameLabel[UBound($IDs)]
                        $idContextmenu = GUICtrlCreateContextMenu($Tabs)
                        $idDeleteTab = GUICtrlCreateMenuItem("Delete Current Tab", $idContextmenu)
                        ;Loop for each Result
                        For $p = 0 To UBound($IDs) - 1
                            Local $Fullresult[3][7] = [[$IDs[$p][0]&'-'&$IDs[$p][1], "Tester", "123456", GUICtrlRead($aInput), '', '', ''], ["Hello", "There", "My", "Fine", "Friend", "", ""], ["GoodBye", "There", "My", "Hated", "Enemy", "", ""]]
                            $Tab[$p] = GUICtrlCreateTabItem($Fullresult[0][0])
                            $ResultList[$p] = GUICtrlCreateListView("", 7, 128, 594, 174,$LVS_EDITLABELS)
                            _GUICtrlListView_AddColumn($ResultList[$p], 'Col0')
                            _GUICtrlListView_AddColumn($ResultList[$p], 'Col1')
                            _GUICtrlListView_AddColumn($ResultList[$p], 'Col2')
                            _GUICtrlListView_AddColumn($ResultList[$p], 'Col3')
                            _GUICtrlListView_AddColumn($ResultList[$p], 'Col4')
                            _GUICtrlListView_AddColumn($ResultList[$p], 'Col5')
                            _GUICtrlListView_AddColumn($ResultList[$p], 'Col6')
                            $NameLabel[$p] = GUICtrlCreateLabel($Fullresult[0][0], 8, 67, 260, 17)
                            Local $aWriter = $Fullresult
                            _ArrayDelete($aWriter, 0)
                            _GUICtrlListView_AddArray($ResultList[$p], $aWriter)
                            GUICtrlCreateTabItem("")
                        Next
                        Hide(1, $aLabel, $aInput, $UserOutput, $aReportBox)
                        SplashOff()
                        GUISetState(@SW_SHOW)
                        While 2
                            ExitLoop
                        WEnd
                    EndIf
                EndIf
            Case $idDeleteTab
                If $tabs Then
$nIndex=GUICtrlRead($tabs)
                    GUICtrlDelete($Tab[$nIndex])
_GUICtrlTab_ActivateTab($tabs,0)
                EndIf
        EndSwitch
    WEnd
EndFunc   ;==>Example
 
Func Hide($toggle, $aLabel, $aInput, $UserOutput, $aReportBox)
    GUICtrlSetState($aLabel, $toggle = 1 ? $GUI_SHOW : $GUI_HIDE)
    GUICtrlSetState($aInput, $toggle = 1 ? $GUI_SHOW : $GUI_HIDE)
    GUICtrlSetState($UserOutput, $toggle = 1 ? $GUI_SHOW : $GUI_HIDE)
    GUICtrlSetState($aReportBox, $toggle = 1 ? $GUI_SHOW : $GUI_HIDE)
EndFunc   ;==>Hide
 
Func _ArrayBlankDeleter($arr_2)
    For $i = UBound($arr_2) - 1 To 0 Step -1
        If $arr_2[$i] = "" Then
            _ArrayDelete($arr_2, $i)
        EndIf
    Next
    Return $arr_2
EndFunc
Edited by Jewtus
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...