The PSION Organiser II Homepage
Forum Home Forum Home Help Help Search Search Members Members Login Login Register Register

Welcome, Guest. Please Login or Register.
Why register?
   The Psion Organiser II Forum
   User Forum
   User Post
(Moderator: Mikesan)
   Match-As-You-Type
« Previous topic | Next topic »
Pages: 1  Reply Reply Notify of replies Notify of replies Send Topic Send Topic Print Print
   Author  Topic: Match-As-You-Type  (Read 786 times)
Mikesan
Administrator




   
WWW

Posts: 236
Match-As-You-Type
« on: Jan 4th, 2015, 7:43pm »
Quote Quote Modify Modify

I have just spent about 3 hours looking on the Org2 Forum and through my own code archives for the procedure which finds in a database in the match-as-you-type fashion.  NO JOY AT ALL!
 
Oh, I'm pretty sure it is out there somewhere, but where?  I could have written this already in the time I spent looking!  So I've just done that.  
 
If anybody else finds it, then can you post the link here, as it is probably written differently anyway?
 
This algorithm will be the main part of my preferred method of input for database text strings.
This example uses an ODB that is just 5 records long; MYDATA, DATAMINE. NOBODY, MYSTICAL, NONSENSE.
 
One possible way would be to display the found information, so if you typed in M, then the records MYDATA DATAMINE and MYSTICAL would all show up, because M is found in all of them.   As soon as you type the Y though, now only MYDATA and MYSTICAL would be displayed, as the search string is MY.  Now type in D and only MYDATA shows up because MYD is only found in that record.
 
However, that means stopping to get a keypress to get the next match and it is not very elegant in practice.  Instead, I've opted to just display the first record found that matches the search string instead , so for example, in order to select MYSTICAL you need to enter MYS as opposed to MYD.
 
You press the DEL key to take off characters from the search string, EXE to select the found one and CLEAR/ON to simply quit.
 
This runs fine as long as you keep depositing a value for K% on the Organiser Developer's emulator, otherwise, it will simply stay at the last value that you were LUCKY ENOUGH to pick up ;-)  I seem to recall the Organiser II handles KEY$ OK though, so it is worth a shot on the real thing...
 
18:43 04/01/2015 100% works now.   Note the T% delay loop.  This is because the Organiser can execute the code faster than the LCD can keep up, so you get enough flicker to make the display too faint.  A bigger file might provide enough of a delay by itself anyway.
 
If we don't use KEY, or KEY$ we end up with a situation where the display is waiting for either the updated found information or the latest search string entry update.
 
I'll have to see if I can think of a way around that without using a get & go method like this, but it is sort of event driven like this, which is cool.  
 
Yes, there are seemingly unnecessary things like USE A in here and variables being nulled etc, but I find it handy to help remembering later when incorporating this into something else.  Maybe it's just me ;-)
 

MATCHIT:
REM (c) Mikesan 2015 - feel free to use wherever and however you like, but I retain copyright.
LOCAL FILE$(10),STROKE$(10),RESULT$(254),SPECHAR$(64)
LOCAL K%,F%,T%
ESCAPE OFF
FILE$="A:MATCHIT"
SPECHAR$=" [\]^_`{|}~!#$%&'()*+,-./:;<=>?@" : REM Those not being " or 0-9, A-Z.  You'd edit this line...
IF EXIST(FILE$)
 OPEN FILE$,A,FDATA$
ELSE
 CLS :PRINT "SELECTIONS FILE!"
 GET
 STOP
ENDIF
DO
  USE A
  FIRST
  IF STROKE$<>""
    IF FIND(STROKE$)>0
 RESULT$=A.FDATA$
 AT 1,2
 PRINT "FOUND:";RESULT$
    ELSE
 RESULT$=""
 AT 1,2
 PRINT "NO MATCH..."
    ENDIF
  ENDIF
  T%=0 :DO :T%=T%+1 :UNTIL T%>100 : REM Keeps LCD display properly visible.  Adjust to suit...
  K%=ASC(UPPER$(KEY$))    : REM Collect key allowable strokes to max allowable search len and allow del last.
  IF (K%>=48 AND K%<=57) OR (K%>=65 AND K%<=90) OR (LOC(SPECHAR$,CHR$(K%))<>0) OR K%=34 :REM Allowable search string chars.
    IF LEN(STROKE$)<10    : REM Not too long already...
 STROKE$=STROKE$+CHR$(K%)   : REM A valid character is added to search for.
    ENDIF
  ELSEIF K%=8 AND LEN(STROKE$)>0  : REM Only if it is DEL key and there is something to delete...
    STROKE$=LEFT$(STROKE$,LEN(STROKE$)-1) : REM Knock last entered character back off.
  ELSEIF K%=1
    RESULT$="" :STROKE$=""
    PRINT "QUIT!" :GET :STOP  : REM You probably WON'T be stopping OPL in many cases...
  ELSEIF K%=13    : REM And this needs thinking about too...
    GOTO J1::
  ENDIF
  CLS     : REM 1st time around K%=0 and nothing found so this appears immediately...
  AT 1,1     : REM Print any entered so far.
  PRINT "FIND:";STROKE$
UNTIL 0
J1::
CLS
AT 1,2
PRINT "RECORD DATA"
VIEW(2,RESULT$)
Pages: 1  Reply Reply Notify of replies Notify of replies Send Topic Send Topic Print Print

« Previous topic | Next topic »

The Psion Organiser II Forum » Powered by YaBB 1 Gold - SP 1.1!
YaBB 2000-2002,
Xnull. All Rights Reserved.
top