Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Search text or keyword from browse.

Status
Not open for further replies.

TinLegs

Programmer
Jan 14, 2003
100
NZ
I have a knowledge base program (C6.1-ABC) and would like to be able to enter a string or keyword and search a tps file for a match, namely text in a Memo field used for the Subject Notes. Can this be done from the Browse window? I see the Query templates available but just wanted to use a simple entry field with a Search button beside it. Suggestions greatly appreciated.
 
Make sure the MEMO fields are set as HOT fields i.e. part of the view and on the Accepted embed of the Search button, do the following :

BRWn.SetFilter(FilterString)
BRWn.ResetSort(True)

This is an extension template I use to work on the ? (Locate) button of the VCR buttons on a Browse. Hope it helps. Paste the following text into a text file called TinLegs.tpl (or any other name) and register it in the template registry.

#!*****************************************************************************
#!*****************************************************************************
#TEMPLATE(TINLEGS_TPL, 'CUSTOM TEMPLATE OF Tin Legs'), FAMILY('ABC')
#!*****************************************************************************
#!*****************************************************************************
#!
#EXTENSION (FilterBrowseOnVCRLocate, 'Filter a Browse List Box when the VCR Locate Button is Pressed'), MULTI, WINDOW
#PREPARE
#ENDPREPARE
#SHEET
#TAB ('Settings')
#PROMPT('Select Browse Control',CONTROL),%VCRFilterBrowseControl,REQ
#PROMPT('Select Browse Object Name',@S20),%VCRFilterBrowseObject,DEFAULT('BRW:'),REQ
#PROMPT('Select Browse Field to Filter',FIELD),%VCRFilterBrowseField,REQ
#ENDTAB
#ENDSHEET
#!-----------------------------------------------------------------------------
#!-----------------------------------------------------------------------------
#AT(%DataSectionAfterWindow), LAST
#!-----------------------------------------------------------------------------

SearchString STRING(60)
SearchWord STRING(40)
SearchFilter STRING(240)

SearchWindow WINDOW,AT(,,260,19),FONT('Arial',9,,FONT:bold,CHARSET:ANSI),COLOR(0F1CC8DH),CENTER,GRAY
PROMPT('Enter Word(s) to Search'),AT(5,4),USE(?SearchString:prompt),TRN,FONT('Arial',9,COLOR:Navy,FONT:bold,CHARSET:ANSI)
ENTRY(@s60),AT(86,4,170,10),USE(SearchString),LEFT,COLOR(COLOR:WINDOW),ALRT(TabKey),ALRT(EnterKey)
END

#ENDAT
#!-----------------------------------------------------------------------------
#AT(%ControlEventHandling, %VCRFilterBrowseControl, 'Locate')
#!-----------------------------------------------------------------------------

OPEN(SearchWindow)
ACCEPT
CASE EVENT()
OF EVENT:CloseWindow
BREAK
OF EVENT:Selected
CASE FIELD()
OF ?SearchString
?SearchString{PROP:Touched} = True
END
OF EVENT:AlertKey
CASE FIELD()
OF ?SearchString
UPDATE(?SearchString) ; BREAK
END
OF EVENT:Accepted
CASE FIELD()
OF ?SearchString
UPDATE(?SearchString) ; BREAK
END
END
END
CLOSE(SearchWindow)

SearchFilter = ''
IF SearchString <> ''
S# = 1 ; L# = LEN(CLIP(SearchString)) ; Q# = 0
LOOP C# = 1 TO L#
IF SearchString[C#] = '"' THEN Q# = CHOOSE(Q#=1,0,1).
IF (SearchString[C#] = ' ' AND NOT Q#) OR C# = L#
SearchWord = UPPER(CLIP(SearchString[S# : CHOOSE(C# < L#, C#-1, L#)]))
IF SearchWord <> ''
W# = LEN(CLIP(SearchWord))
IF SearchWord[1] = '"' AND SearchWord[W#] = '"' ! If Quoted
SearchWord = SearchWord[2 : W#-1]
END

SearchFilter = CHOOSE(SearchFilter <> '',CLIP(SearchFilter) & ' AND ','') & 'INSTRING(<39>' & CLIP(SearchWord) & '<39>,UPPER(%VCRFilterBrowseField),1,1) > 0'
END

S# = C# + 1
END
END
END

%VCRFilterBrowseObject.SetFilter(CLIP(SearchFilter),'9')

%VCRFilterBrowseObject.ResetSort(True)

SELECT(%VCRFilterBrowseControl)

#ENDAT
#!-----------------------------------------------------------------------------
 
Thanks ShankarJ its looks like what I need. For those interested I note you can set the Locator to Entry but I could not find any way to implement a simple search string, another method would be to use the Fuzzy Search but it was not really what I wanted. Thanks again.
Regards,
TinLegs
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top