|
Post by valleyboy on Jul 13, 2023 8:14:49 GMT -5
Hi
In any given LB Program, you have uniquely defined [labelnames] which you can navigate to using various commands. My question is can you use variables to generate the label you want to navigate to?
For example using goto (not every programmers favourite command but it keeps thing simple)
if x=y then goto [morecode1] end if
Works fine, but is it possible somehow to expand that logic to use a variable (for example)
let nextlabel$ = "morecode" + str$(z) goto nextlabel$
I know you have the 'select case' option but was wondering if there was any other way? Hope this makes sense and also hoping this has not already been covered in another thread and I missed it.
|
|
|
Post by tsh73 on Jul 13, 2023 8:35:37 GMT -5
Hello I do not know such way. (I suspect it does not exist)
|
|
|
Post by Rod on Jul 13, 2023 13:20:42 GMT -5
If you better describe a working example I suspect we are discussing handle variables.
|
|
|
Post by xxgeek on Jul 13, 2023 14:52:54 GMT -5
If you post your code, along with your description, others will find it easier to figure out what you want, and how to get there.
|
|
|
Post by tsh73 on Jul 13, 2023 15:15:11 GMT -5
It sounds like computed GOTO in some BASICs. Alas, not in this one.
|
|
|
Post by valleyboy on Jul 13, 2023 16:20:34 GMT -5
nomainwin dim opt$(3) WindowWidth=600: WindowHeight=400 opt$(1) = "style1" opt$(2) = "style2" opt$(3) = "style3" listbox #main.list opt$(), [stylesheet],30,50,100,30 open "test" for graphics_nf_nsb as #main #main "trapclose [close]" print #main.list, "font verdana 12" print #main, "font verdana 18" #main "place 20 30": #main "\Chose a style sheet" wait
[stylesheet] print #main.list,"selection? style$"
' select works
select case style$ case "style1" gosub [style1] case "style2" gosub [style2] case "style3" gosub [style3] end select wait
[close] close #main stop
' let stylelabel$ = style$ ' goto stylelabel$
[style1] print #main, "font verdana 20" print #main, "color red" #main "place 20 130": #main "\" + style$ return
[style2] print #main, "font arial 16" print #main, "color blue" #main "place 20 130": #main "\" + style$ return
[style3] print #main, "font courier 24" print #main, "color green" #main "place 20 130": #main "\" + style$ return
|
|
|
Post by valleyboy on Jul 13, 2023 16:28:28 GMT -5
I've put together some sample code - apologies as not used to doing this sort of this. The actual project I'm working on gives the user the option to skin the UI in more than one way. I was exploring ways of how best to manage this requirement without resorting to case and if statements.
The 2 lines of code I've commented out would be my nirvana - take the new style and jump to or execute the appropriate code at a specific label. The name of this label being derived from a variable consisting in part, the stylesheet of choice. As I said from the off, I know there are a number of methods I could apply to avoid the need for this feature but based on previous experience with this forum, you guys seem to know a trick or two.
|
|
|
Post by Walt Decker on Jul 13, 2023 17:37:58 GMT -5
Personally, I would get rid of the graphics window and use a function to select the style.
|
|
|
Post by xxgeek on Jul 13, 2023 18:24:55 GMT -5
Here is your code back, edited to make it more up to date. We no longer need to use the word 'print' when dealing with #(handles) eg: print #main.list, "font verdana 18" is now written #main.list "font verdana 18" - notice there is no comma after list either. Added #main "cls" - to clear old style leftovers when selecting a new style from the list. I also added singleclick select for the listbox. Easier on the mouse button, and old man fingers than doubleclick Just a thought nomainwin dim opt$(3) WindowWidth=600: WindowHeight=400 opt$(1) = "style1" opt$(2) = "style2" opt$(3) = "style3" listbox #main.list opt$(), [stylesheet],30,50,100,25 open "test" for graphics_nf_nsb as #main #main "trapclose [close]" #main.list "font verdana 12" #main "font verdana 18" #main "place 20 30": #main "\Chose a style sheet" #main.list "singleclickselect" wait
[stylesheet] #main.list "selection? style$" ' select works select case style$ case "style1" gosub [style1] case "style2" gosub [style2] case "style3" gosub [style3] end select wait
[close] close #main end ' let stylelabel$ = style$ ' goto stylelabel$ [style1] #main "cls" #main "font verdana 20" #main "color red" #main "place 20 130": #main "\" + style$ return
[style2] #main "cls" #main "font arial 16" #main "color blue" #main "place 20 130": #main "\" + style$ return
[style3] #main "cls" #main "font courier 24" #main "color green" #main "place 20 130": #main "\" + style$ return
Hope this helps. Is this working as you'd like it to, even before the edits, since you used 'case'?
|
|
|
Post by Walt Decker on Jul 14, 2023 0:31:31 GMT -5
Here is a little trick: ' C0$ = CHR$(0) DIM Options$(2) Options$(0) = "Opt 1" + C0$ + "," + "font 1," + "color 1" Options$(1) = "Opt 2" + C0$ + "," + "font 2," + "color 2" Options$(2) = "Opt 3" + C0$ + "," + "fort 3," + "color 3"
LISTBOX #OPT.LBX, Options$(), [OPTIONS], 5, 5, 90, 80
OPEN "OPTIONS" FOR WINDOW AS #OPT #OPT, "TRAPCLOSE CLOSE.OPT" [BEGIN.WAIT] WAIT
'-------------------- '--------------------
SUB CLOSE.OPT OptHndl$ CLOSE #OPT END
END SUB
'-------------------- '--------------------
[OPTIONS] '############################################### ' here use LB's list box functios to get the ' index # of the selected item and subtract 1 ' from the index to find the array element selected. ' use WORD$ to get the option parameters from the array element. '###############################################
GOTO [BEGIN.WAIT] '
|
|
|
Post by valleyboy on Jul 14, 2023 11:52:55 GMT -5
Thanks for the replies, every day is a school day
|
|