Listbox Plus Function

Questions and information about using VBScript and JavaScript in NeoBook functions

Moderator: Neosoft Support

Locked
User avatar
dpayer
Posts: 1394
Joined: Mon Apr 11, 2005 5:55 am
Location: Iowa - USA

Listbox Plus Function

Post by dpayer »

In an effort to improve on my previous listbox function I have created something that I think is probably more helpful for most who will use it.
Here is a compiled demo.

Image

usage:
call lbplus "[%1]" "[%2]"

[%1] = ListboxName,InitialContentVarName,SelectedItemVarname
[%2] = action
(use only the name of the variables, do not use variable brackets)

lbplus is a Neobook function that adds helpful actions to the listbox including:

Undo, AddItem, CopySelected, CopyAll, DeleteSelected, DeleteAll, MoveUp, MoveDown, DeDupe, Sort, ReverseOrder, SortNumeric

The function attempts to synchronize the content of the listbox with the variable used to add initial content and can undo the last change made with the function.

CopySelected and CopyAll puts the items in the clipboard (with a CRLF after each entry)

Deleting selected items or all the entries in the listbox will put a copy of the deleted items in the clipboard.

DeDupe will remove duplicates in the listbox.

Sort will sort contents (alphabetically) using the ListboxSort NB command.

ReverseOrder will reverse the order of all the items in the listbox.

SortNumeric will sort items numerically. It will handle prefixes like currency symbols and (even inconsistent) use of commas. It appends zeros before the whole number (or the whole number part of a decimal) and then sorts. Once sorted, the prefix is removed and the original line content is displayed. The numeric part can even have a description following it (use a space to separate).

Menu
lbplus has a built in menuing system. If the function is called with just the menu job, it will create a menu with all available options (see image above). The jobs can be specified by separating the menu command with the specific jobs. Example:

call lbplus "ListboxName,ContentVarName,SelectedVarName" "menu,Undo,AddItem,CopySelected,DeleteSelected"
Image
and the menu displayed will only be those items.

Uses in NB programming
lbplus can be called by buttons or programmatically even if the menu is not used. If you put an entry in the actions area for the listbox under the right click tab, you can make your menu appear with a simple right click on the listbox. No additional buttons/links would be needed. (see example above)

How to use:
Put the lbplus file into your functions folder of your Neobook installation. Use the "Call" action command and you will be shown the list of functions in your folder. Choose lbplus and you will be prompted for the input items. The first item is actually three items separated by comma: ListboxName, Name of the initial content variable, Name of the selected item variable. The second item contains the action you want to perform. You can only call one action at a time. The menu action can include a list of desired actions (separated by comma) to include in the menu. If no list is included, the menu command will show all available options. NOTE: this function relies on the listbox set to use the item number vs. the item text

Your feedback is appreciated. If you find something doesn't work as anticipated, let me know and I'll work on it. Additional actions will be considered.

Here is the function. Copy this code, paste into notepad. Save in NB's Functions folder. NO .TXT extension, only lbplus as name:

Code: Select all

{NeoBook Function}
Version=5.80
Language=NeoBook
Comment=LBPlus adds ease of use for Listboxes.||Call the function with the first parameter being |Name of listbox, Name of Variable with initial content, Name of Variable for Selected Item||Second parameter is either a single command or the menu command with a list of commands to display in menu. If Menu is used with no list, all options are shown.||Available commands:|Undo : AddItem : CopySelected : CopyAll : DeleteSelected : DeleteAll : MoveUp : MoveDown : DeDupe : Sort : SortReverse ; SortNumeric : Menu
Param=[%1]|Text|Listboxname,InitialContentVariableName,SelectedItemVariableName
Param=[%2]|Text|Single Action OR Menu with multiple items (see comments)
{End}
.in case someone forgets and puts in an actual variable
StrReplace "[%1]" "[#91]" "" "[%1]" ""
StrReplace "[%1]" "[#93]" "" "[%1]" ""

.1st parameter should hold Listbox Name, Original Content Variable, and Selected Content Variable

StrParse "[%1]" "," "[lbpObj]" "[lbpObjLen]"
If "[lbpObjLen]" "<>" "3"
	Alertbox "Data Missing" "The submitted action requires 3 parameters for ListBox Name, Listbox Content (var name), Listbox Selected (var name)"
	GoToLine "endofscript"
Endif
SetVar "[ThisListboxName]" "[lbpObj1]"
SetVar "[ThisListboxContent]" "[lbpObj2]"
SetVar "[ThisListBoxSelected]" "[lbpObj3]"
DeleteArray "[lbpAct]" "All"
StrParse "[%2]" "," "[lbpAct]" "[lbpActLen]"
.StrParse "[%2]" "," "[lbpAction]" "[lbpObjLen]"
.if only one item, set it as the action
	If "[lbpActLen]" "=" "1"
	SetVar "[lbpAct]" "[%2]"
    Endif
        IfEx "([lbpActLen]>1)AND([lbpAct1]<>Menu)"
            AlertBox "Error" "Multiple Actions called; Menu selections not formed properly"
            GoToLine "endofscript"
        Else
            IfEx "([lbpActLen]>1)AND([lbpAct1]=Menu)"
            SetVar "[lbpAct]" "Menu"
            Endif

        Endif
.else need to parse for menu setup
	Endif

.get current content of listbox and put in the variable used for content

	SetVar "[regenListboxContent]" ""
	ListBoxSize "[ThisListboxName]" "[Thislistboxsize]"
		Loop "1" "[Thislistboxsize]" "[CNTR]"
		ListBoxGetItem "[ThisListboxName]" "[CNTR]" "[ThisEntryofListbox]"
		SetVar "[regenListboxContent]" "[regenListboxContent][ThisEntryofListbox][#13]"
		Endloop
.delete extra carriage returns
        StrReplace "[regenListboxContent]" "[#13][#13]" "" "[regenListboxContent]" ""
	SetVar "[[ThisListboxContent]]" "[regenListboxContent]"
.don't overwrite backup if doing an UNDO or MENU
    IF "[lbpAct]" "=" "Undo"
        SetVar "[[ThisListboxContent]]" "[ThisListboxBackupofContent]"
        Gotoline "endofscript"
    Else
        If "[lbpAct]" "<>" "Menu"
        SetVar "[ThisListboxBackupofContent]" "[regenListboxContent]"
        Endif
    Endif

.process actions

.add item
If "[lbpAct]" "=" "AddItem"
   InputBox "New Item" "Add item to the listbox" "[ThisNewListboxItem]"
    ListBoxAddItem "[ThisListboxName]" "0" "[ThisNewListboxItem]"
GotoLine "endofscript"
Endif


.CopyAll
If "[lbpAct]" "=" "CopyAll"


	SetVar "[PreClipboard]" "[[ThisListboxContent]]"
    StrReplace "[PreClipBoard]" "[#13]" "[#13][#10]" "[ClipBoard]" ""
	GetMousePos "[MouseX]" "[MouseY]"
	StickyNote "[MouseX]" "[MouseY]" "[Thislistboxsize] items copied" "500"

GotoLine "endofscript"
Endif
.CopySelected

If "[lbpAct]" "=" "CopySelected"
	If "[[ThisListBoxSelected]]" "=" ""
	GetMousePos "[MouseX]" "[MouseY]"
	StickyNote "[MouseX]" "[MouseY]" "Nothing selected" "500"
	Gotoline "endofscript"
	Endif
	SetVar "[ListSelectedItems]" ""
	StrParse "[[ThisListboxSelected]]" "[#13]" "[SelectedItem]" "[SelectedItemLen]"
		Loop "1" "[SelectedItemLen]" "[CNTR]"
		ListBoxGetItem "[ThisListboxName]" "[SelectedItem[CNTR]]" "[ThisEntryofListbox]"
		SetVar "[ListSelectedItems]" "[ListSelectedItems][ThisEntryofListbox][#13][#10]"
		Endloop
	SetVar "[Clipboard]" "[ListSelectedItems]"
	getMousePos "[MouseX]" "[MouseY]"
	StickyNote "[MouseX]" "[MouseY]" "[SelectedItemLen] item(s) copied" "500"
	GotoLine "endofscript"
Endif

.DeleteSelected
If "[lbpAct]" "=" "DeleteSelected"


.if nothing is selected, end action
	If "[[ThisListBoxSelected]]" "=" ""
		GetMousePos "[MouseX]" "[MouseY]"
		StickyNote "[MouseX]" "[MouseY]" "Nothing selected" "500"
		Gotoline "endofscript"
	Endif

DisableObject "[ThisListboxName]"
.copy to clipboard first
	DeleteArray "[selecteditem]" "All"

	SetVar "[ListSelectedItems]" ""
	StrParse "[[ThisListboxSelected]]" "[#13]" "[SelectedItem]" "[SelectedItemLen]"
	Loop "1" "[SelectedItemLen]" "[CNTR]"
	   ListBoxGetItem "[ThisListboxName]" "[SelectedItem[CNTR]]" "[ThisEntryofListbox]"
	   SetVar "[ListSelectedItems]" "[ListSelectedItems][ThisEntryofListbox][#13][#10]"
	Endloop
    SetVar "[Clipboard]" "[ListSelectedItems]"
.loop from end position and remove all entries from SelectedItem array
GetArrayInfo "[selecteditem]" "temp1" "temp2" "[selecteditemlen]"
SetVar "[selecteditemnum]" "[selecteditemlen]"
Loop "1" "[selecteditemlen]" "[CNTR7]"
ListBoxDeleteItem "[ThisListboxName]" "[SelectedItem[selecteditemnum]]"
Math "[selecteditemnum]-1" "0" "[selecteditemnum]"
Endloop

.update content var, 
	SetVar "[regenListboxContent]" ""
	ListBoxSize "[ThisListboxName]" "[Thislistboxsize]"
		Loop "1" "[Thislistboxsize]" "[CNTR]"
		  ListBoxGetItem "[ThisListboxName]" "[CNTR]" "[ThisEntryofListbox]"
		  SetVar "[regenListboxContent]" "[regenListboxContent][ThisEntryofListbox][#13][#10]"
		Endloop
     StrReplace "[regenListboxContent]" "[#13][#13]" "" "[[ThisListboxContent]]" ""

	getMousePos "[MouseX]" "[MouseY]"
.***** deleted content start

.***** deleted content finish
	StickyNote "[MouseX]" "[MouseY]" "[SelectedItemLen] item(s) copied to clipboard then deleted" "500"
	GotoLine "endofscript"
Endif
EnableObject "[ThisListboxName]"
.Delete all
If "[lbpAct]" "=" "DeleteAll"
StickyNote "[MouseX]" "[MouseY]" "[Thislistboxsize] item(s) copied to clipboard then deleted" "500"
	SetVar "[ClipBoard]" "[[ThisListboxContent]]"
	SetVar "[[ThisListboxContent]]" ""
	GetMousePos "[MouseX]" "[MouseY]"
	
	GotoLine "endofscript"
Endif

.MoveUp - only first selected item
If "[lbpAct]" "=" "MoveUp"


.if nothing is selected, end action
	If "[[ThisListBoxSelected]]" "=" ""
		GetMousePos "[MouseX]" "[MouseY]"
		StickyNote "[MouseX]" "[MouseY]" "Nothing selected" "500"
		Gotoline "endofscript"
	Endif



	If "[[ThisListBoxSelected]]" "=" ""
	GetMousePos "[MouseX]" "[MouseY]"
	StickyNote "[MouseX]" "[MouseY]" "Nothing selected" "500"
	Gotoline "endofscript"
	Endif
	Disableobject "[ThisListboxName]"
	StrParse "[[ThisListboxSelected]]" "[#13]" "[ListSelectedItems]" "[ListSelectedItemsLen]"
	ListBoxGetItem "[ThisListboxName]" "[ListSelectedItems1]" "[ThisEntryofListbox]"
	ListBoxDeleteItem "[ThisListboxName]" "[ListSelectedItems1]"
	Math "[ListSelectedItems1]-1" "0" "[NewItemPosition]"
	ListBoxAddItem "[ThisListboxName]" "[NewItemPosition]" "[ThisEntryofListbox]"

	.get current content of listbox after insertion and put in the variable used for content
	SetVar "[regenListboxContent]" ""
	ListBoxSize "[ThisListboxName]" "[Thislistboxsize]"
		Loop "1" "[Thislistboxsize]" "[CNTR]"
		ListBoxGetItem "[ThisListboxName]" "[CNTR]" "[ThisEntryofListbox]"
		SetVar "[regenListboxContent]" "[regenListboxContent][ThisEntryofListbox][#13]"
		Endloop
	SetVar "[[ThisListboxContent]]" "[regenListboxContent]"
    SetVar "[[ThisListBoxSelected]]" ""
	EnableObject "[ThisListboxName]"
Endif

.MoveDown - only first selected item
If "[lbpAct]" "=" "MoveDown"


.if nothing is selected, end action
	If "[[ThisListBoxSelected]]" "=" ""
		GetMousePos "[MouseX]" "[MouseY]"
		StickyNote "[MouseX]" "[MouseY]" "Nothing selected" "500"
		Gotoline "endofscript"
	Endif

	If "[[ThisListBoxSelected]]" "=" ""
		GetMousePos "[MouseX]" "[MouseY]"
		StickyNote "[MouseX]" "[MouseY]" "Nothing selected" "500"
		Gotoline "endofscript"
	Endif
	Disableobject "[ThisListboxName]"
	StrParse "[[ThisListboxSelected]]" "[#13]" "[ListSelectedItems]" "[ListSelectedItemsLen]"
	ListBoxGetItem "[ThisListboxName]" "[ListSelectedItems1]" "[ThisEntryofListbox]"
	ListBoxDeleteItem "[ThisListboxName]" "[ListSelectedItems1]"
	Math "[ListSelectedItems1]+1" "0" "[NewItemPosition]"
	ListBoxAddItem "[ThisListboxName]" "[NewItemPosition]" "[ThisEntryofListbox]"

	.get current content of listbox after move and put in the variable used for content
	SetVar "[regenListboxContent]" ""
	ListBoxSize "[ThisListboxName]" "[Thislistboxsize]"
		Loop "1" "[Thislistboxsize]" "[CNTR]"
		ListBoxGetItem "[ThisListboxName]" "[CNTR]" "[ThisEntryofListbox]"
		SetVar "[regenListboxContent]" "[regenListboxContent][ThisEntryofListbox][#13]"
		Endloop
	SetVar "[[ThisListboxContent]]" "[regenListboxContent]"
    SetVar "[[ThisListBoxSelected]]" ""
	EnableObject "[ThisListboxName]"
Endif

.DeDupe - remove duplicates in listbox

If "[lbpAct]" "=" "DeDupe"
DisableObject "[ThisListboxName]"
	SetVar "[NewLBContent]" ""
	StrLen "[[ThisListboxContent]]" "[contentlen]"
	While "[Found13]" "<>" "0"
		SearchStr "[#13]" "[[ThisListboxContent]]" "[Found13]" ""
		SubStr "[[ThisListboxContent]]" "1" "[Found13]" "[dedupecompare]"
		SetVar "[NewLBContent]" "[NewLBContent][dedupecompare]"
		StrReplace "[[ThisListboxContent]]" "[dedupecompare]" "" "[[ThisListboxContent]]" ""

	EndWhile
	SetVar "[[ThisListboxContent]]" "[NewLBContent]"
EnableObject "[ThisListboxName]"
	Refreshobject "[ThisListboxName]"
Endif

.Sort - turn sort on / off, the save content
If "[lbpAct]" "=" "Sort"
DisableObject "[ThisListboxName]"
ListBoxSort "[ThisListboxName]" "True"
ListBoxSort "[ThisListboxName]" "False"
	.get current content of listbox after sort and put in the variable used for content
	SetVar "[regenListboxContent]" ""
	ListBoxSize "[ThisListboxName]" "[Thislistboxsize]"
		Loop "1" "[Thislistboxsize]" "[CNTR]"
		ListBoxGetItem "[ThisListboxName]" "[CNTR]" "[ThisEntryofListbox]"
		SetVar "[regenListboxContent]" "[regenListboxContent][ThisEntryofListbox][#13]"
		Endloop
	SetVar "[[ThisListboxContent]]" "[regenListboxContent]"
EnableObject "[ThisListboxName]"
Endif
.ReverseOrder
If "[lbpAct]" "=" "ReverseOrder"
    DisableObject "[ThisListboxName]"
	ListBoxSize "[ThisListboxName]" "[Thislistboxsize]"
	SetVar "[ListBoxPosition]" "[ThisListboxSize]"
	SetVar "[TempListBoxContent]" ""
    .Grab entries from end of list
	Loop "1" "[ThisListboxSize]" "[CNTR]"
		ListboxGetItem "[ThisListboxName]" "[ListBoxPosition]" "[NewListboxItem]"
		SetVar "[TempListBoxContent]" "[TempListBoxContent][NewListboxItem][#13]"
        Math "[ListBoxPosition]-1" "0" "[ListBoxPosition]"
	Endloop
	SetVar "[[ThisListboxContent]]" "[TempListboxContent]"
	EnableObject "[ThisListboxName]"
Endif

.sort numeric - all numeric or first part of string is numeric
If "[lbpAct]" "=" "SortNumeric"

DisableObject "[ThisListboxName]"

ListBoxSize "[ThisListboxName]" "[Thislistboxsize]"
	.next var is for the long strings making up the new list which will be sorted numerically
	SetVar "[LongStr]" ""
	.now get to work!
    SetVar "[CNTR]" ""
	Loop "1" "[ThisListboxSize]" "[CNTR]"
	ListBoxGetItem "[ThisListboxName]" "[CNTR]" "[ThisEntryofListbox]"
    StrParse "[ThisEntryofListbox]" " " "[ThisEntry]" "[tmp]"
.contains numeric part even if no space
    SetVar "[PreSpacePart]" "[ThisEntry1]"
..... remove all but numbers and dots
    StrLen "[PreSpacePart]" "[PreSpaceLen]"
            SetVar "[NewNumStr]" ""
            SetVar "[CNTR2]" ""
			Loop "1" "[PreSpaceLen]" "[CNTR2]"
				SubStr "[PreSpacePart]" "[CNTR2]" "1" "[ThisChar]"
				SearchStr "[ThisChar]" "1234567890." "[ThisCharLoc]" ""
					If "[ThisCharLoc]" ">" "0"
					SetVar "[NewNumStr]" "[NewNumStr][ThisChar]"
					Endif
			Endloop
    SearchStr "." "[NewNumStr]" "[FoundDot]" ""
.if no dot - it is not a decimal - if dot then determin length of whole number part
        If "[FoundDot]" "=" "0"
            SetVar "[WholeNumLen]" "[PreSpaceLen]"
        Else
        SetVar "[WholeNumLen]" "[FoundDot]-1"
        endif

.now create the required padding

.test removal of 10char lim
			If "[WholeNumLen]" ">" "10"
				AlertBox "Error" "The numbers are too large to sort"
				Gotoline "endofscript"
			Else
			
			.padding the numeric part of orig String with zeros up to 10^10
				SetVar "[NumPrefix]" ""
                    SetVar "[CNTR3]" ""
					Loop "[WholeNumLen]" "9" "[CNTR3]"
						SetVar "[NumPrefix]" "0[NumPrefix]"
					Endloop
			Endif

		SetVar "[NewEntry]" "[NumPrefix][NewNumStr]~~~~~[ThisEntryofListbox][#13]"
    ListBoxDeleteItem "[ThisListboxName]" "[CNTR]"
    ListBoxAddItem "[ThisListboxName]" "[CNTR]" "[NewEntry]"

	Endloop
	.longstring should have delineator appended and thne the original line entry into listbox and be sorted, then remove the prefix and deliminator
.replace current content with long string then sort, then remove the prefx


    ListBoxSort "[ThisListboxName]" "True"
    ListBoxSort "[ThisListboxName]" "False"

.Loop and parse each line
    ListBoxSize "[ThisListboxName]" "[Thislistboxsize]"
            Loop "1" "[ThisListboxSize]" "[CNTR5]"
                 ListBoxGetItem "[ThisListboxName]" "[CNTR5]" "[ThisEntryofListbox]"
                 StrParse "[ThisEntryofListbox]" "~~~~~" "[EntryParsed]" "[tmp]"
                 ListBoxDeleteItem "[ThisListboxName]" "[CNTR5]"
                 ListBoxAddItem "[ThisListboxName]" "[CNTR5]" "[EntryParsed2]"
             Endloop

.regenerate content?
	    SetVar "[regenListboxContent]" ""
        SetVar "[CNTR4]" ""
		Loop "1" "[Thislistboxsize]" "[CNTR4]"
		ListBoxGetItem "[ThisListboxName]" "[CNTR4]" "[ThisEntryofListbox]"
		SetVar "[regenListboxContent]" "[regenListboxContent][ThisEntryofListbox]"
		Endloop

	SetVar "[[ThisListboxContent]]" "[regenListboxContent]"
Endif
EnableObject "[ThisListboxName]"
.end sortnumeric


. create a menu
If "[lbpAct]" "=" "Menu"
    If "[lbpActLen]" ">" "1"
        GetMousePos "[MouseX]" "[MouseY]"
        StrReplace "[%2]" "," "|" "[Menustr]" ""
        StrReplace "[MenuStr]" "Menu|" "" "[MenuStr]" ""
.parse to get individual items without Menu in string
        StrParse "[MenuStr]" "|" "[MenuItem]" "[tmp]"
        .SetVar "[MenuStr]" "[#34][MouseX][#34] [#34][MouseY][#34] [#34][MenuStr][#34] [#34]-1[#34] [#34]-1[#34]"
.2nd part of menu else create full menu that will dsplay by default
        SetVar "[MenuStr2]" ""
            Loop "2" "[lbpActLen]" "[CNTR]"
                SetVar "[MenuStr2]" "[MenuStr2]Call [#34]lbplus[#34] [#34][%1][#34] [#34][lbpAct[CNTR]][#34][#13]"
            Endloop
    MenuEx "[MouseX]" "[MouseY]" "[MenuStr]" "[MenuVar]" "-1" "-1"
        If "[MenuVar]" "=" ""
            GoToLine "endofscript"
        Else
            Call "lbplus" "[%1]" "[MenuItem[MenuVar]]"
			EnableObject "[ThisListboxName]"
.null action name so no repeat of full menu
            SetVar "[%2]" ""
            GoToLine "endofscript"
        Endif
    Else


    GetMousePos "[MouseX]" "[MouseY]"
.MenuEx "[MouseX]" "[MouseY]" "" "" "-1" "-1"
    Menu "[MouseX]" "[MouseY]" "Undo|Add Item|Copy Selected|Copy All|Delete Selected|Delete All|Move UP|Move Down|De Dupe|Sort|Reverse Order|Sort Numeric" "-1" "-1"
    Call "lbplus" "[%1]" "Undo"
    Call "lbplus" "[%1]" "AddItem"
    Call "lbplus" "[%1]" "CopySelected"
    Call "lbplus" "[%1]" "CopyAll"
    Call "lbplus" "[%1]" "DeleteSelected"
    Call "lbplus" "[%1]" "DeleteAll"
    Call "lbplus" "[%1]" "MoveUp"
    Call "lbplus" "[%1]" "MoveDown"
    Call "lbplus" "[%1]" "DeDupe"
    Call "lbplus" "[%1]" "Sort"
    Call "lbplus" "[%1]" "ReverseOrder"
    Call "lbplus" "[%1]" "SortNumeric"




    Endif




Endif




EnableObject "[ThisListboxName]"
:endofscript
Here is the demo app: (create a new 640x480 app and paste the following into it) Compile to see it run faster.

Code: Select all

{NeoBook 5 Objects}
NeoBookVer=5.80
ObjectType=10
Name=ListBox1
X=152
Y=56
W=248
H=280
Anchor=0
Text=[listbox2]
VarName=[ListBox3]
VarType=1
MultiSelect=Yes
XPTheme=Yes
ObjRAction=.if you want a menu with all items, you only need to includ line #4 here¶. other lines are only used for this sample app¶If "[MS1]" "=" "Checked"¶Call "LBPlus" "listbox1,listbox2,listbox3" "menu"¶Else¶    SetVar "[NewMenu]" ""¶    Loop "2" "13" "[cntr]"¶        If "[MS[cntr]]" "=" "Checked"¶            SetVar "[NewMenu]" "[NewMenu],[Menu[CNTR]]"¶        Endif¶    Endloop¶    If "[NewMenu]" "=" ""¶        Alertbox "No action" "Nothing to do!"¶    Else¶        Call "LBPlus" "listbox1,listbox2,listbox3" "menu[NewMenu]"¶    Endif¶¶Endif
LineColor=0
LineWidth=1
LineStyle=0
FillColor=14219464
FillPattern=0
Font=Arial
FontSize=10
FontStyle=0
FontCharset=1
TextColor=0
TabOrder=1
ObjectType=9
Name=TextEntry4
X=432
Y=79
W=168
H=32
Anchor=0
VarName=[TextEntry4]
Align=1
EditLen=0
LineColor=0
LineWidth=1
LineStyle=0
FillColor=16777215
FillPattern=0
Font=Arial
FontSize=10
FontStyle=0
FontCharset=1
TextColor=0
TabOrder=2
ObjectType=8
Name=Text1
X=16
Y=8
W=168
H=40
Anchor=0
Font=Arial
FontSize=10
FontStyle=0
FontCharset=1
TextColor=0
Text={\rtf1\ansi\deff0\deftab254{\fonttbl{\f0\fnil\fcharset1 Arial;}}{\colortbl\red0\green0\blue0;\red255\green0\blue0;\red0\green128\blue0;\red0\green0\blue255;\red255\green255\blue0;\red255\green0\blue255;\red128\green0\blue128;\red128\green0\blue0;\red0\green255\blue0;\red0\green255\blue255;\red0\green128\blue128;\red0\green0\blue128;\red255\green255\blue255;\red192\green192\blue192;\red128\green128\blue128;\red0\green0\blue0;\red0\green0\blue0;}\paperw12240\paperh15840\margl1440\margr1440\margt1440\margb1440\margh720\margf720{\*\pnseclvl1\pnucrm\pnstart1\pnhang\pnindent720{\pntxtb}{\pntxta{.}}}¶{\*\pnseclvl2\pnucltr\pnstart1\pnhang\pnindent720{\pntxtb}{\pntxta{.}}}¶{\*\pnseclvl3\pndec\pnstart1\pnhang\pnindent720{\pntxtb}{\pntxta{.}}}¶{\*\pnseclvl4\pnlcltr\pnstart1\pnhang\pnindent720{\pntxtb}{\pntxta{)}}}¶{\*\pnseclvl5\pndec\pnstart1\pnhang\pnindent720{\pntxtb{(}}{\pntxta{)}}}¶{\*\pnseclvl6\pnlcltr\pnstart1\pnhang\pnindent720{\pntxtb{(}}{\pntxta{)}}}¶{\*\pnseclvl7\pnlcrm\pnstart1\pnhang\pnindent720{\pntxtb{(}}{\pntxta{)}}}¶{\*\pnseclvl8\pnlcltr\pnstart1\pnhang\pnindent720{\pntxtb{(}}{\pntxta{)}}}¶{\*\pnseclvl9\pndec\pnstart1\pnhang\pnindent720{\pntxtb{(}}{\pntxta{)}}}¶\endnhere\sectdefaultcl{\pard{\ql\li0\fi0\ri0\sb0\sl\sa0 \plain\f0\fs36\cf0 ListBox Plus}}¶}
HMargin=0
VMargin=0
LineColor=0
LineWidth=0
LineStyle=0
FillColor=16777215
FillPattern=0
TabOrder=4
ObjectType=12
Name=CheckBox1
X=16
Y=56
W=88
H=32
Anchor=0
Text=Full Menu
Align=1
VarName=[MS1]
InitState=1
ObjAction=If "[MS1]" "=" "Checked"¶Loop "2" "13" "[CNTR]"¶SetVar "[MS[CNTR]]" ""¶DisableObject "Checkbox[CNTR]"¶Endloop¶Else¶Loop "2" "13" "[CNTR]"¶EnableObject "Checkbox[CNTR]"¶Endloop¶Endif
LineColor=0
LineWidth=1
LineStyle=0
FillColor=16777215
FillPattern=0
Font=Arial
FontSize=10
FontStyle=0
FontCharset=1
TextColor=0
TabOrder=5
ObjectType=12
Name=CheckBox2
X=16
Y=148
W=80
H=20
Anchor=0
Text=Undo
Align=1
VarName=[MS2]
InitState=0
ObjAction=SetVar "[MS1]" ""¶If "[MS2]" "=" "Checked"¶    SetVar "[Menu2]" "Undo"¶Else¶    SetVar "[Menu2]" ""¶Endif
LineColor=0
LineWidth=1
LineStyle=0
FillColor=16777215
FillPattern=0
Font=Arial
FontSize=10
FontStyle=0
FontCharset=1
TextColor=0
TabOrder=6
ObjectType=12
Name=CheckBox3
X=16
Y=163
W=80
H=20
Anchor=0
Text=AddItem
Align=1
VarName=[MS3]
InitState=0
ObjAction=SetVar "[MS1]" ""¶If "[MS3]" "=" "Checked"¶    SetVar "[Menu3]" "AddItem"¶Else¶    SetVar "[Menu2]" ""¶Endif
LineColor=0
LineWidth=1
LineStyle=0
FillColor=16777215
FillPattern=0
Font=Arial
FontSize=10
FontStyle=0
FontCharset=1
TextColor=0
TabOrder=7
ObjectType=12
Name=CheckBox4
X=16
Y=177
W=120
H=20
Anchor=0
Text=CopySelected
Align=1
VarName=[MS4]
InitState=0
ObjAction=SetVar "[MS1]" ""¶If "[MS4]" "=" "Checked"¶    SetVar "[Menu4]" "CopySelected"¶Else¶    SetVar "[Menu4]" ""¶Endif
LineColor=0
LineWidth=1
LineStyle=0
FillColor=16777215
FillPattern=0
Font=Arial
FontSize=10
FontStyle=0
FontCharset=1
TextColor=0
TabOrder=8
ObjectType=12
Name=CheckBox5
X=16
Y=192
W=120
H=20
Anchor=0
Text=CopyAll
Align=1
VarName=[MS5]
InitState=0
ObjAction=SetVar "[MS1]" ""¶If "[MS5]" "=" "Checked"¶    SetVar "[Menu5]" "CopyAll"¶Else¶    SetVar "[Menu5]" ""¶Endif
LineColor=0
LineWidth=1
LineStyle=0
FillColor=16777215
FillPattern=0
Font=Arial
FontSize=10
FontStyle=0
FontCharset=1
TextColor=0
TabOrder=9
ObjectType=12
Name=CheckBox6
X=16
Y=206
W=120
H=20
Anchor=0
Text=DeleteSelected
Align=1
VarName=[MS6]
InitState=0
ObjAction=SetVar "[MS1]" ""¶If "[MS6]" "=" "Checked"¶    SetVar "[Menu6]" "DeleteSelected"¶Else¶    SetVar "[Menu6]" ""¶Endif
LineColor=0
LineWidth=1
LineStyle=0
FillColor=16777215
FillPattern=0
Font=Arial
FontSize=10
FontStyle=0
FontCharset=1
TextColor=0
TabOrder=10
ObjectType=12
Name=CheckBox7
X=16
Y=222
W=120
H=20
Anchor=0
Text=DeleteAll
Align=1
VarName=[MS7]
InitState=0
ObjAction=SetVar "[MS1]" ""¶If "[MS7]" "=" "Checked"¶    SetVar "[Menu7]" "DeleteAll"¶Else¶    SetVar "[Menu7]" ""¶Endif
LineColor=0
LineWidth=1
LineStyle=0
FillColor=16777215
FillPattern=0
Font=Arial
FontSize=10
FontStyle=0
FontCharset=1
TextColor=0
TabOrder=11
ObjectType=12
Name=CheckBox8
X=16
Y=237
W=120
H=20
Anchor=0
Text=MoveUp
Align=1
VarName=[MS8]
InitState=0
ObjAction=SetVar "[MS1]" ""¶If "[MS8]" "=" "Checked"¶    SetVar "[Menu8]" "MoveUp"¶Else¶    SetVar "[Menu8]" ""¶Endif
LineColor=0
LineWidth=1
LineStyle=0
FillColor=16777215
FillPattern=0
Font=Arial
FontSize=10
FontStyle=0
FontCharset=1
TextColor=0
TabOrder=12
ObjectType=12
Name=CheckBox9
X=16
Y=250
W=120
H=20
Anchor=0
Text=MoveDown
Align=1
VarName=[MS9]
InitState=0
ObjAction=SetVar "[MS1]" ""¶If "[MS9]" "=" "Checked"¶    SetVar "[Menu9]" "MoveDown"¶Else¶    SetVar "[Menu9]" ""¶Endif
LineColor=0
LineWidth=1
LineStyle=0
FillColor=16777215
FillPattern=0
Font=Arial
FontSize=10
FontStyle=0
FontCharset=1
TextColor=0
TabOrder=13
ObjectType=12
Name=CheckBox10
X=16
Y=265
W=120
H=20
Anchor=0
Text=DeDupe
Hint=Remove duplicate entries
Align=1
VarName=[MS10]
InitState=0
ObjAction=SetVar "[MS1]" ""¶If "[MS10]" "=" "Checked"¶    SetVar "[Menu10]" "DeDupe"¶Else¶    SetVar "[Menu10]" ""¶Endif
LineColor=0
LineWidth=1
LineStyle=0
FillColor=16777215
FillPattern=0
Font=Arial
FontSize=10
FontStyle=0
FontCharset=1
TextColor=0
TabOrder=14
ObjectType=12
Name=CheckBox11
X=16
Y=280
W=120
H=20
Anchor=0
Text=Sort
Hint=Remove duplicate entries
Align=1
VarName=[MS11]
InitState=0
ObjAction=SetVar "[MS1]" ""¶If "[MS11]" "=" "Checked"¶    SetVar "[Menu11]" "Sort"¶Else¶    SetVar "[Menu11]" ""¶Endif
LineColor=0
LineWidth=1
LineStyle=0
FillColor=16777215
FillPattern=0
Font=Arial
FontSize=10
FontStyle=0
FontCharset=1
TextColor=0
TabOrder=15
ObjectType=12
Name=CheckBox12
X=16
Y=294
W=120
H=20
Anchor=0
Text=ReverseOrder
Hint=Remove duplicate entries
Align=1
VarName=[MS12]
InitState=0
ObjAction=SetVar "[MS1]" ""¶If "[MS12]" "=" "Checked"¶    SetVar "[Menu12]" "SortReverse"¶Else¶    SetVar "[Menu12]" ""¶Endif
LineColor=0
LineWidth=1
LineStyle=0
FillColor=16777215
FillPattern=0
Font=Arial
FontSize=10
FontStyle=0
FontCharset=1
TextColor=0
TabOrder=16
ObjectType=12
Name=CheckBox13
X=16
Y=308
W=120
H=20
Anchor=0
Text=SortNumeric
Hint=Remove duplicate entries
Align=1
VarName=[MS13]
InitState=0
ObjAction=SetVar "[MS1]" ""¶If "[MS13]" "=" "Checked"¶    SetVar "[Menu13]" "SortNumeric"¶Else¶    SetVar "[Menu13]" ""¶Endif
LineColor=0
LineWidth=1
LineStyle=0
FillColor=16777215
FillPattern=0
Font=Arial
FontSize=10
FontStyle=0
FontCharset=1
TextColor=0
TabOrder=17
ObjectType=8
Name=Text2
X=10
Y=124
W=136
H=23
Anchor=0
Font=Arial
FontSize=10
FontStyle=0
FontCharset=1
TextColor=0
Text={\rtf1\ansi\deff0\deftab254{\fonttbl{\f0\fnil\fcharset1 Arial;}}{\colortbl\red0\green0\blue0;\red255\green0\blue0;\red0\green128\blue0;\red0\green0\blue255;\red255\green255\blue0;\red255\green0\blue255;\red128\green0\blue128;\red128\green0\blue0;\red0\green255\blue0;\red0\green255\blue255;\red0\green128\blue128;\red0\green0\blue128;\red255\green255\blue255;\red192\green192\blue192;\red128\green128\blue128;\red0\green0\blue0;\red0\green0\blue0;}\paperw12240\paperh15840\margl1440\margr1440\margt1440\margb1440\margh720\margf720{\*\pnseclvl1\pnucrm\pnstart1\pnhang\pnindent720{\pntxtb}{\pntxta{.}}}¶{\*\pnseclvl2\pnucltr\pnstart1\pnhang\pnindent720{\pntxtb}{\pntxta{.}}}¶{\*\pnseclvl3\pndec\pnstart1\pnhang\pnindent720{\pntxtb}{\pntxta{.}}}¶{\*\pnseclvl4\pnlcltr\pnstart1\pnhang\pnindent720{\pntxtb}{\pntxta{)}}}¶{\*\pnseclvl5\pndec\pnstart1\pnhang\pnindent720{\pntxtb{(}}{\pntxta{)}}}¶{\*\pnseclvl6\pnlcltr\pnstart1\pnhang\pnindent720{\pntxtb{(}}{\pntxta{)}}}¶{\*\pnseclvl7\pnlcrm\pnstart1\pnhang\pnindent720{\pntxtb{(}}{\pntxta{)}}}¶{\*\pnseclvl8\pnlcltr\pnstart1\pnhang\pnindent720{\pntxtb{(}}{\pntxta{)}}}¶{\*\pnseclvl9\pndec\pnstart1\pnhang\pnindent720{\pntxtb{(}}{\pntxta{)}}}¶\endnhere\sectdefaultcl{\pard{\ql\li0\fi0\ri0\sb0\sl\sa0 \plain\f0\fs20\cf0 Create right click menu}}¶}
HMargin=0
VMargin=0
LineColor=0
LineWidth=0
LineStyle=0
FillColor=16777215
FillPattern=0
TabOrder=18
ObjectType=9
Name=TextEntry5
X=433
Y=148
W=168
H=157
Anchor=0
VarName=[TextEntry5]
Align=1
EditMultiLine=Yes
EditLen=0
LineColor=0
LineWidth=1
LineStyle=0
FillColor=16777215
FillPattern=0
Font=Arial
FontSize=10
FontStyle=0
FontCharset=1
TextColor=0
TabOrder=19
ObjectType=8
Name=Text3
X=434
Y=124
W=131
H=22
Anchor=0
Font=Arial
FontSize=10
FontStyle=0
FontCharset=1
TextColor=0
Text={\rtf1\ansi\deff0\deftab254{\fonttbl{\f0\fnil\fcharset1 Arial;}}{\colortbl\red0\green0\blue0;\red255\green0\blue0;\red0\green128\blue0;\red0\green0\blue255;\red255\green255\blue0;\red255\green0\blue255;\red128\green0\blue128;\red128\green0\blue0;\red0\green255\blue0;\red0\green255\blue255;\red0\green128\blue128;\red0\green0\blue128;\red255\green255\blue255;\red192\green192\blue192;\red128\green128\blue128;\red0\green0\blue0;\red0\green0\blue0;}\paperw12240\paperh15840\margl1440\margr1440\margt1440\margb1440\margh720\margf720{\*\pnseclvl1\pnucrm\pnstart1\pnhang\pnindent720{\pntxtb}{\pntxta{.}}}¶{\*\pnseclvl2\pnucltr\pnstart1\pnhang\pnindent720{\pntxtb}{\pntxta{.}}}¶{\*\pnseclvl3\pndec\pnstart1\pnhang\pnindent720{\pntxtb}{\pntxta{.}}}¶{\*\pnseclvl4\pnlcltr\pnstart1\pnhang\pnindent720{\pntxtb}{\pntxta{)}}}¶{\*\pnseclvl5\pndec\pnstart1\pnhang\pnindent720{\pntxtb{(}}{\pntxta{)}}}¶{\*\pnseclvl6\pnlcltr\pnstart1\pnhang\pnindent720{\pntxtb{(}}{\pntxta{)}}}¶{\*\pnseclvl7\pnlcrm\pnstart1\pnhang\pnindent720{\pntxtb{(}}{\pntxta{)}}}¶{\*\pnseclvl8\pnlcltr\pnstart1\pnhang\pnindent720{\pntxtb{(}}{\pntxta{)}}}¶{\*\pnseclvl9\pndec\pnstart1\pnhang\pnindent720{\pntxtb{(}}{\pntxta{)}}}¶\endnhere\sectdefaultcl{\pard{\ql\li0\fi0\ri0\sb0\sl\sa0 \plain\f0\fs20\cf0 Paste a list (w/ CRLF)}}¶}
HMargin=0
VMargin=0
LineColor=0
LineWidth=0
LineStyle=0
FillColor=16777215
FillPattern=0
TabOrder=20
ObjectType=8
Name=Text4
X=433
Y=53
W=98
H=24
Anchor=0
Font=Arial
FontSize=10
FontStyle=0
FontCharset=1
TextColor=0
Text={\rtf1\ansi\deff0\deftab254{\fonttbl{\f0\fnil\fcharset1 Arial;}}{\colortbl\red0\green0\blue0;\red255\green0\blue0;\red0\green128\blue0;\red0\green0\blue255;\red255\green255\blue0;\red255\green0\blue255;\red128\green0\blue128;\red128\green0\blue0;\red0\green255\blue0;\red0\green255\blue255;\red0\green128\blue128;\red0\green0\blue128;\red255\green255\blue255;\red192\green192\blue192;\red128\green128\blue128;\red0\green0\blue0;\red0\green0\blue0;}\paperw12240\paperh15840\margl1440\margr1440\margt1440\margb1440\margh720\margf720{\*\pnseclvl1\pnucrm\pnstart1\pnhang\pnindent720{\pntxtb}{\pntxta{.}}}¶{\*\pnseclvl2\pnucltr\pnstart1\pnhang\pnindent720{\pntxtb}{\pntxta{.}}}¶{\*\pnseclvl3\pndec\pnstart1\pnhang\pnindent720{\pntxtb}{\pntxta{.}}}¶{\*\pnseclvl4\pnlcltr\pnstart1\pnhang\pnindent720{\pntxtb}{\pntxta{)}}}¶{\*\pnseclvl5\pndec\pnstart1\pnhang\pnindent720{\pntxtb{(}}{\pntxta{)}}}¶{\*\pnseclvl6\pnlcltr\pnstart1\pnhang\pnindent720{\pntxtb{(}}{\pntxta{)}}}¶{\*\pnseclvl7\pnlcrm\pnstart1\pnhang\pnindent720{\pntxtb{(}}{\pntxta{)}}}¶{\*\pnseclvl8\pnlcltr\pnstart1\pnhang\pnindent720{\pntxtb{(}}{\pntxta{)}}}¶{\*\pnseclvl9\pndec\pnstart1\pnhang\pnindent720{\pntxtb{(}}{\pntxta{)}}}¶\endnhere\sectdefaultcl{\pard{\ql\li0\fi0\ri0\sb0\sl\sa0 \plain\f0\fs20\cf0 Add item to list}}¶}
HMargin=0
VMargin=0
LineColor=0
LineWidth=0
LineStyle=0
FillColor=16777215
FillPattern=0
TabOrder=22
ObjectType=3
Name=PushButton26
X=540
Y=50
W=51
H=27
Anchor=0
Text=Add
Align=2
ImageStyle=0
XPTheme=Yes
ObjAction=ListBoxAddItem "ListBox1" "" "[TextEntry4]"¶SetVar "[textentry4]" ""
LineColor=0
LineWidth=1
LineStyle=0
FillColor=16777215
FillPattern=0
Font=Arial
FontSize=10
FontStyle=0
FontCharset=1
TextColor=0
TabOrder=3
ObjectType=3
Name=PushButton4
X=540
Y=309
W=51
H=27
Anchor=0
Text=Add
Align=2
ImageStyle=0
XPTheme=Yes
ObjAction=SetVar "[Listbox2]" "[textentry5]"¶SetVar "[textentry5]" ""
LineColor=0
LineWidth=1
LineStyle=0
FillColor=16777215
FillPattern=0
Font=Arial
FontSize=10
FontStyle=0
FontCharset=1
TextColor=0
TabOrder=21
ObjectType=9
Name=TextEntry3
X=24
Y=356
W=593
H=105
Anchor=0
Text=ListBox Plus¶¶usage:¶call lbplus "ListboxName,InitialContentVarName,SelectedItemVarname" "action"¶(use only the name of the variables, do not use variable brackets)¶¶lbplus is a Neobook function that adds helpful actions to the listbox including:¶¶Undo, AddItem, CopySelected, CopyAll, DeleteSelected, DeleteAll, MoveUp, MoveDown, DeDupe, Sort, ReverseOrder, SortNumeric¶¶The function attempts to synchronize the content of the listbox with the variable used to add initial content and can undo the last change made with the function.¶¶CopySelected and CopyAll puts the items in the clipboard (with a CRLF after each entry)¶¶Deleting selected items or all the entries in the listbox will put a copy of the deleted items in the clipboard.¶¶DeDupe will remove duplicates in the listbox.¶¶Sort will sort contents (alphabetically) using the ListboxSort NB command.¶¶ReverseOrder will reverse the order of all the items in the listbox.¶¶SortNumeric will sort items numerically. It will handle prefixs like currency symbols and (even inconsistent) use of commas. It appends zeros before the whole number (or the whole number part of a decimal) and then sorts. Once sorted, the prefix is removed and the original line content is displayed.¶¶Menu¶lbplus has a built in menuing system. If the function is called with just the menu job, it will create a menu with all available options. The jobs can be specified by separating the menu command with the specific jobs. Example:¶¶call lbplus "ListboxName,ContentVarName,SelectedVarName" menu,Undo,AddItem,CopySelected,DeleteSelected"¶¶and the menu displayed will only be those items.¶¶Uses in NB programming¶lbplus can be called by buttons or programmatically even if the menu is not used. If you put an entry in the actions area for the listbox under the right click tab, you can make your menu appear with a simple right click on the listbox. No additional buttons/links would be needed. (see example above)¶¶How to use:¶Put the lbplus file into your functions folder of your Neobook installation. Use the "Call" action command and you will be shown the list of functions in your folder. Choose lbplus and you will be prompted for the input items.  The first item is actually three items separated by comma: ListboxName, Name of the initial content variable, Name of the selected item variable. The second item contains the action you want to perform. You can only call one action at a time. The menu action can include a list of desired actions (separated by comma) to include in the menu. If no list is included, the menu command will show all available options.
VarName=[TextEntry3]
Align=1
EditMultiLine=Yes
EditLen=0
LineColor=0
LineWidth=1
LineStyle=0
FillColor=16777215
FillPattern=0
Font=Arial
FontSize=10
FontStyle=0
FontCharset=1
TextColor=0
TabOrder=24
Last edited by dpayer on Thu Apr 14, 2016 9:32 am, edited 1 time in total.
David Payer
Des Moines, Iowa
USA
Neosoft Support
NeoSoft Team
Posts: 5628
Joined: Thu Mar 31, 2005 10:48 pm
Location: Oregon, USA
Contact:

Re: Listbox Plus Function

Post by Neosoft Support »

Nice! Thank you David.
NeoSoft Support
User avatar
CN_Iceman
Posts: 300
Joined: Tue Mar 01, 2011 11:04 am
Location: España
Contact:

Re: Listbox Plus Function

Post by CN_Iceman »

Very interesting.
Thanks David.
Greetings/Saludos, Jose.
www.icemansoft.es
Palamar
Posts: 161
Joined: Wed Apr 06, 2005 4:34 pm

Re: Listbox Plus Function

Post by Palamar »

dplayer hello , you could send your contributions to Tna ( www.theneobookarchive.com ?. Place them on a tablet and send them to me to add them on the web . Thanks .
User avatar
agilefalcon
Posts: 11
Joined: Sat Jan 06, 2007 7:47 pm
Contact:

Re: Listbox Plus Function

Post by agilefalcon »

Thanks for the code sample - also, I really like the Neobook Archive link (TNA).

Chris
Chris Berardi
Fort Worth, TX
Locked