|
Post by sundale on Dec 29, 2009 8:49:13 GMT -5
Having difficulties in ListBox initial value setting. I cannot get the expected results. I have tried following code: ' list of shop code - 12 items shoplist$ = "CH,HH,HC,HS,TO,KI,SH,WH,CS,ET,AG,YJ" idcount = 12
' allocate listbox array dim shopgroup$(idcount) for x = 1 to idcount shopgroup$(x)=word$(shoplist$, x, ",") next x
' set initial value for listbox curID$ = "TO" idx = 5 htmlcode = 1
print chr$(160) if htmlcode then html "<TABLE><TR><TD align=right>" html "Shop Code:</TD><TD>" else print "Shop Code:" end if
listbox #shopchoice, shopgroup$(), 0
if htmlcode then html "</TD></TR><TR><TD>" print " "
#shopchoice select(idx) print "initial setup" print "=============" print "index = "; idx; "("; #shopchoice selection(); ")" print "selection = "; #shopchoice selection$() print " "
link #conf, "[OK]", [showSelected] link #can, "[Cancel]", [cancel] if htmlcode then html "</TD></TR></TABLE>" wait
[showSelected] print " " print "Result values" print "=============" print "index = "; #shopchoice selection() print "choice = "; #shopchoice selection$()
[cancel] end
The result shows bellow: Shop Code: KI initial setup ============= index = 5(5) selection = 5 [OK][Cancel] Result values ============= index = 0 choice = KI Why? 1) The initial value has been set properly at initial time index=5 2) But, the listbox still shows the first item 3) After "OK" is clicked the result is not correct index=0 4) But, the string value is correct. How? 1) do I make it display fifth item "TO" at initial time? 2) if the user change the item, any method to understand that event occured? so that I can display other items accordingly? ex) Actual Name from the code selected.
|
|
|
Post by sundale on Dec 29, 2009 9:00:51 GMT -5
Also, at initial setup, the selection should be string "TO" instead of numeric value 5.
The second question under How, is to make the program more interactive - responding user input and verifying whether the selection is correct.
|
|
|
Post by JackWebb on Dec 29, 2009 22:30:06 GMT -5
Sundale, Nothing wrong with your logic except that the variable curID$ was not being used anywhere in the program. the line that says #shopchoice select(idx) is what gives you the 5 instead of the word "TO".. Change the line to #shopchoice select(curID$) and it will return "TO" but you probably already knew that. Other than that, there isn't an index anywhere. The statement #shopchoice selection() is not a valid runbasic statement as far as I know. I searched the wikki and could not find that method so it's always 0. Why it prints 5 is beyond me... Looks like 5 might be a string  I rewrote some sections, seems to work ok. By the way, nice work! ' allocate listbox array dim shopgroup$(12) gosub [LoadArray] ' set initial value for listbox idx = 5 'make "TO" initial (default) setting shopgroup$(0) = shopgroup$(idx) 'assign default setting to array 0 htmlcode = 1 print chr$(160) if htmlcode then html "<TABLE><TR><TD align=right>" html "Shop Code:</TD><TD>" else print "Shop Code:" end if listbox #shopchoice, shopgroup$(), 1 if htmlcode then html "</TD></TR><TR><TD>" end if print " " print "initial setup" print "=============" print "index = "; idx; "("; shopgroup$(idx); ")" print "selection = "; shopgroup$(idx) print " " link #conf, "[OK]", [showSelected] link #can, "[Cancel]", [cancel] if htmlcode then html "</TD></TR></TABLE>" end if wait [showSelected] gosub [LoadArray] for idx = 0 to 12 if shopgroup$(idx) = #shopchoice selection$() then exit for end if next idx print " " print "Result values" print "=============" print "index = "; idx print "choice = "; #shopchoice selection$() [cancel] end [LoadArray] restore for idx = 0 to 12 read shopgroup$(idx) next idx return ' data section data "--", "CH", "HH", "HC", "HS", "TO", "KI", "SH", "WH", "CS", "ET", "AG", "YJ"
Happy New Year! ;D
|
|
|
Post by sundale on Dec 29, 2009 23:26:45 GMT -5
Hi Jack, Thanks for your help.
The main idea is to set the initial value to array zero. Just adding one line worked as desired.
shopgroup$(0)= shopgroup$(idx)
I have seen the selection() statement from the "Run BASIC Document" the help file in the Run Basic - section LISTBOX methods. Anyway learned new stuff!
Happy New Year!!!
|
|
|
Post by JackWebb on Dec 30, 2009 20:05:53 GMT -5
Hey Sundale thanks! I found the method in the RunBasic documentaion. From the documentation: LISTBOX methods #handle SELECTION() - Return the current selection as a number. #handle SELECTION$() - Return the current selection as a string. So if i'm reading this correctly selection() should work the same way selection$() does, but it always returns 0. ' allocate listbox array dim shopgroup$(12) gosub [LoadArray]
' set initial value for listbox idx = 5 'make "TO" initial (default) setting shopgroup$(0) = shopgroup$(idx) 'assign default setting to array 0
htmlcode = 1 print chr$(160) if htmlcode then html "<TABLE><TR><TD align=right>" html "Shop Code:</TD><TD>" else print "Shop Code:" end if listbox #shopchoice, shopgroup$(), 1 if htmlcode then html "</TD></TR><TR><TD>" end if print " " print "initial setup" print "=============" print "index = "; idx; "("; shopgroup$(idx); ")" print "selection = "; shopgroup$(idx) print " " link #conf, "[OK]", [showSelected] link #can, "[Cancel]", [cancel] if htmlcode then html "</TD></TR></TABLE>" end if wait [showSelected] gosub [LoadArray] for idx = 0 to 12 if shopgroup$(idx) = #shopchoice selection$() then exit for end if next idx print " " print "Result values" print "=============" print "index from idx = "; idx print "index from selection() = "; #shopchoice selection() print "choice from selection$() = "; #shopchoice selection$() [cancel] end [LoadArray] restore for idx = 0 to 12 read shopgroup$(idx) next idx return ' data section data "--", "CH", "HH", "HC", "HS", "TO", "KI", "SH", "WH", "CS", "ET", "AG", "YJ"
|
|
|
Post by sundale on Dec 31, 2009 1:04:20 GMT -5
Right! we need to move this topic to bug report, but I do not know how to do it. Anyone can help?
|
|
|
Post by StefanPendl on Dec 31, 2009 12:15:32 GMT -5
Right! we need to move this topic to bug report, but I do not know how to do it. Only moderators can move threads. I have been struggling with this before and there is already a bug report, which turned out to be an enhancement request. There is nothing wrong with both methods, but there is currently no method to get the array index of the selected item. selection() is the same as val(selection$()).
|
|
|
Post by rich357 on Jan 1, 2010 2:29:50 GMT -5
This has been discussed before as I brought up the same question once last year. The only other way for now is to physically number the items. Then selection() will return the number. Since selection$() returns a string, the value will always be 0 (zero).
I believe Carl had mentioned he was working on getting indexing to work with it.
|
|
metro
Full Member
 
Posts: 179
|
Post by metro on Sept 14, 2015 21:18:37 GMT -5
I should have searched here first very frustrating hope the next release solves this
|
|