Source language: Translate to:

Change attribute of Listbox

Questions about using NeoBook's scripting language

Moderator: Neosoft Support

Change attribute of Listbox

Postby dpayer » Tue Jun 26, 2012 1:43 pm

Is there a way to change the attributes of a listbox in real time?

If not at the present time, would it be feasible to have the following NB Actions in the future?:
Code: Select all
SetListBoxVar "Listbox1" "MultiSelect"
SetListBoxVar "Listbox1" "SingleSelect"
SetListBoxVar "ListBox1" "ItemNumber"
SetListBoxVar "Listbox1" "ItemText"


David P
User avatar
dpayer
 
Posts: 1383
Joined: Mon Apr 11, 2005 5:55 am
Location: Iowa - USA

Postby Gaev » Tue Jun 26, 2012 3:21 pm

David P:
would it be feasible to have the following NB Actions in the future?:
Until then, if you choose the Variable Contains: Item number (1,2,3) option ... you can then easily get the corresponding Item text if you place this command in the object's Selection Changed section ...
Code: Select all
ListBoxGetItem "ListBox1" "[ListBox1]" "[ListBox1Text]"
User avatar
Gaev
 
Posts: 3736
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada

Postby dpayer » Tue Jun 26, 2012 5:00 pm

Gaev wrote:David P:
would it be feasible to have the following NB Actions in the future?:
Until then, if you choose the Variable Contains: Item number (1,2,3) option ... you can then easily get the corresponding Item text if you place this command in the object's Selection Changed section ...
Code: Select all
ListBoxGetItem "ListBox1" "[ListBox1]" "[ListBox1Text]"


True, that one has a good workaround. The issue I wanted to address most was that of having a listbox sometimes be single select and other times be multiple select. The workaround for that is to create a second listbox and export everything from one to the other then allow the multiple select and reimport the remainin back into the first listbox.

So much of what we do are workarounds!

thanks.

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

Postby Gaev » Tue Jun 26, 2012 5:24 pm

David P:
The issue I wanted to address most was that of having a listbox sometimes be single select and other times be multiple select. The workaround for that is to create a second listbox and export everything from one to the other then allow the multiple select and reimport the remainin back into the first listbox.
a) It might be a good idea to have two ListBox objects anyway ... on account of how the selections are returned to you.

b) But you might be able to avoid the export/reimport stuff if ... instead of hard coding the Items at Design Time ... you specified a variable for List Items: ... e.g. [ListItems] ... which you populate in your pub's Start Up section ... then all you need to do is place one object exactly on top of another ... and Hide/Show as required ... ok, I haven't tried this before ... so it may have flaws.
User avatar
Gaev
 
Posts: 3736
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada

Postby dpayer » Wed Jun 27, 2012 7:01 am

Gaev wrote:David P:

b) But you might be able to avoid the export/reimport stuff if ... instead of hard coding the Items at Design Time ... you specified a variable for List Items: ... e.g. [ListItems] ... which you populate in your pub's Start Up section ... then all you need to do is place one object exactly on top of another ... and Hide/Show as required ... ok, I haven't tried this before ... so it may have flaws.


I have found that using a variable to populate a listbox works the first time but if you try to update the variable and then refresh the listbox, the items are not included, you must add them.

Exporting from and Importing to listboxes has become much easier since creating Listbox Functions.

Thanks for your input.

David P.
User avatar
dpayer
 
Posts: 1383
Joined: Mon Apr 11, 2005 5:55 am
Location: Iowa - USA

Postby Gaev » Wed Jun 27, 2012 9:43 am

DavidP:

I have found that using a variable to populate a listbox works the first time but if you try to update the variable and then refresh the listbox, the items are not included, you must add them.
I just did a test ...

1) ListBox named Fruits ... List Items: [FruitList] ... Variable: [Fruits] ... with script ...
Code: Select all
AlertBox "Selected" "[Fruits]"


2) Button with script ...
Code: Select all
SetVar "[FruitList]" "Apples[#13]Bananas[#13]Cherries"


3) Button with script ...
Code: Select all
SetVar "[FruitList]" "Pears[#13]Peaches[#13]Pineapples"



I clicked on the two Buttons (multiple times) ... and after each click, I clicked on a List Item ... all worked as expected.

Note: I did NOT do any kind of Refresh functions.

Wonder what you were doing differently ... was the ListBox visible when you tried populating a new list ? ... with NeoBook I have found that when objects are hidden (or behind other objects), the face text is not updated.
User avatar
Gaev
 
Posts: 3736
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada

Postby dpayer » Thu Jun 28, 2012 8:02 am

Gaev wrote:Wonder what you were doing differently ... was the ListBox visible when you tried populating a new list ? ... with NeoBook I have found that when objects are hidden (or behind other objects), the face text is not updated.


Here is the scenario I ran into.

Listbox & text entry box
Button1 = add contents from multiline text entry box to listbox variable
Button2 - delete selected item from listbox

OK - type a few lines into text entry box and then click button1, it then adds to the list box as expected.
Next, remove an entry to the listbox via button2
Now, click button1 again to push the original values into the listbox. Nothing changes, the original list is not restored, the list with the deleted item remains.
If I change anything in the text entry box and then click button1, it will put that into the listbox as expected.

David

edit: I just tested changing the button from the sample below so that it first resets the variable ("") used to populate the listbox and then establishes the values for it from the text entry field. This DOES then properly populate the listbox.


Sample pub, remember to remove spaces at the end of each line (I use Word to do this then save again as a text/pub file).
Code: Select all
NBW Publication Source File
(C)1993-2011 NeoSoft Corp.
Title=Untitled NeoBook Publication
Language=US
NeoBookVer=5.70
ScreenColors=16777216
ScreenWidth=640
ScreenHeight=480
BkndColor=0
ScreenAutoSize=Yes
LinkColor=16711680
WindowStyle=0
WindowOrder=0
WindowPos=0
WindowProps=31
BiDiMode=0
UseUpdateTimer=Yes
ReturnTime=60
ShapeTransColor=536870912
CompileType=0
MediaType=0
FilesIncluded=1
FontsIncluded=2
CopyExternalFiles=No
SetupMedia=3
SetupInstDir=C:\MyProgram
SetupTitle=Setup
SetupColors=16711680|0|65535
VersionMajor=1
VersionMinor=0
VersionRelease=0
VersionBuild=0
ReqExLevel=1
CustomFontName=Arial
CustomFontSize=9
CustomFontStyle=0
CustomCharset=1
CacheSize=30
ExtractOp=132
L_OK=OK
L_CANCEL=Cancel
L_YES=Yes
L_NO=No
L_CLOSE=Close
L_ERRORTITLE=Error
L_FINDTITLE=Find
L_FINDPROMPT=Find &What
L_FINDFIRST=&Find First
L_FINDNEXT=Find &Next
L_FINDERROR=Search text not found.
L_PWORDTITLE=Password required
L_PWORDMSG=Before continuing, you must first|enter the correct password.
L_PWORDPROMPT=&Password:
L_PWORDERROR=That's not the right password!
L_MEDIAERROR=In order to play this type of file you must install|the appropriate multimedia hardware and/or|software.
L_INTERNETERROR=Unable to locate Internet Browser software.
L_ABORTFUNCTION=Do you want to cancel this function?
L_EXTRACTERROR=This file could not be extracted and cannot be played.
L_INSTDIRPROMPT=Please enter the drive and directory where you would like this program to be installed. To accept the default drive and directory, simply press Enter.
L_INSTFOLDERPROMPT=Do you wish to create a program folder?
L_INSTRUNPROMPT=Do you want to run
L_INSTDISKPROMPT=Please insert disk #
L_INSTDISKERROR=That's not the correct disk, try again.
L_INSTGENERROR=The installation has terminated.
L_INSTEXITPROMPT=Do you really want to cancel the installation?
L_INSTWINTITLE=Setup
L_INSTPROGTITLE=Extracting Files...
L_SENDEMAIL=Sending Mail...
L_MAILSERVER=Please enter the name of your outgoing email server:
L_COPY=Copy to Clipboard
L_SELECTALL=Select All
L_DONWLOADFILE=Downloading: %s
L_PLEASEWAIT=Please wait...
TrayMenuBegin
MenuName=TrayOpen
MenuText=Open
MenuState=3
MenuKey=0
MenuAction=SetVar "[WindowState]" "Normal"
MenuName=TrayExit
MenuText=Exit
MenuState=3
MenuKey=0
MenuAction=Exit "" ""
MenuEnd
MasterPage
NewPage=New Page
PageStyle=0
PageColor=16777215
PageGradient1=16711680
PageGradient2=255
PageGradientDir=1
WallpaperStyle=0
ObjectType=10
Name=ListBox1
X=400
Y=64
W=200
H=352
Anchor=0
Text=[testlist]
VarName=[selected]
VarType=1
XPTheme=Yes
LineColor=0
LineWidth=1
LineStyle=0
FillColor=16777215
FillPattern=1
Font=Arial
FontSize=10
FontStyle=0
FontCharset=1
TextColor=0
TabOrder=2
ObjectType=3
Name=PushButton1
X=48
Y=376
W=136
H=48
Anchor=0
Text=Reset listbox
Align=2
ImageStyle=0
XPTheme=Yes
ObjAction=SetVar "[testlist]" "[TextEntry1]"
LineColor=0
LineWidth=1
LineStyle=0
FillColor=16777215
FillPattern=1
FillMode=Yes
Font=Arial
FontSize=10
FontStyle=0
FontCharset=1
TextColor=0
TabOrder=3
ObjectType=3
Name=PushButton2
X=472
Y=432
W=128
H=24
Anchor=0
Text=Delete Selected
Align=2
ImageStyle=0
XPTheme=Yes
ObjAction=ListBoxDeleteItem "ListBox1" "[selected]"
LineColor=0
LineWidth=1
LineStyle=0
FillColor=16777215
FillPattern=1
FillMode=Yes
Font=Arial
FontSize=10
FontStyle=0
FontCharset=1
TextColor=0
TabOrder=4
ObjectType=9
Name=TextEntry1
X=40
Y=208
W=144
H=152
Anchor=0
VarName=[TextEntry1]
EditMultiLine=Yes
WordWrap=No
EditLen=0
LineColor=0
LineWidth=1
LineStyle=0
FillColor=16777215
FillPattern=1
FillMode=Yes
Font=Arial
FontSize=10
FontStyle=0
FontCharset=1
TextColor=0
TabOrder=5
ObjectType=8
Name=Text1
X=48
Y=168
W=256
H=24
Anchor=0
Font=Arial
FontSize=10
FontStyle=0
FontCharset=1
TextColor=0
Text={\rtf1\ansi\deff0\deftab254{\fonttbl{\f0\fnil\fcharset1 Arial;}}{\pard{\ql\li0\fi0\ri0\sb0\sl\sa0 \plain\f0\fs20\cf0 Add entries, one per line}}}
HMargin=4
VMargin=4
LineColor=0
LineWidth=0
LineStyle=0
FillColor=16777215
FillPattern=1
TabOrder=6
User avatar
dpayer
 
Posts: 1383
Joined: Mon Apr 11, 2005 5:55 am
Location: Iowa - USA

Postby Gaev » Thu Jun 28, 2012 9:25 am

DavidP:

Thank you for the detailed scenario.

I did not use your pub source ... just added to my Lab example.

I noticed the same results ... but it is a problem only after a delete (via script) of the selected item ... I think this is because the ListBoxDeleteItem causes the Variable: (to contain selected item) to be "gone" (not shown in the Debugger) ... and a subsequent command to populate the "Item List" is not serviced.

Fortunately, there is a workaround ...
Code: Select all
SetVar "[FruitList]" ""
SetVar "[FruitList]" "[NewFruits]"

... where [NewFruits] is the multiline Text Entry object and [FuitList] is the variable specified for the ListBox.

Also works when I change my Button code to ...
Code: Select all
SetVar "[FruitList]" ""
SetVar "[FruitList]" "Apples[#13]Bananas[#13]Cherries"
User avatar
Gaev
 
Posts: 3736
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada


Return to NeoBook Action Commands

Who is online

Users browsing this forum: No registered users and 2 guests