of_replace


pfcdwsrv.pbl   >   pfc_n_cst_dwsrv_find   >   of_replace   

Full name pfc_n_cst_dwsrv_find.of_replace
Access protected
Extend of integer
Return value integer
Prototype protected function integer of_replace(long,string,string)

Name Datatype
No Data

Name Datatype
lb_replacechars boolean
li_count integer
li_find_startpos integer
li_i integer
li_maskedfind_selectedtextlen integer
li_maskedfind_startpos integer
li_maskedfind_textlen integer
li_rc integer
ls_coltype string
ls_editstyle string
ls_find string
ls_maskedfind string
ls_maskedfind_selectedtext string
ls_selectedtext string

protected function integer of_replace (long al_row, string as_colname, string as_replacewith);//////////////////////////////////////////////////////////////////////////////
//
//	Function:  		of_Replace
//
//	Access:  		protected
//
//	Arguments: 	
//	al_row			The row number for the value that may be replaced.
//	as_column		The column name for the value that may be replaced.
//	as_replacewith	The value to replace with.
//
//	Returns:  		integer
//						1 if it succeeds and -1 if an error occurs. 
//
//	Description: 	Replace on a specific row and column, with a specific value.
//
//////////////////////////////////////////////////////////////////////////////
//
//	Revision History
//
//	Version
//	5.0   Initial version
// 5.0.03 Corrected Matchcase attribute being ignored.
//
//////////////////////////////////////////////////////////////////////////////
//
//	Copyright © 1996-1997 Sybase, Inc. and its subsidiaries.  All rights reserved.
//	Any distribution of the PowerBuilder Foundation Classes (PFC)
//	source code by other than Sybase, Inc. and its subsidiaries is prohibited.
//
//////////////////////////////////////////////////////////////////////////////

string 	ls_selectedtext
string	ls_coltype
string	ls_find
integer	li_rc=0
integer	li_count, li_i
boolean 	lb_replacechars=False
integer	li_find_startpos
string	ls_editstyle
string	ls_maskedfind, ls_maskedfind_selectedtext
integer	li_maskedfind_textlen, li_maskedfind_startpos, li_maskedfind_selectedtextlen

//Get the current column, columntype, and editstyle
ls_coltype = idw_requestor.describe(as_colname+".ColType")
ls_editstyle = idw_requestor.Describe(as_colname+".Edit.Style")

//Get the currently selected text.
ls_selectedtext = idw_requestor.SelectedText()

//Process according to the column type.
//Check that the ReplaceWith value is appropriate for the column type.
Choose Case Left(Lower(ls_coltype),4)
	Case 'numb', 'long', 'inte'
		If IsNumber(ls_selectedtext) and IsNumber(inv_findattrib.is_find) Then
			If Long(ls_selectedtext) = Long(inv_findattrib.is_find) Then
				If IsNumber(inv_findattrib.is_replacewith) Then
					li_rc = idw_requestor.SetItem(al_row, as_colname, &
					 			Long(inv_findattrib.is_replacewith))
				Else
					of_MessageBox ('pfc_find_replaceinvalidnumber', 'Replace', &
						'The Replace With value is not a valid number.', Information!, Ok!, 1)
					li_rc = -2
				End If										
			End If
		End If
		Return li_rc /* numb, long, inte */
		
	Case 'ulon'
		If IsNumber(ls_selectedtext) and IsNumber(inv_findattrib.is_find) Then
			If Long(ls_selectedtext) = Long(inv_findattrib.is_find) Then
				If IsNumber(inv_findattrib.is_replacewith) Then
					If Long(inv_findattrib.is_replacewith) > 0 Then
 						li_rc = idw_requestor.SetItem(al_row, as_colname, &
						 			Long(inv_findattrib.is_replacewith))
					Else
						of_MessageBox ('pfc_find_replaceinvalidnumber', 'Replace', &
							'The Replace With value is not a valid number.', Information!, Ok!, 1)
						li_rc = -2
					End If														
				Else
					of_MessageBox ('pfc_find_replaceinvalidnumber', 'Replace', &
						'The Replace With value is not a valid number.', Information!, Ok!, 1)					
					li_rc = -2
				End If										
			End If
		End If	
		Return li_rc /* ulon */
		
	Case 'deci'
		If IsNumber(ls_selectedtext) and IsNumber(inv_findattrib.is_find) Then
			If Dec(ls_selectedtext) = Dec(inv_findattrib.is_find) Then
				If IsNumber(inv_findattrib.is_replacewith) Then
					li_rc = idw_requestor.SetItem(al_row, as_colname, &
								Dec(inv_findattrib.is_replacewith))
				Else
					of_MessageBox ('pfc_find_replaceinvalidnumber', 'Replace', &
						'The Replace With value is not a valid number.', Information!, Ok!, 1)					
					li_rc = -2
				End If									
			End If
		End If	
		Return li_rc /* Deci */
		
	Case 'date'
		If IsDate(ls_selectedtext) and IsDate(inv_findattrib.is_find) Then
			If Date(ls_selectedtext) = Date(inv_findattrib.is_find) Then
				If IsDate(inv_findattrib.is_replacewith) Then
					li_rc = idw_requestor.SetItem(al_row, as_colname, &
								Date(inv_findattrib.is_replacewith))
				Else
					of_MessageBox ('pfc_find_replaceinvaliddate', 'Replace', &
						'The Replace With value is not a valid date.', Information!, Ok!, 1)					
					li_rc = -2
				End If								
			End If
		End If
		Return li_rc /* Date */
		
	Case 'time'	
		If IsTime(ls_selectedtext) and IsTime(inv_findattrib.is_find) Then
			If Time(ls_selectedtext) = Time(inv_findattrib.is_find) Then
				If IsTime(inv_findattrib.is_replacewith) Then
					li_rc = idw_requestor.SetItem(al_row, as_colname, &
								Time(inv_findattrib.is_replacewith))
				Else
					of_MessageBox ('pfc_find_replaceinvalidtime', 'Replace', &
						'The Replace With value is not a valid time.', Information!, Ok!, 1)					
					li_rc = -2
				End If								
			End If
		End If	
		Return li_rc /* Time */		
		
	Case 'char' 
		If of_Find(as_colname, inv_findattrib.is_find, al_row, al_row) = al_row Then
			//Get the entire string.
			ls_find = idw_requestor.GetItemString(al_row, as_colname)

			If (inv_findattrib.ib_matchcase) Then
				li_find_startpos = Pos(ls_find, inv_findattrib.is_find)
			Else
				li_find_startpos = Pos(Lower(ls_find),Lower(inv_findattrib.is_find))
			End If

			//Handle edimask fields.
			If ls_editstyle='editmask' Then
				//Check if the selected text matches the the "Find string".
				//Get "Masked Find"  and its appropriate length.
				ls_maskedfind = of_GetItem(al_row, as_colname)
				li_maskedfind_textlen = Len(ls_maskedfind)
				li_maskedfind_startpos = Pos (ls_maskedfind, ls_selectedtext)
				li_maskedfind_selectedtextlen = Len(ls_selectedtext)
				
				li_count = 1
				For li_i = 1 to li_maskedfind_textlen
					If Mid(ls_find, li_count, 1) =  Mid(ls_maskedfind, li_i, 1) Then
						If li_i >= li_maskedfind_startpos And &
							li_i <= li_maskedfind_startpos + (li_maskedfind_selectedtextlen -1) Then
							ls_maskedfind_selectedtext = ls_maskedfind_selectedtext + Mid(ls_find, li_count, 1)
						ElseIf li_i > li_maskedfind_startpos + (li_maskedfind_selectedtextlen -1) Then
								Exit
						End If
						li_count ++							
					End If
				Next 
				
				//Check if the selected text matches the the "Find string".					
				If (inv_findattrib.ib_matchcase And &
						ls_maskedfind_selectedtext = inv_findattrib.is_find) Or &
					(Not inv_findattrib.ib_matchcase And &
						Lower(ls_maskedfind_selectedtext) = Lower(inv_findattrib.is_find)) Then
					lb_replacechars = True
				End If
			Else
				//Check if the selected text matches the the "Find string".
				If (inv_findattrib.ib_matchcase And &
						ls_selectedtext = inv_findattrib.is_find) Or &
					(Not inv_findattrib.ib_matchcase And &
						Lower(ls_selectedtext) = Lower(inv_findattrib.is_find)) Then
					lb_replacechars = True
				End If
			End If
				
			If lb_replacechars Then
				//Replace the "Find" characters with the "ReplaceWith" characters.
				ls_find = Replace(ls_find, li_find_startpos, Len(inv_findattrib.is_find), &
							inv_findattrib.is_replacewith)
				li_rc = idw_requestor.SetItem(al_row, as_colname, ls_find)
			End If
		End If
		Return li_rc /* Char */
		
	Case Else
		//Code should never reach this line.		
		Return -1
End Choose

//Code should never reach this line.
Return -1
end function

     
Name Owner
pfc_n_cst_dwsrv_find.pfc_replace pfc_n_cst_dwsrv_find

     
Name Owner
datawindow.describe datawindow
datawindow.getitemstring datawindow
datawindow.selectedtext datawindow
datawindow.setitem datawindow
datawindow.setitem datawindow
systemfunctions.date systemfunctions
systemfunctions.dec systemfunctions
systemfunctions.isdate systemfunctions
systemfunctions.isnumber systemfunctions
systemfunctions.istime systemfunctions
systemfunctions.left systemfunctions
systemfunctions.len systemfunctions
systemfunctions.long systemfunctions
systemfunctions.lower systemfunctions
systemfunctions.mid systemfunctions
systemfunctions.pos systemfunctions
systemfunctions.replace systemfunctions
systemfunctions.time systemfunctions
pfc_n_cst_dwsrv.of_getitem pfc_n_cst_dwsrv
pfc_n_cst_dwsrv_find.of_find pfc_n_cst_dwsrv_find
pfc_n_base.of_messagebox pfc_n_base

     
Full name
No Data

     
Name Scope
No Data