Re: [Ql-Users] Select on
I have a vague recollection that Simon N Goodwin did something similar, maybe, in the DIY Toolkit. I think it was passed a variable and a list of strings, and returned the position of the variable in the list. Something like that. Maybe useful? Cheers, Norm. -- Sent from my Android device with K-9 Mail. Please excuse my brevity. ___ QL-Users Mailing List
Re: [Ql-Users] Select on
Op Sun, 21 Jun 2020 09:46:23 +0200 schreef Norman Dunbar via Ql-Users : I have a vague recollection that Simon N Goodwin did something similar, maybe, in the DIY Toolkit. I think it was passed a variable and a list of strings, and returned the position of the variable in the list. Something like that. Maybe useful? That would then be the PICK$ function. It's on DIY disk 1, sub E, found on Dilwyn's site, where else? Bob -- The BSJR QL software site at: "http://home.hccnet.nl/b.spelten/ql/"; -- Deze e-mail is gecontroleerd op virussen door AVG. http://www.avg.com ___ QL-Users Mailing List
Re: [Ql-Users] Select on
That's probably the best solution for the problem - String$ SELECT has always been a half-baked solution in SuperBASIC. Tobias > Am 21.06.2020 um 13:38 schrieb Bob Spelten via Ql-Users > : > > Op Sun, 21 Jun 2020 09:46:23 +0200 schreef Norman Dunbar via Ql-Users > : > >> I have a vague recollection that Simon N Goodwin did something similar, >> maybe, in the DIY Toolkit. >> >> I think it was passed a variable and a list of strings, and returned the >> position of the variable in the list. Something like that. >> >> Maybe useful? >> > That would then be the PICK$ function. > It's on DIY disk 1, sub E, found on Dilwyn's site, where else? > > Bob > > -- > The BSJR QL software site at: "http://home.hccnet.nl/b.spelten/ql/"; > > -- > Deze e-mail is gecontroleerd op virussen door AVG. > http://www.avg.com > > ___ > QL-Users Mailing List ___ QL-Users Mailing List
Re: [Ql-Users] Select on
If we are talking about Selecting on single-character strings, such as when coding actions depending on some keypress, I would like to tell you about how I get around this problem. At the very beginning, I would declare some constants of the codes of all the alphabetical characters, all 52 of them. Underscores are used in the names to highlight these vars are constants and their initial values should not change. I will give what the code would look like under Minerva, and then how this would look in SMSQ/E. Note that when Selecting on strings, both cases, capitals and lower case letters are considered equivalent. This has to be taken into account. 100 : 110 :120 REMark In Minerva SuperBASIC130 case$ = "" : REMark "a" == "A" - both cases140 SELect ON case$150 = "a" : PRINT 'Choice is "A"'160 = "b" : PRINT 'Choice is "B"'170 = "c" : PRINT 'Choice is "C"'180 = "d" : PRINT 'Choice is "D"'190 = "e" : PRINT 'Choice is "E"'200 = "f" : PRINT 'Choice is "F"'210 = CHR$(27) : PRINT 'Esc pressed'220 END SELect230 :2000 REMark In SMSQ/E S*BASIC2010 REMark Note: MANIFEST is optional TURBO command for extra constant checking2020 :2030 MANIFEST : _a = 97 : A_ = 652040 MANIFEST : _b = 98 : B_ = 662050 MANIFEST : _c = 99 : C_ = 672060 MANIFEST : _d = 100 : D_ = 682070 MANIFEST : _e = 101 : E_ = 692080 MANIFEST : _f = 102 : F_ = 702090 MANIFEST : ENTER = 10 : Esc = 272100 CLS2110 REPeat loop2120 PRINT 'Choose case: Press a letter between "a" and "F" ';2130 case = CODE(INKEY$(#1,-1)) : IF case <> ENTER : PRINT CHR$(case); " ";2140 SELect ON case2150 = _a,A_ : PRINT 'Choice is "A"'2160 = _b,B_ : PRINT 'Choice is "B"'2170 = _c,C_ : PRINT 'Choice is "C"'2180 = _d,D_ : PRINT 'Choice is "D"'2190 = _e,E_ : PRINT 'Choice is "E"'2200 = _f,F_ : PRINT 'Choice is "F"'2210 = Esc : PRINT 'Esc pressed' : EXIT loop2220 = REMAINDER : PRINT 'Try again'2230 END SELect2240 END REPeat loop2250 PRINT 'Test complete'2260 PRINT #0,'Test complete' Michael ___ QL-Users Mailing List
Re: [Ql-Users] Ql-Users Digest, Vol 196, Issue 7
Sent from Yahoo Mail on Android On Sun, 21 Jun 2020 at 21:04, ql-users-requ...@lists.q-v-d.com wrote: Send Ql-Users mailing list submissions to ql-users@lists.q-v-d.com To subscribe or unsubscribe via the World Wide Web, visit http://lists.q-v-d.com/listinfo.cgi/ql-users-q-v-d.com or, via email, send a message with subject or body 'help' to ql-users-requ...@lists.q-v-d.com You can reach the person managing the list at ql-users-ow...@lists.q-v-d.com When replying, please edit your Subject line so it is more specific than "Re: Contents of Ql-Users digest..." Today's Topics: 1. Re: Select on (Michael Bulford) -- Message: 1 Date: Sun, 21 Jun 2020 19:53:50 + (UTC) From: Michael Bulford To: ql-users@lists.q-v-d.com Subject: Re: [Ql-Users] Select on Message-ID: <100179.2817707.1592769230...@mail.yahoo.com> Content-Type: text/plain; charset=UTF-8 If we are talking about Selecting on single-character strings, such as when coding actions depending on some keypress, I would like to tell you about how I get around this problem.? At the very beginning, I would declare some constants of the codes of all the alphabetical characters, all 52 of them.? Underscores are used in the names to highlight these vars are constants and their initial values should not change.? I will give what the code would look like under Minerva, and then how this would look in SMSQ/E. Note that when Selecting on strings, both cases, capitals and lower case letters are considered equivalent.? This has to be taken into account. 100 :? 110 :120 REMark In Minerva SuperBASIC130 case$ = "" : REMark "a" == "A" - both cases140 SELect ON case$150 = "a" : PRINT 'Choice is "A"'160 = "b" : PRINT 'Choice is "B"'170 = "c" : PRINT 'Choice is "C"'180 = "d" : PRINT 'Choice is "D"'190 = "e" : PRINT 'Choice is "E"'200 = "f" : PRINT 'Choice is "F"'210 = CHR$(27) : PRINT 'Esc pressed'220 END SELect230 : 2000 REMark In SMSQ/E S*BASIC2010 REMark Note: MANIFEST is optional TURBO command for extra constant checking2020 :2030 MANIFEST : _a =? 97 : A_ = 652040 MANIFEST : _b =? 98 : B_ = 662050 MANIFEST : _c =? 99 : C_ = 672060 MANIFEST : _d = 100 : D_ = 682070 MANIFEST : _e = 101 : E_ = 692080 MANIFEST : _f = 102 : F_ = 702090 MANIFEST : ENTER = 10 : Esc = 272100 CLS2110 REPeat loop2120 PRINT 'Choose case: Press a letter between "a" and "F" ';2130 case = CODE(INKEY$(#1,-1)) : IF case <> ENTER : PRINT CHR$(case); " ";2140 SELect ON case2150 = _a,A_ : PRINT 'Choice is "A"'2160 = _b,B_ : PRINT 'Choice is "B"'2170 = _c,C_ : PRINT 'Choice is "C"'2180 = _d,D_ : PRINT 'Choice is "D"'2190 = _e,E_ : PRINT 'Choice is "E"'2200 = _f,F_ : PRINT 'Choice is "F"'2210 = Esc? ?: PRINT 'Esc pressed' : EXIT loop2220 = REMAINDER : PRINT 'Try again'2230 END SELect2240 END REPeat loop2250 PRINT 'Test complete'2260 PRINT #0,'Test complete' Michael -- Subject: Digest Footer ___ QL-Users mailing list -- End of Ql-Users Digest, Vol 196, Issue 7 Think this is a tidied/readable version.. ___ QL-Users Mailing List
Re: [Ql-Users] Select on
If we are talking about Selecting on single-character strings, such as when coding actions depending on some keypress, I would like to tell you about how I get around this problem. At the very beginning, I would declare some constants of the codes of all the alphabetical characters, all 52 of them. Underscores are used in the names to highlight these vars are constants and their initial values should not change. I will give what the code would look like under Minerva, and then how this would look in SMSQ/E. Note that when Selecting on strings, both cases, capitals and lower case letters are considered equivalent. This has to be taken into account. 100 : 110 : 120 REMark In Minerva SuperBASIC 130 case$ = "" : REMark "a" == "A" - both cases 140 SELect ON case$ 150 = "a" : PRINT 'Choice is "A"' 160 = "b" : PRINT 'Choice is "B"' 170 = "c" : PRINT 'Choice is "C"' 180 = "d" : PRINT 'Choice is "D"' 190 = "e" : PRINT 'Choice is "E"' 200 = "f" : PRINT 'Choice is "F"' 210 = CHR$(27) : PRINT 'Esc pressed' 220 END SELect 230 : 2000 REMark In SMSQ/E S*BASIC 2010 REMark Note: MANIFEST is optional TURBO command for extra constant checking 2020 : 2030 MANIFEST : _a = 97 : A_ = 65 2040 MANIFEST : _b = 98 : B_ = 66 2050 MANIFEST : _c = 99 : C_ = 67 2060 MANIFEST : _d = 100 : D_ = 68 2070 MANIFEST : _e = 101 : E_ = 69 2080 MANIFEST : _f = 102 : F_ = 70 2090 MANIFEST : ENTER = 10 : Esc = 27 2100 CLS 2110 REPeat loop 2120 PRINT 'Choose case: Press a letter between "a" and "F" '; 2130 case = CODE(INKEY$(#1,-1)) : IF case <> ENTER : PRINT CHR$(case); " "; 2140 SELect ON case 2150 = _a,A_ : PRINT 'Choice is "A"' 2160 = _b,B_ : PRINT 'Choice is "B"' 2170 = _c,C_ : PRINT 'Choice is "C"' 2180 = _d,D_ : PRINT 'Choice is "D"' 2190 = _e,E_ : PRINT 'Choice is "E"' 2200 = _f,F_ : PRINT 'Choice is "F"' 2210 = Esc : PRINT 'Esc pressed' : EXIT loop 2220 = REMAINDER : PRINT 'Try again' 2230 END SELect 2240 END REPeat loop 2250 PRINT 'Test complete' 2260 PRINT #0,'Test complete' Michael ___ QL-Users Mailing List
Re: [Ql-Users] Select on
On 21/06/2020 13:38, Bob Spelten via Ql-Users wrote: Op Sun, 21 Jun 2020 09:46:23 +0200 schreef Norman Dunbar via Ql-Users : I have a vague recollection that Simon N Goodwin did something similar, maybe, in the DIY Toolkit. I think it was passed a variable and a list of strings, and returned the position of the variable in the list. Something like that. Maybe useful? That would then be the PICK$ function. It's on DIY disk 1, sub E, found on Dilwyn's site, where else? To me it looks like PICK$ is the OPPOSITE of string SELect. PICK$ goes like this: direction$ = PICK$(direction%,"North","East","South","West") Which is nothing other than what we've already got, ie: SELect on direction% = 1: direction$ = "North" = 2: direction$ = "East" = 3: direction$ = "South" = 4: direction$ = "West" = REMAINDER: direction$ = "???" END SELect although it is theoretically faster than SELect as it calculates the location of the desired value rather than doing a bunch of comparisons. But what a string select is supposed to do is: direction% = PICK%(direction$,"North","East","South","West") ie it returns some processable answer to a string query, viz SELect on direction$ = 'North': Go_to_North = 'East': Go_to_East = 'South': Go_to_South = 'West: Go_to_West = REMAINDER: Go_to_Hell END SELect Just for fun, after reading Giorgio's mail, I went and wrote a function like PICK% (not PICK$). Although it is very simple, it is significantly slower than the INSTR suggestion I made earlier. It would probably more or less match a real string select in speed. A hash function could be faster/more efficient for lists critical enough to justify the presence of such a function. Ideally, it would be some function that would map lexicographical values well onto numbers, eg f('ABC') < f('abc') or f('abcd') > f('abc'), etc, in a word or longword. Then things like ranges might be possible: term = Magic(term$) : SELect on term = $0123 TO $0300: Go_to_North = $3001, $1234: Go_to_East = etc though of what practical use they would be I know not.. But out of interest, does such a function exist? Per ___ QL-Users Mailing List