|
Post by windfire on Jan 24, 2022 18:26:02 GMT
Back to my original question. I want to know if there is a better way to link the key to the label . Rather than a page of if >> then's and gosub's something like { case 0.5968 ; gosub [048574]:case 0.5968 ; gosub [048574]---
|
|
|
Post by tsh73 on Jan 24, 2022 19:59:47 GMT
Suppose you have a table of pairs key label key1 label1 key2 label2 ... ? So then you get key to find you search a table and get corresponding label.
I see some problems 1) there no way to actually call that label from JB. You can generate string "gosub [048574]" but you can't run it.
But - from a table, you can generate whole program of
if key1=keyToFind then [label1] if key2=keyToFind then [label2]
You even could run that generated program (jbasic.exe -r -a your_program.bas) Will it help you?
Probably you should look at another language/tool? Like, one that from string "[048574]" you can make code
gosub [048574] and execute it? (I have no idea if this tool exists at all, but making JB doing this for me amounts to writing new language, and that's a huge task IMHO)
2) so if we have table of pairs (key label), there by "key" you get label. That sounds like database to me. And some databases could execute code from text stored in a table So may be not (key label) but (key code_to_be_executed) ?
3) in some languages (:python) there are dictionaries (key=>value) AND "value" itself could be a function AND you can create functions on the fly (sorry, I just read about it, never tried myself) Now with this you probably make your code write itself. (But as I understand there no GOTO in python, at all. So GOTO approach just will not do.)
|
|
|
Post by Brandon Parker on Jan 24, 2022 20:02:17 GMT
Have you looked at the Select Case functionality? There are tons of variations you can achieve...
var = 2
Select Case var Case 1 Print "var = 1" Case 2 Print "var = 2" Case Else Print "var = ";var End Select
var2 = 1 Select Case Case (var = 1) Print "var = 1" Case (var = 2) And (var2 = 1) Print "var = 2 and var2 = 1" Case Else Print "var = ";var End Select
{:0)
Brandon Parker
|
|
|
Post by windfire on Jan 24, 2022 23:02:15 GMT
tsh73 thank's that's how I've been doing it. Just wondering if I missed a better way. Look's like it takes up a lot of room that way.I don't know.
|
|
|
Post by windfire on Jan 24, 2022 23:09:20 GMT
Thank's to all you.Appreciate your help.Till next_time .
|
|