Question and Answer Help about SB
#21
Some more differences I encountered...

No $ needed for string variables and I do not believe marks like % are supported in numeric variables.
INKEY$ = INKEY
end if = endif
else if = elif or elseif
END IF = endif = fi
DO = WHILE
Exit Do = Exit Loop
labelname: = label labelname
CSRLIN = YPOS
POS(0) = XPOS
END = STOP

Screen Mapping SB starts at 0,0 : QB at 1,1
LOCATE needs both parameters, no [empty], to indicate current position as the default.
True is 1 not -1
MID cannot handle third parameter outside of string length or a zero in either parameter.
MID cannot have replacements values like MID(word, 5, 1) = "X"
Variables in SB are global by default.
INKEY does not recognize some keys like esc and delete.
No extended ascii character support.

-----------------------------------------------------------

My Android won't register Esc or Delete. I have code similar to the ascii key display code you posted and when I press Esc or delete the screen returns nothing at all. I substituted the Android escape switch, chr(197), instead. I used Tab for delete and I made a toggle switch out of the ` key for insert/overwrite. Arrow up is home, arrow down is end. Right and left arrow keys work. This one is a bit different from my previous post. I reworked it to include a cursor routine.

Thanks for your help in some problem areas. I think what I will look into next is some touch features.

- Pete

Code:
Const ESCS = Chr(27) + "[" ' Escape sequence prefix.
Const LINE_ON  = ESCS + "4m"  ' underline
Const LINE_OFF = ESCS + "24m"
Def uline(text) = LINE_ON + text + LINE_OFF
toggleblink = 1
inscur = "_"
word = ""
mykey = ""
z = -1
PRINT "Input: ";
startpos = XPOS
endpos = 48
WHILE -1
  mykey = INKEY
  IF LEN(mykey) THEN
    IF XPOS - startpos < LEN(word) THEN
      PRINT MID(word, XPOS - startpos + 1, 1);
      LOCATE YPOS, XPOS - 1
    ENDIF
    IF LEN(mykey) = 2 THEN
      SELECT CASE MID(mykey, 2, 1)
        CASE CHR(4) ' Cursor Left
          IF XPOS > startpos THEN
            IF XPOS - (startpos - 1) > LEN(word) THEN
              PRINT " ";: LOCATE YPOS, XPOS - 1
            ENDIF
          LOCATE YPOS, XPOS - 1
          ENDIF
        CASE CHR(5) ' Cursor Right
          IF XPOS < endpos THEN
            IF XPOS - (startpos - 1) < LEN(word) THEN
              LOCATE YPOS, XPOS + 1
            ELSE
              IF XPOS - (startpos - 1) = LEN(word) THEN
                LOCATE YPOS, XPOS + 1
                PRINT inscur;: LOCATE YPOS, XPOS - 1
              ENDIF
            ENDIF
          ENDIF
        CASE CHR(9) ' Cursor Home
          IF XPOS - (startpos - 1) > LEN(word) THEN
            LOCATE YPOS, startpos + LEN(word): PRINT " ";
          ENDIF
          LOCATE YPOS, startpos
        CASE CHR(10) ' Cursor End
          LOCATE YPOS, startpos + LEN(word)
        CASE CHR$(197) ' Android Exit
          LOCATE 3, 0: PRINT "Finished...";
          STOP
      END SELECT
      z = - 1: toggleblink = 1: mycursor
    ELSE
      SELECT CASE mykey
        CASE CHR(8) ' Backspace
          IF XPOS > startpos THEN
            LOCATE YPOS, XPOS - 1
            IF XPOS - (startpos - 1) >= LEN(word) THEN
              word = MID(word, 1, XPOS - (startpos - 1) - 1)
            ELSE
              word = MID(word, 1, XPOS - (startpos - 1) - 1) + MID(word, XPOS - (startpos - 1) + 1)
            ENDIF
            wipe = 1: GOSUB xprint
            IF x - (startpos - 1) > LEN(word) THEN
              PRINT inscur;: LOCATE YPOS, XPOS - 1
            ENDIF
            LOCATE y, x
          ENDIF
        CASE CHR(9) ' Delete via Tab Key
          IF XPOS - (startpos - 1) <= LEN(word) THEN  
            IF XPOS = startpos THEN
              IF LEN(word) > 1 THEN
                word = MID(word, 2)
              ELSE
                word = ""
              ENDIF          
            ELSE
              IF XPOS - (startpos - 1) < LEN(word) THEN
                word = MID(word, 1, XPOS - (startpos - 1) - 1) + MID(word, XPOS - (startpos - 1) + 1)
              ELSE
                word = MID(word, 1, XPOS - (startpos - 1) - 1)  
              ENDIF
            ENDIF
            wipe = 1: GOSUB xprint
            IF x - (startpos - 1) > LEN(word) THEN
              PRINT inscur;: LOCATE YPOS, XPOS - 1
            ENDIF
            LOCATE y, x
          ENDIF
        CASE "`" ' Insert / Overwrite via ` key
          IF inscur = "_" THEN inscur = CHR(32) ELSE inscur = "_"
        CASE CHR(27) ' Quit
          STOP
        CASE ELSE ' Type Characters 32 - 126 to the screen
          IF inscur <> "_" AND XPOS < endpos OR inscur = "_" AND startpos + LEN(word) < endpos THEN
            IF mykey >= CHR(32) AND mykey <= CHR(126) THEN
              IF XPOS - (startpos - 1) > LEN(word) THEN
                word = word + mykey
              ELSE
                SELECT CASE inscur
                  CASE " " ' Overwrite
                    IF XPOS = startpos THEN
                      word = mykey + MID(word, XPOS - (startpos - 1) + 1)
                    ELSE
                      IF XPOS - (startpos - 1) >= LEN(word) THEN
                        word = MID(word, 1, XPOS - (startpos - 1) - 1) + mykey
                      ELSE
                        word = MID(word, 1, XPOS - (startpos - 1) - 1) + mykey + MID(word, XPOS - (startpos -1) + 1)
                      ENDIF
                    ENDIF
                  CASE ELSE ' Insert
                    IF XPOS = startpos THEN
                      word = mykey + MID$(word, XPOS - (startpos - 1))
                    ELSE
                      word = MID$(word, 1, XPOS - (startpos - 1) - 1) + mykey + MID$(word, XPOS - (startpos - 1))
                    ENDIF
                END SELECT
              ENDIF
              wipe = 0: GOSUB xprint
              LOCATE YPOS, XPOS + 1
              IF XPOS - (startpos - 1) > LEN(word) THEN
                PRINT inscur;: LOCATE YPOS, XPOS - 1
              ENDIF
            ENDIF
          ENDIF
      END SELECT
      z = -1: toggleblink = 1: mycursor
    ENDIF
  ELSE
    mycursor
  ENDIF
WEND
STOP

label xprint
y = YPOS: x = XPOS
IF wipe THEN LOCATE YPOS, startpos: PRINT SPACE(endpos - startpos + 1);
LOCATE YPOS, startpos
PRINT word;
LOCATE y, x
RETURN

SUB mycursor
  IF ABS(z - TIMER) > .33 or z = -1 THEN
    IF XPOS - (startpos - 1) > LEN(word) THEN
      SELECT CASE inscur
        CASE "_"
          IF toggleblink THEN COLOR 7, 0 ELSE COLOR 0, 0
        CASE ELSE
          IF toggleblink THEN COLOR 0, 8 ELSE COLOR 7, 0
      END SELECT
      PRINT inscur;: LOCATE YPOS, XPOS - 1
    ELSE
      SELECT CASE toggleblink
        CASE 0
          SELECT CASE inscur
            CASE "_"
              PRINT MID(word, XPOS - startpos + 1, 1);
            CASE ELSE
              COLOR 0, 8
              PRINT MID(word, XPOS - startpos + 1, 1);
            END SELECT
        CASE 1
          COLOR 7, 0
          PRINT Uline(MID(word, XPOS - startpos + 1, 1));
          DELAY 35
      END SELECT
      LOCATE YPOS, XPOS - 1
    ENDIF
    z = TIMER
    toggleblink = ABS(toggleblink - 1)
    COLOR 7, 0
  ENDIF
END SUB
Reply
#22
Hi Pete, 

I am liking how much progress you've made (assuming the above is working). I am liking the idea, I might of helped (so let me dream on if this is not so). 

I am not liking the fact that I hadn't checked my own Android keyboard to realize escape key isn't even there! (But some equivalent as I think you have found.)

I like how much I learn trying to help others and I liked WHN? very much for that quality too. Some times it looks like ugly interference but the spirit is right.

Can't wait to see what you've done! I hope it doesn't involve another hat trick though.
B += x
Reply
#23
Hi Pete, 

First thing I think when I see Input is that after I type something and then Enter, something should happen on the program response end. Didn't we fix enter?

BTW I am testing on laptop Windows version of SmallBASIC not Android version of SmallBASIC.

BTW #2 what are we doing here? Duplicating the Line Input sub SB has?

And here is what I learned MID$ does not throw error and works!
test:
Code:
'does mid$ work or why isn't the error flagged?

test = mid$("repete", 3)
? test
'well I'll B...

'test lineinput in Android
?"INPUT: ";
lineinput getInput
? "Echo: ";getInput.

I would check if Android version of SB has LINEINPUT variable (done, it does and it works).

I can't test my Android version because the 3 vertical dots don't work on my device, so I can't access editor.


On the other hand, I spent a good amount of time working on a whole screen version of a message box for SB, only to learn after posting my great achievement, that SB already has a version much better than what I came up with.

Do I regret my efforts... ?

Ha, I never got around to going back to use that message box in my code. I should do that!



Are we going for a multi-line text input or full fledged editor?


Update:
OK I did test run your code on my Android device and I can not access my keyboard nor are the 3 vertical dots even showing! This does have SB Android version and LINEINPUT does work and does throw up the keyboard so I can enter letters and does respond to Enter (Return =   <--- ) and does echo the text I entered.
B += x
Reply
#24
Code:
CASE CHR(13) ' Print word and quit
          LOCATE 2, 0
          PRINT word;
          STOP

from code Pete posted at SB

now enter works!

Smile
B += x
Reply
#25
MID("repete", 3) is going to print: "pete" in SB or QB. What SB doesn't do is allow for substitution like: MID$("repete", 3, 1) = "h" uncase your order of pete gets cold.

QB also lets you get away with letting the third parameter be out of bounds. QB will handle: MID$("repete", 12) It just ignores that the string isn't nearly that long. This definitely saves work for the coder but I have noticed most BASIC languages I've tried do like SB and force you to put in parameters that are in bounds.

I tried lineinput. I also made a QB scrolling text input line that one. I suppose I could add that in as well. The point of not using what the system has is simple. With my custom routine I can do other things in the app outside of finish the input. SB lineinput is better than most BASIC line input statements.

I popped that Enter key into the one I posted at SB. I see you found it. 

I'm not sure where I'm going with this particular app. Mostly this is the stuff I like and use so, 1) I wanted to see if SB could handle what I like to do and 2) This helps me learn the syntax and differences better than going through each keyword at a time. 

What's neat is I tried that "Desktop" feature in the menu and it made me a desktop shortcut. Clicked the shortcut and it did just like the old win 3.1 pif shortcuts. It not only loads and runs SB but it starts your app up immediately. That makes it more like a real app. 

I have a few WP's I've built but they are about 10-20 times the size of what I put together yesterday. I will probably try other things before I commit to that kind of a  monstrosity. 

Thanks for trying it!

OH WAIT! I did have one question. Since I can run it from the desktop is there also a command to automatically load the on-screen keyboard when the program starts ???

Pete Shy
Reply
#26
Hi Pete, 

I am a little confused about your setup and where this on-screen keyboard is coming from.

When you say desktop, I assume you mean a Windows desktop? But then why do you need a keyboard?

You would need a keyboard for Android, does it have a desktop? Does it also have something like a Batch file as well? or macros?

I do know SmallBASIC has some few switches for command line or batch file running and also used setting up Geany (or Notepad++ ?) editor, check forum site.

PS my point about MID was that it worked with the $ sign with SB. I do fondly remember the MID$ sub that could alter inner contents from QB.

update: -e fullpathFilename or -r fullpathFilename are the 2 switches, not much but something, e for Edit, r for Run
B += x
Reply
#27
Quote:OH WAIT! I did have one question. Since I can run it from the desktop is there also a command to automatically load the on-screen keyboard when the program starts ???

Pete [Image: shy.gif]


I've had a couple more ideas about what you might be asking in the above quote but doubt this hits nail.

The on-screen keyboard automatically pops up when the SB app contains the keyword INPUT or LINEINPUT, again speaking for my device only but INKEY does not popup the keyboard even though it's supposed to be polling keypresses. Now there we need a popup! and my Android use to have an icon to popup the keyboard but it disappeared after an Android update along with a working 3 bar access (not 3 tiny circles) to the essential right  click popup menu (Windows version) that accesses the editor, the IDE for SmallBASIC.

Also you can setup SmallBASIC to edit a .bas file when you click it in Windows, which is what I have mine set at. You can also set it up to run a .bas file when you click on a .bas, so it reacts just like an exe would react to being clicked!
B += x
Reply
#28
I actually figured that one out for myself. Experimented earlier with lineinput. As, like you wrote, the keyboard pops up. Yes, I agree I wish Chris would make it so with INKEY but also have a keyword call for it along with a parameter to remove it, too.

I didn't get into much else today. Took the wife out shopping this afternoon and they we went to a sports restaurant to watch game 4 of the Series. Go Dodgers!

Pete Big Grin
Reply
#29
Yeah, I thought Indians would get farther than they did this year, specially with that hot winning streak they had near end of season.

I do not fore see great things with Cavs this year either. Do you know they claim to have lost $40 million last year?

Gives me the DT's, "Unbelievable!"
B += x
Reply