Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.
|
Forum Index : Microcontroller and PC projects : MMBasic for DOS Beta 6
Page 5 of 5 | |||||
Author | Message | ||||
Geoffg Guru Joined: 06/06/2011 Location: AustraliaPosts: 3165 |
Wow! That is a subtle one. Thanks for finding it and thanks for the demo code. Geoff Geoff Graham - http://geoffg.net |
||||
Geoffg Guru Joined: 06/06/2011 Location: AustraliaPosts: 3165 |
If the user just hits enter the variable will be set to an empty string or zero. So I normally do something like this: input"Default string to be edit or not";s$ if s$ = "" then s$="default string" print s$ Geoff Geoff Graham - http://geoffg.net |
||||
twofingers Guru Joined: 02/06/2014 Location: GermanyPosts: 1138 |
Hi Peter, this is not the solution for Micromites (or MMBasic for DOS)! But for Maximites I wrote a function called "LineEdit". Maybe is it a inspiration to do it on Micromites (or MMBasic for DOS)? 2017-09-19_093400_LineEdit2.zip Regards Michael |
||||
Peter63 Newbie Joined: 28/07/2017 Location: SwedenPosts: 14 |
Hi, Geoff Yes, this is a way, to do it . But i missed the edit part of the string . input"Default string to be edit or not";s$ if s$ = "" then s$="default string" print s$ Is sending in default-string to buffer before input a way? MM.keybuf$="default string" input"Default string to be edit or not";s$ print s$ Peter |
||||
Peter63 Newbie Joined: 28/07/2017 Location: SwedenPosts: 14 |
Hi Michael, This is a way to do it . I have a Sub i called sinput that works like this . 2017-09-20_064054_sinput.zip This (sinput) Sub return exit keystoke Peter |
||||
twofingers Guru Joined: 02/06/2014 Location: GermanyPosts: 1138 |
Hi Peter, this is excellent! Good job! Maybe something for the MMBasic Library? Michael |
||||
Geoffg Guru Joined: 06/06/2011 Location: AustraliaPosts: 3165 |
No, all that would do is allow you to backspace over the string (not very useful) - plus it is not a good thing to complicate the language with extra speciality constructs like this when the same outcome can be achieved using ordinary BASIC programming. Geoff Geoff Graham - http://geoffg.net |
||||
CaptainBoing Guru Joined: 07/09/2016 Location: United KingdomPosts: 1987 |
I have never met a Basic where you could provide a default string to the INPUT statement - happy to be shown otherwise but it defo isn't Microsoft standard from where MMBasic draws its inspiration (and a lot of look 'n' feel of the language). Years ago (QB5 days) I had a function called EDIT$ that did very much the same as Michael's LineEdit above. INPUT never had the flexibility for really nice character screen handling... "Redo from start" and scrolling, limiting string length and the ? prompt etc.... EDIT$ allowed you to edit a string at a position on the screen with a maximum length etc. |
||||
robert.rozee Guru Joined: 31/12/2012 Location: New ZealandPosts: 2292 |
the following comes close to what is being asked for: Z$="default value" Do getstring("some string = ", Z$) Print "<" Z$ ">" Loop Until Z$="quit" End Sub getstring(A$, B$) Print Chr$(13) A$ B$ Chr$(13) A$; Do I=Asc(Inkey$) Loop Until I=13 Or I=8 If I=8 Then For J=1 To Len(B$): Print " ";:Next J For J=1 To Len(B$): Print Chr$(8);:Next J Input "", B$ Else EndIf End Sub you have the choice of pressing the enter key to accept the current default value, or press the backspace key and entering a new value. in order to get away without needing to press the backspace key, there would need to be some way of peeking into the keyboard input buffer without removing the next character from it. but pressing backspace first is really a pretty minor 'cosmetic' issue. cheers, rob :-) |
||||
Peter63 Newbie Joined: 28/07/2017 Location: SwedenPosts: 14 |
Hi Michael, sinput - it's uploaded to (Fruit of The Shed) now Peter |
||||
twofingers Guru Joined: 02/06/2014 Location: GermanyPosts: 1138 |
Thanks Peter! BTW. I find my MaskEdit$-Function also very useful (for MAXIMITES) if you have to get some file names or something like that ... I needed it for my Maximite File Selector. '************************************************* '* '* MASKEdit$ V.95 '* mod of LineEdit() '* MMBasic 4.5/Maximite '* '* line editor for small strings (e.g. file names '* time$, date$ ...) '* MASKEdit$("12:45:56",1,"##.##.##") '* MASKEdit$(" TEST.BAS",1," . ") '* Special mask characters: '* " " any ascii character '* "#" any number(0-9) '* "." skip char will be ignored/skipped '* "@" numbers & letters (not yet implemented!) '* Used functions: FindLeft,FindRight,IsNum '* Limit: '* The string must not exceed the width of screen '*------------------------------------------------ Function MaskEdit$ edText$, cursorp, edMask$ Local hpos, vpos, p, ep, keyvalue, enterPressed Local text$,ltext$,mtext$,rtext$,C$,M$,Mask$ Local TRUE, FALSE TRUE=1 FALSE=0 hpos=MM.HPos:vpos=MM.VPos ' save print position text$=edText$ ' use local copy of text$ string MaskEdit$=edText$ ' backup edText$ for Esc enterPressed=FALSE ' Flag to EXIT the loop escPressed=FALSE ' a Global var ep=Len(text$) ' end pointer C$="." ' prohibited/skipped char p=cursorp:If Not p Then p=1 ' cursor pointer Mask$=edMask$ ' local copy If ep<>Len(Mask$) Then Mask$=Space$(ep) Pause 200 ' es gibt einen Zeitfaktor fuer keyboard input buffer ~140ms ltext$=Mid$(text$,1,p-1) mtext$=Mid$(text$,p,1) rtext$=Mid$(text$,p+1,ep-p) Print @(hpos,vpos)ltext$; Font#1,,1 Print mtext$; Font#1 Print rtext$; Do Do:keyvalue=KeyDown:Pause 50:Loop While keyvalue=0 If keyvalue=130 And p>1 Then p=FindLeft(Mask$,C$,p) 'p=p-1 'left arrow EndIf If keyvalue=131 And p<ep Then 'p=p+1 'right arrow p=FindRight(Mask$,C$,p) EndIf If keyvalue=13 Then enterPressed=TRUE 'Enter EndIf If keyvalue=27 Then 'Esc Print @(hpos,vpos)MaskEdit$; escPressed=TRUE EndIf If keyvalue=134 Then 'Home p=1 If Mid$(text$,p,1)=C$ Then p=FindLeft(Mask$,C$,p) EndIf EndIf If keyvalue=135 Then 'End p=ep If Mid$(text$,p,1)=C$ Then p=FindRight(Mask$,C$,p) EndIf EndIf If keyvalue>=32 And keyvalue<127 Then 'all ASCII chars M$= Mid$(Mask$,p,1) If m$=" " Or (m$="#" And IsNum(Chr$(keyvalue))) Then ' num mask, only numbers If p<ep Then ltext$=ltext$+Chr$(keyvalue) If Mid$(Mask$,p+1,1)=C$ Then ltext$=ltext$+Mid$(Text$,p+1,1) p=FindRight(Mask$,C$,p) mtext$=Mid$(text$,p,1) rtext$=Mid$(text$,p+1) Else ltext$=Left$(text$,p-1) mtext$=Chr$(keyvalue) rtext$="" EndIf EndIf ElseIf keyvalue=132 Then 'insert, when dot is on the right _and_ If mask$=" . " And p<9 Then ' mask$=" . " mtext$=" " ltext$=Mid$(text$,2,p-1) EndIf ElseIf keyvalue=127 Then 'Del If mask$=" . " And p<9 Then ' mask$=" . " If p>1 Then mtext$=Mid$(text$,p-1,1) ltext$=" "+Mid$(text$,1,p-2) Else mtext$=" " EndIf EndIf ElseIf keyvalue=8 And p>1 Then 'Bsp, delete left space p=FindLeft(Mask$,C$,p) mtext$=" " ltext$=Mid$(text$,1,p-1) rtext$=Mid$(text$,p+1) Else If p>=ep Then p=ep ltext$=Mid$(text$,1,p-1) 'move cursor / over write mtext$=Mid$(text$,p,1) rtext$=Mid$(text$,p+1,ep-p) EndIf Print @(hpos,vpos)ltext$; Font#1,,1 Print mtext$; Font#1 Print rtext$; text$=Left$(ltext$+mtext$+rtext$,ep) Pause 125 ' some wait states to slow down key input Loop While Not enterPressed And Not escPressed If Not escPressed Then MaskEdit$=ltext$+mtext$+rtext$ Print @(hpos,vpos)MaskEdit$; EndIf End Function '***************************************************** Function IsNum(Num$) IsNum=(Asc(Num$)>=48) And (Asc(Num$)<58) End Function Function FindRight(S$,C$,p) Local i If p<=Len(S$) Then For i = p+1 To Len(S$) If Mid$(s$,i,1)<>C$ Then Exit For Next i EndIf If i=0 Then i=p FindRight=i End Function Function FindLeft(S$,C$,p) Local i If p>1 Then For i = p-1 To 1 Step-1 If Mid$(s$,i,1)<>C$ Then Exit For Next i EndIf If i=0 Then i=p FindLeft=i End Function '--^^^^^^^ used by MaskEdit ^^^^^^-- Maybe someday we can convert it to MMBasic for DOS. Regards Michael |
||||
Peter63 Newbie Joined: 28/07/2017 Location: SwedenPosts: 14 |
Hi Michael jepp, this is useful function... have not tested it yet... I have tested out Beta 7, version little bit more. add in three basic program 2017-09-22_213558_coldemo.zip Color-demo program 2017-09-22_213617_psmenu.zip Simple menu-routine 2017-09-22_213648_sortname.zip Sort name inside strings Peter |
||||
Peter63 Newbie Joined: 28/07/2017 Location: SwedenPosts: 14 |
Hi Michael, all add in one more test-program for Beta 7, i wrote... 2017-09-22_215047_sort1.zip Sort strings based on a number inside the strings This will i used in my Polis Scanner UNIDEN UBC780XLT project Peter |
||||
Page 5 of 5 |
Print this page |