mst@mx.csun.edu (Michael Temkin) (07/29/90)
While working with the "Extended Functions" Function Pack (included in Full Impact 2.0) I found a bug(feature?) in the Search function. The call is a follows: Search(find,text[,start]) Search will return the character position (1-n) where the string find begins in the string text. If the optional start parameter is given, the search begins at that character. The problem occurs if text is shorter than find. In this case the function returns !VALUE (I myself would prefer either 0 or -1). Be sure to test for this case! Below (for you amusement) I have included a much needed "Find" command (macro) that searches for text (or numbers) within a spreadsheet (I put it in my Global macros). It shows how to trap for the error (trivial). Call the first one something like "Find_Text" so it won't conflict with the "Find" function in the "Extened Functions", and call the second one something like "Find_Next". Mike. I have not check it, but I assume that the "Find" function also included in the "Extended Functions" also has this bug. It is the same function, only it is case-sensitive. -------------------------- Cut Here ------------------------------ Macro(f_Col,f_Row) ; ; This macro searches the spreadsheet in column major sequence ; for a specified text string. If f_Col and f_Row are passed in ; (eg. in a Find_Next call) the search begins with the cell (f_Col,f_Row). ; If f_Col and f_Row are not passed in, they are set to cell(A1). ; { find_text:=Get_String("Text to find") last_Row:=Row(Get_Last_Cell) last_Col:=Column(Get_Last_Cell) found:=False first_Row:=f_Row first_Col:=f_Col If (f_Row=0)&(f_Col=0) { first_Row:=1 first_Col:=1 } ; The 2 on the next line should be a <= (option ,) While (first_Col2last_Col) { ; The 2 on the next line should be a <= (option ,) While (first_Row2last_Row) { thisCell:=Cell(first_Col,first_Row) If ~Istext(thisCell) thisCell:=Num2c(Cell(first_Col,first_Row)) ; The 3 on the next line should be a >= (option .) ; Trap the string length problem If (Length(thisCell)3Length(find_text)) { If (Search(find_text,thisCell)>0) { Select(Cell(first_Col,first_Row)) curCell:=Get_Selection(1) Next_Cell(first_Col-Column(curCell),first_Row-Row(curCell)) first_Col:=last_Col first_Row:=last_Row found:=True } } first_Row:=first_Row+1 } first_Row:=1 first_Col:=first_Col+1 } If (found=False) Pause(3,"Text '"||find_text||"' not found") } Macro ; ; This macro calls Find_Text to locate the next occurrance of ; a specified string. The current cell is excluded. ; { curCell:=Get_Selection(1) dest_Col:=Column(curCell) dest_Row:=Row(curCell)+1 #Find_Text(dest_Col,dest_Row) } -- Mike Temkin mst@csun.edu ...!{sdcrdcf,hplabs,psivax,ttidca}!csun!mst Cal. State U. Northridge, School of Engineering and Computer Science Voice phone: (818) 885-3919