Jump to content

i can't find it... it's easy "while"


Recommended Posts

I have tab and tabitems, in first "tabitem" i have options which are deciding what is in listview in second "tabitem2".

what should I do when I click "tabitem2" to stop "while" from "tabitem"?

because in "tabitem"2, "while" is not working when it's working in "tabitem"

pls help :mellow:

Link to comment
Share on other sites

  • Moderators

ZwinnyRolnik,

Why do you need to exit the While...WEnd loop? :mellow:

You are obviously in MessageLoop mode, so put all the controls in the same loop. If the first tab is not visible none of the Cases from the first tab can fire because you cannot access the controls:

#include <GUIConstantsEx.au3>

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

$hTab = GUICtrlCreateTab(10, 10, 200, 100)

    $hTab0 = GUICtrlCreateTabItem("Tab 0")
    $hCheckbox = GUICtrlCreateCheckbox(" Checkbox 0", 30, 80, 50, 20)

    $hTab1 = GUICtrlCreateTabItem("Tab 1")
    $hLabel = GUICtrlCreateLabel("Unchecked", 30, 40, 100, 20)
    $hButton = GUICtrlCreateButton("Press Me!", 30, 60, 80, 30)

GUICtrlCreateTabItem(""); end tabitem definition

GUISetState()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hCheckbox
            If GUICtrlRead($hCheckbox) = 1 Then
                GUICtrlSetData($hLabel, "Checked")
            Else
                GUICtrlSetData($hLabel, "Unchecked")
            EndIf
        Case $hButton
            MsgBox(0,"", "You pressed it")
    EndSwitch

WEnd

If your code for each control is more than just a few lines, you will need to put the actions for each control in separate functions or your loop will get too long to maintain easily: :party:

#include <GUIConstantsEx.au3>

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

$hTab = GUICtrlCreateTab(10, 10, 200, 100)

    $hTab0 = GUICtrlCreateTabItem("Tab 0")
    $hCheckbox = GUICtrlCreateCheckbox(" Checkbox 0", 30, 80, 50, 20)

    $hTab1 = GUICtrlCreateTabItem("Tab 1")
    $hLabel = GUICtrlCreateLabel("Unchecked", 30, 40, 100, 20)
    $hButton = GUICtrlCreateButton("Press Me!", 30, 60, 80, 30)

GUICtrlCreateTabItem(""); end tabitem definition

GUISetState()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hCheckbox
            _Checkbox()
        Case $hButton
            _Button()
    EndSwitch

WEnd

Func _Checkbox()
    If GUICtrlRead($hCheckbox) = 1 Then
        GUICtrlSetData($hLabel, "Checked")
    Else
        GUICtrlSetData($hLabel, "Unchecked")
    EndIf
EndFunc

Func _Button()
    MsgBox(0,"", "You pressed it")
EndFunc

I hope that helps. If not, show us some code which lets us see exactly what you are trying to do. :P

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

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Include <GuiListView.au3>
#include <GUIScrollbars_Ex.au3>
#include <Constants.au3>
#include <FontConstants.au3>
#include <StructureConstants.au3>
#include <WinAPI.au3>
#include <_EIPListView.au3>

Opt("GUICloseOnESC", 0)
Opt("GUIOnEventMode", 1)








Global $wartosc[100][100]
Global $Checkbox1, $Checkbox2, $HelpContext, $bProgressShowing, $Tab1;,$Status1,$Status2
Global $hFont, $defColLV = 0x000000, $defBkColLV = 0xFFFFFF
load()



Func _Main()
    

    global $guiw = 800
    global $guih = 400
    global $deskh = @DesktopHeight - _GetTaskBarHeight()
    global $aWinPos[4] = [(@DesktopWidth - $guiw) / 2, ($deskh - $guih) / 2, 800, 400]
    $Gui = GUICreate("Edit", $aWinPos[2], $aWinPos[3], $aWinPos[1], $aWinPos[0], BitOR($GUI_SS_DEFAULT_GUI, $WS_CLIPSIBLINGS));, 424, 280, 200, 110)
    GUISetOnEvent($GUI_EVENT_CLOSE, "OnExit")
    GUISetBkColor(0xCECECE)
    
    
    ; ok HERE is TAB
    
    
    $tab = GUICtrlCreateTab(110, 60, $guiw - 220, $guih - 80)
    $tab0 = GUICtrlCreateTabItem("Karta")
    
    GUICtrlCreateLabel("Ilość partnerów", 130,100,60,40)
    Global $partn = GUICtrlCreateCombo("0", 200, 102, 100, 40, $CBS_DROPDOWNLIST)
GUICtrlSetData(-1, "1|2|3", "0") 
    GUICtrlCreateLabel("Koszty pośrednie rozliczane:", 130,150,60,40)
    Global $partn = GUICtrlCreateCombo("Ryczałtowo", 200, 160, 270, 40, $CBS_DROPDOWNLIST)
GUICtrlSetData(-1, "Na podstawie rzeczywiście poniesionych wydatków", "Ryczałtowo") 
    
    $PP = GuiCtrlCreateCheckbox("Pomoc Publiczna", 130, 200, 150, 20) ; if i set PP not checked then... \/
    
    
    
    
    
    $tab1 = GUICtrlCreateTabItem("Budzet")
    
    
    ;======>>> set the type of control for each column <<<======
    ;0= ignore, 1= edit, 2= combo, 4= calendar, 256= use callback.
    Global $LVcolControl[40] = [1, 1, 2, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1] ;left click actions
    ;0 = ignore, 1= use context callback
    Global $LVcolRControl[40] = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] ; right click actions

    
    
    global $ListView = GUICtrlCreateListView("", 110, 80, $guiw - 220, $guih - 100)
    
    GUICtrlSendMsg($ListView, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_GRIDLINES, $LVS_EX_GRIDLINES)
    $__LISTVIEWCTRL = $ListView
    
    
For $i = 0 To 20
    _GUICtrlListView_AddColumn($ListView, $wartosc[$i][0], "",2)
    _GUICtrlListView_SetColumnWidth($ListView, $i, 100)
Next
    

    _GUICtrlListView_SetBkColor($ListView, $CLR_MONEYGREEN)
    _GUICtrlListView_SetTextColor($ListView, $CLR_BLACK)
    _GUICtrlListView_SetTextBkColor($ListView, $CLR_MONEYGREEN)

    
    
    
    
    Global $B_DESCENDING[_GUICtrlListView_GetColumnCount($ListView)]
    Global $maxColumn = _GUICtrlListView_GetColumnCount($ListView)
    Global $aIParam[1][$maxColumn+1][5]
    Global $oParamSearch = ObjCreate('Scripting.Dictionary') ; store for faster search (iParam, arrayIndex)
    
    

    
    GUICtrlSetOnEvent($__LISTVIEWCTRL, "lvListViewHandler")
    global $cccc
    $cccc = StringTrimRight("L|P|0|1|2|", 1)
    
For $i = 1 To 99
    if $i = 1 Then
        
        If GuiCtrlRead($PP) = $GUI_CHECKED Then
            ContinueLoop ; then here no column PP
        EndIf
    EndIf
     _GUICtrlListView_AddItem($ListView, $wartosc[0][$i])
Next

For $i = 1 To 99
    if $i = 1 Then
        If GuiCtrlRead($PP) = $GUI_CHECKED Then
            ContinueLoop
        EndIf
    EndIf
    
    For $j = 1 To 10
    _GUICtrlListView_AddSubItem($ListView, $i - 1, $wartosc[$j][$i], $j)

    Next    
Next    



$usun = GUICtrlCreateButton("Usun", 100, 0, 60, 40)
GUICtrlSetOnEvent($usun, "usuwanie")
$load = GUICtrlCreateButton("load", 170, 0, 60, 40)
GUICtrlSetOnEvent($load, "load")
$dodaj = GUICtrlCreateButton("Dodaj poz", 240, 0, 60, 40)
GUICtrlSetOnEvent($dodaj, "dodaj")
$do = GUICtrlCreateButton("save", 310, 0, 60, 40)
GUICtrlSetOnEvent($do, "save")
$dod = GUICtrlCreateButton("Dodaj Zad", 380, 0, 60, 40)
GUICtrlSetOnEvent($dod, "zadanie")


    
Local $liczebka[99]
Local $rzym[99]

    For $k = 1 to 19
                $liczebka[$k] = IniRead($lokacja2, "section-2", $k, "")
            Next
            For $s = 1 to 19 step 2
                $rzym[$s] = IniRead($lokacja2, "section-1", $s, "")
            Next
            
                    
                    For $f = 1 To 99
                    _GUICtrlListView_SetItemText($listview, $f-1, $f-3)
                    Next
                    
                    for $d = 1 to 19 step 2
                    
                        _GUICtrlListView_SetItemText($listview, $liczebka[$d]-1, $rzym[$d])
                            
                    Next
                    
                    _GUICtrlListView_SetItemText($listview, 0, "-")
                    _GUICtrlListView_SetItemText($listview, 1, "-") 
            $liczebka[0] = IniRead($lokacja2, "section-2", 0, "")   
GUICtrlCreateTabItem("") 




for $d = 0 to 98
    IniWrite(@ScriptDir&"\plik.ini", "section-1", $d, $rzym[$d])
    IniWrite(@ScriptDir&"\plik.ini", "section-2", $d, $liczebka[$d])
Next
        IniWrite(@ScriptDir&"\plik.ini", "section-2", 0, $liczebka[0])

FileSetAttrib(@ScriptDir&"\plik.ini", "+H")                     
    


$iLV_Width = 17
For $i = 0 To 11
    if $i = 1 Then
        ContinueLoop
    EndIf
    _GUICtrlListView_SetColumnWidth($ListView, $i, $LVSCW_AUTOSIZE_USEHEADER)
    $iHeader_Width = _GUICtrlListView_GetColumnWidth($ListView, $i)
   
    _GUICtrlListView_SetColumnWidth($ListView, $i, $LVSCW_AUTOSIZE)
    $iData_Width = _GUICtrlListView_GetColumnWidth($ListView, $i)
  
    If $iHeader_Width > $iData_Width Then
        _GUICtrlListView_SetColumnWidth($ListView, $i, $iHeader_Width)
        $iLV_Width += $iHeader_Width
    Else
        $iLV_Width += $iData_Width
    EndIf
Next







    GUISetState(@SW_SHOW, $Gui)
    
    
    _InitEditLib ("", "", "", "", $Gui);

    GUICtrlSetData($lvCombo, $cccc)
    

    $bLVEDITondblclick = True
    $bInitiated = True
    $bLVUPDATEonfocusCHANGE = True
    
    While 1
    
        _MonitorEditState ($editCtrl, $editFlag, $__LISTVIEWCTRL, $LVINFO);<<<======  add this in your message loop<<<======
        If $bCALLBACK_EVENT = True Then
            $bCALLBACK_EVENT = False
            
            Call($LVCALLBACK, $LVINFO)
        EndIf
        
        
    WEnd
    
    
    
    _TermEditLib ()
EndFunc

you can see, all of this is working from the beginning of program... and 2x while :mellow: well, i need functions? but how do it in one GUI?

Link to comment
Share on other sites

  • Moderators

ZwinnyRolnik,

If you want help, you need to post some code that at least runs - what you posted above is missing include files, functions and formatting! And I have no idea what "and 2x while well, i need functions? but how do it in one GUI?" means - please try and ask specific questions. I am very happy to try and help, as you know, but I need to know what it is you need. :mellow:

By the way, I see you are using OnEvent mode - so you should only have the one While...WEnd loop to keep the script active. So I ask again: why do you want to exit it? What exactly are you trying to do? Perhaps if you wrote a small script to illustrate the problem you are having? :P

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

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...