Home  |  Contents 
Microcontroller and PC projects
  Forum Index : Microcontroller and PC projects         Section
Subject Topic: MMBasic for DOS Beta 6 Post ReplyPost New Topic
<< Prev Page of 8
Author
Message << Prev Topic | Next Topic >>
Peter63
Newbie
Newbie


Joined: 28 July 2017
Location: Sweden
Online Status: Offline
Posts: 14
Posted: 20 September 2017 at 6:44am | IP Logged Quote Peter63

Hi Michael,

Quote:
I wrote a function called "LineEdit".

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




Back to Top View Peter63's Profile Search for other posts by Peter63
 
twofingers
Guru
Guru


Joined: 02 June 2014
Location: Germany
Online Status: Offline
Posts: 506
Posted: 20 September 2017 at 10:38am | IP Logged Quote twofingers

Hi Peter,

this is excellent! Good job! Maybe something for the MMBasic Library?

Michael

Edited by twofingers on 20 September 2017 at 10:38am
Back to Top View twofingers's Profile Search for other posts by twofingers
 
Geoffg
Guru
Guru
Avatar

Joined: 06 June 2011
Location: Australia
Online Status: Offline
Posts: 2135
Posted: 20 September 2017 at 1:09pm | IP Logged Quote Geoffg

Peter63 wrote:
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$

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

Edited by Geoffg on 20 September 2017 at 1:21pm
Back to Top View Geoffg's Profile Search for other posts by Geoffg Visit Geoffg's Homepage
 
CaptainBoing
Guru
Guru
Avatar

Joined: 07 September 2016
Location: United Kingdom
Online Status: Offline
Posts: 340
Posted: 20 September 2017 at 2:18pm | IP Logged Quote CaptainBoing

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.


Edited by CaptainBoing on 20 September 2017 at 2:42pm


__________________

all you need is duct tape and WD40 (if it moves and shouldn't, use duct tape; if it doesn't move and should, use WD40)
Back to Top View CaptainBoing's Profile Search for other posts by CaptainBoing
 
robert.rozee
Guru
Guru


Joined: 31 December 2012
Location: New Zealand
Online Status: Offline
Posts: 1160
Posted: 21 September 2017 at 6:49am | IP Logged Quote robert.rozee

the following comes close to what is being asked for:

Z$="default value"
Do
  getstring("some string = ", Z$)
  Print "<" Z$ ">"
  Print
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
    Print
  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 :-)
Back to Top View robert.rozee's Profile Search for other posts by robert.rozee
 
Peter63
Newbie
Newbie


Joined: 28 July 2017
Location: Sweden
Online Status: Offline
Posts: 14
Posted: 22 September 2017 at 9:18am | IP Logged Quote Peter63

Hi Michael,

Quote:
this is excellent! Good job! Maybe something for the MMBasic Library?


sinput - it's uploaded to (Fruit of The Shed) now

Peter



Back to Top View Peter63's Profile Search for other posts by Peter63
 
twofingers
Guru
Guru


Joined: 02 June 2014
Location: Germany
Online Status: Offline
Posts: 506
Posted: 22 September 2017 at 1:20pm | IP Logged Quote twofingers

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
Back to Top View twofingers's Profile Search for other posts by twofingers
 
Peter63
Newbie
Newbie


Joined: 28 July 2017
Location: Sweden
Online Status: Offline
Posts: 14
Posted: 22 September 2017 at 9:40pm | IP Logged Quote Peter63

Hi Michael

Quote:
I find my MaskEdit$-Function also very useful

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


Back to Top View Peter63's Profile Search for other posts by Peter63
 
Peter63
Newbie
Newbie


Joined: 28 July 2017
Location: Sweden
Online Status: Offline
Posts: 14
Posted: 22 September 2017 at 9:54pm | IP Logged Quote Peter63

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
Back to Top View Peter63's Profile Search for other posts by Peter63
 


If you wish to post a reply to this topic you must first login
If you are not already registered you must first register

  Search the forums using Google.
<< Prev Page of 8
In the news...
 
Post ReplyPost New Topic
Printable version Printable version
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum

Powered by Web Wiz Forums version 7.8
Copyright ©2001-2004 Web Wiz Guide

This page was generated in 0.1250 seconds.
Privacy Policy     Process times : 0, 0.02, 0, 0.11