DIY-Toolkit EDLINE$() function - improved version
Posted: Thu Mar 30, 2017 9:14 pm
On the English download page of my homepage you now will find an improved version for this nice function:
If called with 3 parameters (no defaults for the first three parameters, as in original version) it behaves as the original DIY-TK function (i.e. existing code should not be broken): Only ENTER allowed for terminating editing, the string is returned without the terminating character. I have added a fourth, optional parameter. Only the first four bits are used, and at least one bit must be set. I.e. range is from 1 to 15 - this is checked, if outside you get a bad parameter error (I should correct this to out of range).
When used with the 4th parameter, the terminating character is the last character of the returned string and must normally be stripped. Therefore 2 support functions are included in the toolkit:
lastChar=EDLINEL(string$) returns the character code of the last character in a string or -1 for a zero length string
humanString$=EDLIN$(string$) strips the last character of string$ and returns it. For a zero length string, a zero length string is returned.
Should I rename the 2 support functions (in fact EDLINEL() returns an int)?
Here an example how you can use it:
If called with 3 parameters (no defaults for the first three parameters, as in original version) it behaves as the original DIY-TK function (i.e. existing code should not be broken): Only ENTER allowed for terminating editing, the string is returned without the terminating character. I have added a fourth, optional parameter. Only the first four bits are used, and at least one bit must be set. I.e. range is from 1 to 15 - this is checked, if outside you get a bad parameter error (I should correct this to out of range).
Code: Select all
Bit set Terminating key allowed
0 ENTER (10)
1 ESC (27) (Only on Minerva and some SMS versions)
2 Arrow (cursor) Up (208)
4 Arrow (cursor) Down (216)
lastChar=EDLINEL(string$) returns the character code of the last character in a string or -1 for a zero length string
humanString$=EDLIN$(string$) strips the last character of string$ and returns it. For a zero length string, a zero length string is returned.
Should I rename the 2 support functions (in fact EDLINEL() returns an int)?
Here an example how you can use it:
Code: Select all
1000 REMark Test for improved EDLINE$(...)-FuNction from hps
1040 :
1080 DIM field$(3,22)
1120 field$(0)="Field1":field$(1)="Field2":field$(2)="Field3":field$(3)="Field4"
1160 CLS#1
1200 PRINT#1,"ENTER accepts all input fields"
1240 PRINT#1,"ESC restores current input field"
1280 PRINT#1,"Cursor Up/Down to select field"
1320 FOR inln=0 TO DIMN(field$):PRINT field$(inln)
1360 inln=0
1400 REPeat inloop
1440 SELect ON inln
1480 ON inln=0
1530 AT#1,3+inln,0
1560 fld$=EDLINE$(#1,21,field$(inln),1+2+8):REMark ENTER+ESC+CrsDown
1840 ON inln=1TO DIMN(field$)-1
1880 AT#1,3+inln,0
1920 fld$=EDLINE$(#1,21,field$(inln),15):REMark ENTER+ESC+CrsDown+CrsUp
2240 ON inln=DIMN(field$)
2280 AT#1,3+inln,0:fld$=EDLINE$(#1,21,field$(inln),1+2+4):REMark ENTER+ESC+CrsUp
2520 END SELect
2570 last=EDLINEL(fld$)
2600 IF last=27:NEXT inloop
2650 field$(inln)=EDLIN$(fld$)
2680 SELect ON last
2720 ON last=10
2760 EXIT inloop
2800 ON last=216
2840 inln=inln+1
2880 ON last=208
2920 inln=inln-1
2960 END SELect
3000 END REPeat inloop
3040 AT#1,8,0
3050 PRINT"User Input:"
3080 FOR inln=0 TO 3
3120 PRINT field$(inln)
3160 END FOR inln