,

Join The Works program to have access to the most current content, and to be able to ask questions and get answers from Revelation staff and the Revelation community

AUTOFILL - Shareware (None Specified)

At 31 DEC 1999 01:47:21AM Barry Stevens wrote:

Here is the code for an AUTOFILL routine that works for EDITLINE, EDITTABLE and COMBOBOX.

Auto fills line as you type with matches from a supplied 'lookup table'

If this doesnt come out well - email me for a .src copy.

bsbsoft@ozemail.com.au

!!!!CODE FOLLOWS!!!!!

<code>
subroutine AutoFill(CtrlEntId,Event,NewData,TableString)
*
*	Barry Stevens 31/12/99
*
*	Acknowledgement to Richard Hunt for the Original code for editline
*
*	
*	Autofill line with matching text from a @vm delimited string
*	
*	Use for:
*		EDITLINE
*		EDITTABLE
*		COMBOBOX	
*
*				
*
*		Enter space to stop further matches
*
*Use:
*
*		Call from CHAR event:
*
*				call AutoFill(CtrlEntId,"CHAR",VirtCode)
*
*		Call from CHANGED event:
*
*				call AutoFill(CtrlEntId,"CHANGED",NewData,TableString)
*
*						If COMBOBOX and the TableString is not passed the the LIST property is used
*
*						TableString is @vm delimited
*
* Declare statements.
DECLARE FUNCTION POST_EVENT, UnAssigned
DECLARE FUNCTION GET_PROPERTY, SEND_MESSAGE, SET_PROPERTY

*
**********
* Set program variables.

equ DTM_EDITCURCELL$ to 1024 + 95

FALSE=0
TRUE=1
OTHERWISE=TRUE
NOTHING='
FM=@FM

ControlType=get_property(CtrlEntId,"TYPE")

begin case
	
	case Event=CHAR"
	
		gosub CharEvent

	case Event=CHANGED"
	
		gosub ChangedEvent

end case

return

!*********
CharEvent:
!*********

	VirtCode=NewData
	**********
	* Check for backspace.
	IF VIRTCODE EQ CHAR(8) THEN
		Foo=POST_EVENT(CTRLENTID,'CHANGED',CHAR(8))
	END else
		
		if ControlType=COMBOBOX" or ControlType=EDITTABLE" then
			Foo=POST_EVENT(CTRLENTID,'CHANGED')
		end
	end

return


 
!************ 
ChangedEvent:
!************
	
	*
	**********
	* Check for backspace key.
	IF NEWDATA EQ CHAR(8) THEN
		BACKSPACE=TRUE
	END ELSE
		BACKSPACE=FALSE
	END
	SelPos=0
	if ControlType=EDITTABLE" then 
		SelPos=get_property(CtrlEntId,"SELPOS")
	end
	LOCATE_STRING=GET_PROPERTY(CTRLENTID,'DEFPROP',SelPos)
	
	if UnAssigned(TableString) and ControlType=COMBOBOX" then
		TableString=get_property(CtrlEntId,"LIST")
		convert @fm to @vm in TableString
	end
	*
	**********
	* Truncate locate string.
	POS=GET_PROPERTY(CTRLENTID,'SELECTION') - 1
	IF POS THEN
		LOCATE_STRING=LOCATE_STRING1,POS
	END
	*
	**********
	* Get strings. (change this section to your liking).
	
	SEARCH_STRINGS=TableString
	*
	
	**********
	* Extract string from TableString one at a time for testing.
	VALUE=FALSE
	POS=FALSE
	MORE=(TableString NE NOTHING)
	LOOP WHILE MORE
		REMOVE STRING FROM SEARCH_STRINGS AT POS SETTING MORE
		VALUE += 1
		FOUND=FALSE
		*
		**********
		* Check for beginning string match.
		LENGTH=LEN(LOCATE_STRING)
		IF LENGTH AND LOCATE_STRING _EQC STRING1,LENGTH THEN
			FOUND=TRUE
			MORE=FALSE
		END
	REPEAT
	*
	**********
	* Position to matched list item.
	IF FOUND THEN
		CHANGED_EVENT=SEND_MESSAGE(CTRLENTID,'QUALIFY_EVENT','CHANGED',FALSE)
		RESULT=SET_PROPERTY(CTRLENTID,'DEFPROP',TableString,SelPos)
		RESULT=SEND_MESSAGE(CTRLENTID,'QUALIFY_EVENT','CHANGED',CHANGED_EVENT)
		START=LEN(LOCATE_STRING) + (NOT(BACKSPACE))
		*
		*Put in editmode so that the selection will work
		*
		hTable=Get_Property(CtrlEntID, 'HANDLE')
		if hTable then
			Message=DTM_EDITCURCELL$
			call SendMessage(hTable, Message, 1, 0)
		end
		
		RESULT=SET_PROPERTY(CTRLENTID,'SELECTION',START:FM:99999)
		
	END
	
return

</code>

!!!!!END OF CODE!!!!!!

View this thread on the Works forum...