List contents accumulates - how to fix?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
kdaube
Posts: 86
Joined: 02 Nov 2015, 03:11

List contents accumulates - how to fix?

Post by kdaube » 02 Feb 2023, 09:51

Dear gurus and experts.
In a script I select in list A (the left one in the screen shot). This fills list B.
If I then change the selection A, list B is not built afresh but amended by the new items.
Image
Snippet of UI

Code: Select all

Gui Tab, 2 ; From existing TLB ------------------------------
Gui, Font, s10 w400, MS sans serif
Gui Add, Text,    x020 y030 w200 h025                     , % lang("UItxTbLbls")
Gui Add, Text,    x230 y030 w150 h025                     , % lang("UItxTbBtn")
Gui Add, Groupbox,x390 y030 w400 h170                     , % lang("UItxTbPrp")
Gui Add, ListBox, x020 y050 w200 h200   gFn2SelInTbarList  vTbCurrent  AltSubmit, %lstTbLabels% ; list A
Gui Add, ListBox, x230 y050 w150 h200   gFn2SelInBtnList   vBtnCurrent AltSubmit, %lstBtnCmds%  ; list B
.....
Fn2SelInTbarList() {  ;  ------  Select from tool bar list
  Gui, Submit, noHide                                       ; get the varaible content
  If (A_GuiEvent != "DoubleClick") {
    return
  } else {                                                  ; build button list
    Fn2GetBtnData(TbCurrent)
    Fn2FillBtnList()                                        ; fill list lstBtnCmds
MsgBox «%lstBtnCmds%»
    GuiControl, Choose, SysTabControl321, 2                 ; Got to tab 2
    GuiControl,, BtnCurrent,  %lstBtnCmds%
  }
}
At the first selection the message list the 14 items which also appear in the list box:
«Nudge1ptUp|Nudge1ptDown|Nudge1ptLeft|Nudge1ptRight|AlignGfxTop|AlignGfxTBCenter|AlignGfxBottom|AlignGfxLeft|AlignGfxLRCenter|AlignGfxRight|RotateGfxClockwise|RotateGfxCounterClock|SetPatternSolid|SetPatternDashed»

At the second selection the message lists only the 6 items which should appear in the list box, but which appear in the list box appended to the previous ones:
«DocDirectionLTR|DocDirectionRTL|NumberUtilityITN|NumberUtilityNTI|NumberUtilityFTN|NumberUtilityNTF»

Obviously my GuiControl is not correct - but what is wrong here?
Klaus Daube, Zürich, CH

User avatar
kdaube
Posts: 86
Joined: 02 Nov 2015, 03:11

Re: List contents accumulates - how to fix?

Post by kdaube » 02 Feb 2023, 10:00

I think I got it:
To replace (overwrite) the list instead, include a pipe as the first character (e.g. |Red|Green|Blue).
Klaus Daube, Zürich, CH

RussF
Posts: 1242
Joined: 05 Aug 2021, 06:36

Re: List contents accumulates - how to fix?

Post by RussF » 02 Feb 2023, 10:01

In the docs for Guicontrol:
Tab/DropDownList/ComboBox/ListBox: Value should contain a pipe-delimited list of entries to be appended at the end of the control's list. To replace (overwrite) the list instead, include a pipe as the first character (e.g. |Red|Green|Blue). To make the control empty, specify only a pipe character (|). To have one of the entries pre-selected, include two pipes after it (e.g. Red|Green||Blue). The separator between fields may be changed to something other than pipe. For example, Gui +Delimiter`n would change it to linefeed and Gui +DelimiterTab would change it to tab (`t).
Russ

User avatar
mikeyww
Posts: 26599
Joined: 09 Sep 2014, 18:38

Re: List contents accumulates - how to fix?

Post by mikeyww » 02 Feb 2023, 10:21

I thought the goal was to append the lists. If so, an idea is below.

Code: Select all

#Requires AutoHotkey v1.1.33
list := {"List 1": "A|B|C", "List 2": "D|E|F"}
rows := 10
For box1item in list
 box1str .= (box1str = "" ? "" : "|") box1item
Gui Font, s10
Gui Add, ListBox, w200 vsel r%rows% gUpdate, % box1str
Gui Add, ListBox, wp   vstr r%rows% x+m
Gui Show,, Lists
Return

Update:
Gui Submit, NoHide
For each, item in StrSplit(list[sel], "|")
 box2str .= InStr("|" box2str "|", "|" item "|") ? "" : "|" item
GuiControl,, str, % box2str
Return

Post Reply

Return to “Ask for Help (v1)”