I would like to be able to populate a listbox with a variable and then when items are added or removed, the original variable would be synchronized with the contents of the box. I could write a function to do this but I would have to have a hook that would indicate when a change had been made in the listbox, not merely a selection change.

As is, if you populate with a variable and then add or delete entries using ListboxAddItem, or ListboxDeleteItem, the original variable remains the same but the display no longer reflects the original variable that set it.

I've created a demonstration of the issue. Create a new 640x480 app and paste the following code in it:

{NeoBook 5 Objects}NeoBookVer=5.80ObjectType=10Name=ListBox1X=204Y=39W=203H=366Anchor=0Text=[OriginalList]VarName=[ListBox1]VarType=0XPTheme=YesLineColor=0LineWidth=1LineStyle=0FillColor=16777215FillPattern=0Font=ArialFontSize=11FontStyle=1FontCharset=1TextColor=0TabOrder=2ObjectType=3Name=PushButton1X=38Y=41W=124H=30Anchor=0Text=Set ListHint= Assign new values to variable OriginalListAlign=2ImageStyle=0XPTheme=YesObjAction=SetVar "[originalList]" "apple[#13]orange[#13]banana[#13]"¶RefreshObject "ListBox1"¶ListBoxSize "ListBox1" "[listboxlen]"¶StrParse "[OriginalList]" "[#13]" "[OriginalList]" "[OLlen]"LineColor=0LineWidth=1LineStyle=0FillColor=16777215FillPattern=0Font=ArialFontSize=11FontStyle=0FontCharset=1TextColor=0TabOrder=3ObjectType=3Name=PushButton2X=207Y=409W=204H=30Anchor=0Text=Show value of OriginalList varHint=apple, orange, bananaAlign=2ImageStyle=0XPTheme=YesObjAction=Alertbox "test" "The value of the original list var is:|[OriginalList]"LineColor=0LineWidth=1LineStyle=0FillColor=16777215FillPattern=0Font=ArialFontSize=11FontStyle=0FontCharset=1TextColor=0TabOrder=4ObjectType=3Name=PushButton3X=38Y=197W=124H=30Anchor=0Text=Clear ListboxAlign=2ImageStyle=0XPTheme=YesObjAction=ListBoxSize "ListBox1" "[listboxlen]"¶StrParse "[OriginalList]" "[#13]" "[test]" "[OLlen]"¶Alertbox "test" "ListboxSize is [listboxlen]"¶¶Loop "1" "[listboxlen]" "[CTR]"¶SetVar "[DisplayNum]" "[listboxlen]+1-[ctr]"¶StickyNote "-1" "-1" "Deleting listbox item #[DisplayNum]" "500"¶ListBoxDeleteItem "ListBox1" "[DisplayNum]"¶Endloop¶ListBoxSize "ListBox1" "[listboxlen]"¶StrParse "[OriginalList]" "[#13]" "[OriginalList]" "[OLlen]"LineColor=0LineWidth=1LineStyle=0FillColor=16777215FillPattern=0Font=ArialFontSize=11FontStyle=0FontCharset=1TextColor=0TabOrder=5ObjectType=3Name=PushButton4X=38Y=93W=124H=30Anchor=0Text=Add item to OL VarHint=Add item to OriginalList variable stringAlign=2ImageStyle=0XPTheme=YesObjAction=InputBox "Add to list" "This will add to the variable OriginalList |and refresh the listbox" "[NewItem]"¶¶SetVar "[originalList]" "[OriginalList][NewItem][#13]"¶RefreshObject "ListBox1"¶SetVar "[newitem]" ""¶ListBoxSize "ListBox1" "[listboxlen]"¶StrParse "[OriginalList]" "[#13]" "[OriginalList]" "[OLlen]"LineColor=0LineWidth=1LineStyle=0FillColor=16777215FillPattern=0Font=ArialFontSize=11FontStyle=0FontCharset=1TextColor=0TabOrder=6ObjectType=3Name=PushButton5X=38Y=144W=124H=30Anchor=0Text=Add item to listboxHint=Add item using NB ListBoxAddItem Align=2ImageStyle=0XPTheme=YesObjAction=InputBox "Add to listbox" "This will add an item to the listbox itself|and then refresh the object" "[NewItem]"¶ListBoxAddItem "ListBox1" "0" "[NewItem]"¶RefreshObject "ListBox1"¶SetVar "[newitem]" ""¶ListBoxSize "ListBox1" "[listboxlen]"¶StrParse "[OriginalList]" "[#13]" "[OriginalList]" "[OLlen]"LineColor=0LineWidth=1LineStyle=0FillColor=16777215FillPattern=0Font=ArialFontSize=11FontStyle=0FontCharset=1TextColor=0TabOrder=7ObjectType=8Name=Text1X=426Y=47W=174H=40Anchor=0Font=ArialFontSize=11FontStyle=0FontCharset=1TextColor=0Text={\rtf1\ansi\deff0\deftab254{\fonttbl{\f0\fnil\fcharset1 Arial;}}{\pard{\ql\li0\fi0\ri0\sb0\sl\sa0 \plain\f0\fs22\cf0 Listbox size is: [listboxlen]}}}HMargin=0VMargin=0LineColor=0LineWidth=0LineStyle=0FillColor=16777215FillPattern=0TabOrder=8ObjectType=8Name=Text2X=411Y=383W=226H=40Anchor=0Font=ArialFontSize=11FontStyle=0FontCharset=1TextColor=0Text={\rtf1\ansi\deff0\deftab254{\fonttbl{\f0\fnil\fcharset1 Arial;}}{\pard{\ql\li0\fi0\ri0\sb0\sl\sa0 \plain\f0\fs22\cf0 #Lines in OriginalList variable: [OLlen]}}}HMargin=0VMargin=0LineColor=0LineWidth=0LineStyle=0FillColor=16777215FillPattern=0TabOrder=9ObjectType=8Name=Text3X=202Y=2W=244H=42Anchor=0Font=ArialFontSize=11FontStyle=0FontCharset=1TextColor=0Text={\rtf1\ansi\deff0\deftab254{\fonttbl{\f0\fnil\fcharset1 Arial;}}{\pard{\ql\li0\fi0\ri0\sb0\sl\sa0 \plain\f0\fs22\cf0 Listbox populated with "OriginalList" \par\ql\li0\fi0\ri0\sb0\sl\sa0 \plain\f0\fs22\cf0 variable using #13 separators}}}HMargin=0VMargin=0LineColor=0LineWidth=0LineStyle=0FillColor=16777215FillPattern=1TabOrder=10ObjectType=9Name=TextEntry1X=431Y=94W=183H=261Anchor=0Text=The list box is populated at startup by setting the variable [OriginalList].¶¶Click Set List and this resets the value of the variable [OriginalList]¶¶Click Add item to OL (OrigianList) Var and you will be prompted to add a value to the listbox. Note how the Listbox size and the #lines in the OL variable are still the same.¶¶Click Add item to listbox. This prompts you for a value and then inserts it using the ListboxAddItem command.Note how the listbox has 5 items but the OL variable is still only 4 lines. Click the Show Value of Originallist var button at bottom. You see it does not show the newly added item.¶¶Click the Add item to OL Var button and add another item. Notice how it overwrites the last item added by ListboxAddItem.¶¶Again add an item to listbox and see how it is added to the listbox but is not in the OriginalList variable. Also Listbox size and OriginalList variable have different numbers of lines.¶¶Click Clear Listbox button. This usese the ListBoxDeleteItem command. Note that the listbox is empty but the OriginalList variable is as was. VarName=[TextEntry1]Align=1EditMultiLine=YesEditLen=0LineColor=0LineWidth=1LineStyle=0FillColor=16777215FillPattern=0Font=ArialFontSize=11FontStyle=0FontCharset=1TextColor=0TabOrder=11

Follow the steps I have typed in to see the issues.

As mentioned, if I had a way to know when a change occurred in the list, not just a selection change, I could address this. As it is, maybe NB could have a new function in this area. Synchronizing the listbox contents with the variable that originally set the value of the listbox. Make this an option when defining the object.

Is there a way currently to know when a change has been made to the listbox?

This is an interesting question. Since the only way to add or remove something from a listbox is via code, you already know when it's being modified because you're the one doing it. You could manually add and remove items directly from the [OriginalList] variable, but that requires more code and isn't as convenient as using ListBoxAddItem and ListBoxDeleteItem. What you could do if you wanted to use the ListBox actions, is call a subroutine whenever you make changes that affect the list. For example:

A new feature that allowed you to specify a subroutine to execute whenever a variable's value changes is something that might be worth considering for the future. However, for variables that are updated a lot such a feature could become a big performance drag.