March 28, 2024, 09:28:42 AM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


Auto complete - a step by step guide - part 1 - getting words

Started by Andy, January 23, 2020, 09:10:06 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Andy

There are times when you would really like an auto complete function to look up and finish off words being typed.

So how do you go about it?

This is my way...

Step 1, Finding words in a string.

To make life more simple, I'm using my convertkeywords include file as it has all the code in it to help us out on this one.

So how do we break a string down into words?

We have to pick out words, and that we do by looking how they are separated, e.g a space, a comma etc.

Once we realise that, we can write a little code to do it for us (see attached).

Words are separated by 'delimiters', these are the ones I'm using in the include file...

ISTRING CheckLetter[20] = " ,'-+()[]=:<>&|" + CHR$(9) + CHR$(34) 'Includes tabs and quotations.

There may be more words than delimiters (or vice versa) so I keep the count the same, that is if there are 15 words, and only 14 delimiters, the 15th delimiter will be blank, but either way 15 is the total.

Have a look and play around with the attached program, I will post part 2 a little later.

Andy.
:)
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

Andy

Auto complete - a step by step guide - part 2 - Matching words...

The next step is to create a window with an edit box and a list view control.

The edit box so we can type something, and the list view where we can load all our words to check against.

In this example, I am using the IW key words.

Here is the basic window:


$INCLUDE "codetools.inc"
ReadKeyWords() 'Read in IW keywords.

OPENWINDOW w7,0,0,500,400,@MINBOX|@MAXBOX|@SIZE|@CAPTION,0,"Window",&handler
  CONTROL w7,@EDIT,"",20,110,400,25,0,WordSearch1
  CONTROL w7,@LISTVIEW,"",20,230,440,100,@BORDER|@LVSNOCOLUMNHEADER|@LVSSHOWSELALWAYS|@LVSREPORT|@VSCROLL,ListView
          SENDMESSAGE w7,LVM_SETEXTENDEDLISTVIEWSTYLE,0,LVS_EX_GRIDLINES|LVS_EX_FULLROWSELECT|LVS_EX_FLATSB|LBS_WANTKEYBOARDINPUT|LVS_EX_ONECLICKACTIVATE,ListView
          CONTROLCMD w7,ListView,@LVINSERTCOLUMN,0,""
          CONTROLCMD w7,ListView,@LVSETCOLWIDTH,0,440
          CONTROLCMD w7,ListView,@LVINSERTITEM,0,""
  SETFONT w7,"Arial",10,500,0,WordSearch1
  SETCONTROLCOLOR w7,WordSearch1,RGB(0,0,0),RGB(255,255,255)
  SETFONT w7,"Arial",10,500,0,ListView
  SETCONTROLCOLOR w7,ListView,RGB(0,0,0),RGB(255,255,255)
  setfocus w7,WordSearch1
WAITUNTIL IsWindowClosed(w7)
Finish()

SUB handler(),INT
 SELECT @MESSAGE
          CASE @IDCREATE
                CENTERWINDOW w7

          CASE @IDCLOSEWINDOW
                CLOSEWINDOW w7

          CASE @IDCONTROL
                SELECT @CONTROLID
                      'CASE 1
                            'IF @NOTIFYCODE = 0

                            'ENDIF

    ENDSELECT
ENDSELECT
RETURN 0
ENDSUB
 

A point to note, you will need (in this example) my code tools include file as it has all the IW key words already in a pointer array. This is my own choice, you could just use a normal array.

In the include file, there is a sub routine called "ReadKeyWords", all 1,661 key words are loaded here.

We load them into our program like this...

$INCLUDE "codetools.inc"
ReadKeyWords() 'Read in IW keywords.

Now we have some words we can compare against.

I'm also using a sub routine called "Finish" to simply delete the pointers when the program closes.

Attached is the latest version of the include file.
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

Andy

Attached is a working example of auto complete, I have taken some time to document the program.

So please have a read through the code, and please feel free to ask any questions (no matter how "silly" you might think they are - I ask many "silly" questions!).

All controls, arrays, windows etc are defined in the include file.

I've used this code in my Advanced find & replace program which can be found here...

http://www.ionicwind.com/forums/index.php?topic=6369.0

Hope this example will help you with your coding.

Andy.
:)
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.