• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 339
  • Last Modified:

datawindow text search( gafoor78@yahoo.com)

Hi
dear gafoor with refrence to one other question u provided a userobject for text serach on datawindow can u please mail that to me i have an urgent requirement or if any body else can help me pls.
thanks in advance
GHulam Rabbani
my email is
rabani_mcsd@hotmail.com
0
SHFDEV
Asked:
SHFDEV
1 Solution
 
diasroshanCommented:
hi,

is this what ur looking for...

//////////////////////////// code starts here//////////////////////

$PBExportHeader$sle_uo_fast_find.sru
$PBExportComments$UserObject to FastFind Data in Datawindows
forward
global type sle_uo_fast_find from singlelineedit
end type
end forward

global type sle_uo_fast_find from singlelineedit
integer width = 530
integer height = 96
integer textsize = -8
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "MS Sans Serif"
long textcolor = 33554432
borderstyle borderstyle = stylelowered!
event ue_edit_change pbm_enchange
event ue_enter pbm_keydown
end type
global sle_uo_fast_find sle_uo_fast_find

type variables
Boolean          ib_fastfind = True, ib_quote[], ib_repeat, ib_select = True, ib_pfc
Boolean          ib_MatchCase
Integer          ii_colcount, ii_found
String          is_colname[], is_start_any[]
Datawindow     idw_Ref
end variables

forward prototypes
public subroutine of_setfastfind (boolean ab_choice)
public function integer of_registercol (string as_colname, string as_start_any)
public subroutine of_setrowselect (boolean ab_rowselect)
public function boolean of_setdw (ref datawindow adw_ref)
public subroutine of_setmatchcase (boolean ab_matchcase)
end prototypes

event ue_edit_change;String     ls_text, ls_find
Integer     li_len, li_i, li_start

ls_text = This.Text
li_len = Len(ls_text)

If not ib_MatchCase Then ls_text = Upper(ls_text)

If li_len <= 0 Then
     ii_found = 0
     ib_repeat = False
//     Return
End If

// Generate the Find Expression
For li_i = 1 To ii_colcount
     If is_start_any[li_i] = 'start' Then     // Look for entered text starting with
//          If ib_quote[li_i] Then
          If ib_MatchCase Then
               ls_find     =     ls_find + "Left(String(" + is_colname[li_i] + ")," +&
                                   String(li_len) + ") = '" + ls_text + "' Or "               
          Else
               ls_find     =     ls_find + "Left(Upper(String(" + is_colname[li_i] + "))," +&
                                   String(li_len) + ") = '" + ls_text + "' Or "
          End If
//          ElseIf IsNumber(ls_text) Then
//               ls_find     =     ls_find + "Left(Upper(String(" + is_colname[li_i] + "))," +&
//                                   String(li_len) + ") = " + ls_text + " Or "
//          End If
     Else     // Look for entered text anywhere in the col data
          If ib_MatchCase Then
               ls_find     =     ls_find + "Pos(String(" + is_colname[li_i] + "), '" +&
                                   ls_text + "', 1) > 0 Or "               
          Else
               ls_find     =     ls_find + "Pos(Upper(String(" + is_colname[li_i] + ")), '" +&
                                   ls_text + "', 1) > 0 Or "
          End If
     End If
Next

// Trim the find expression to remove the " Or " sequence at the end.
ls_find = Left(ls_find, Len(ls_find) - 4)

If ib_repeat Then
     li_start = ii_found
Else
     li_start = 0
End If
//MessageBox("find string", ls_find)
ii_found     =     idw_ref.Find(ls_find, li_start + 1, idw_ref.RowCount())

// If row is found, scroll to it
If ii_found > 0 Then
     idw_ref.ScrollToRow(ii_found)
     If ib_Select Then
          SetRedraw(False)
          // Check if this is a pfc dw and if the row select service is turned on
          If ib_pfc Then
               idw_Ref.Event RowFocusChanged(ii_found)
          Else
               idw_Ref.SelectRow(0, False)
               idw_Ref.SelectRow(ii_found, True)
          End If
          SetRedraw(True)
     End If
End If
end event

event ue_enter;If Key = KeyEnter! Then
     ib_repeat = True
     This.Event ue_Edit_Change()
Else
     ib_repeat = False
End If
end event

public subroutine of_setfastfind (boolean ab_choice);ib_FastFind = ab_choice
end subroutine

public function integer of_registercol (string as_colname, string as_start_any);String     ls_coltype
Boolean     lb_quote

// Possible Values for as_start_any are 'start', 'any' meaning, search for the reqd text
// from the start or anywhere in between

// There is no Reference to the Search DW, Call of_SetDW() first.
If Not IsValid(idw_Ref) Then Return -1

ls_coltype = Lower(Left(idw_ref.Describe(as_colname + ".ColType"),4))

Choose Case ls_coltype
     Case 'char', 'date'
          lb_quote = True
     Case 'numb', 'long', 'int', 'deci', 'real'
          lb_quote = False
     Case Else
          Return -1
          // Either Invalid Column OR UnSupported Datatype.
          // This object can be changed to include required datatypes.
End Choose

ii_colcount ++

is_colname[ii_colcount] = Lower(as_colname)
ib_quote[ii_colcount] = lb_quote
is_start_any[ii_colcount] = Lower(as_start_any)

Return ii_colcount
end function

public subroutine of_setrowselect (boolean ab_rowselect);ib_select = ab_rowselect
end subroutine

public function boolean of_setdw (ref datawindow adw_ref);Boolean lb_return

If IsValid(adw_ref) Then
     idw_Ref = adw_ref
     ib_pfc = (idw_Ref.TriggerEvent('pfc_descendant') = 1)
     lb_Return = True
End If

Return lb_Return

end function

public subroutine of_setmatchcase (boolean ab_matchcase);ib_MatchCase = ab_matchCase
end subroutine

on sle_uo_fast_find.create
end on

on sle_uo_fast_find.destroy
end on

event constructor;// AUTHOR:               gaf
// OBJECT NAME:     sle_uo_fast_find
// PURPOSE:               To search through datawindow columns for a text/number/date
//     HOW TO USE:      1. Place this SLE userobject in any window/userobject
//                              2. In THIS object's constructor (recommended) event...
//                                        of_SetDW(search_dw)
//                                        of_RegisterCol(column_name, search_type)
//                                        of_SetRowSelect(boolean)
//                              3. Call of_RegisterCol any number of times to include all
//                                   searchable columns
//                              4. The Search_Type can be - 'START' or 'ANY'
//                              5. 'START' will search for data (in columns) that start with the text entered
//                              6.     'ANY' will search for the entered text anywhere in column data
//                              7. If the required text appears more than once in all rows, then hit
//                                   'enter' key to loop through all occurences.
//                              8. of_SetRowSelect() actually determines whether to select the row if the
//                                   search criteria matches.
//     LAST REVISED:     May 9, 2003 -


end event

///////////////////code ends here/////////////////////

Please refer the following links...
http://www.experts-exchange.com/Programming/Programming_Languages/PowerBuilder/Q_21221722.html
http://www.experts-exchange.com/Programming/Programming_Languages/PowerBuilder/Q_21224261.html

Cheers,
Rosh
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now