[Gambas-user] Text Search - string/textarea Issue - 1.0.14

ron ronstk at ...239...
Mon Mar 20 02:50:59 CET 2006


On Monday 20 March 2006 01:15, A Person wrote:
> Good Day All . . .
> 
> I am having an issue searching for text in a string/textarea.
> 
> The following code does not do as expected. It just keeps looping 
> through the string to be searched.
> 
> Public iStartAt as Integer
> 
> PUBLIC SUB btnFind_Click()
> 
>    DIM sTemp AS String
>    DIM iTemp AS Integer
> 
>    sTemp = textareaHelp.Text
>    iTemp = Instr(sTemp, "change", iStartAt) - 1

after the second found you press again 'find'
There are no more so iTemp is set to 0

>    PRINT ERROR, ERROR.CODE, ERROR.CLASS
>    iStartAt = iTemp + Len("change")

iStart wil be iTemp+6 at the 3'th press, resulting in your
display of 6 and the search point is again at the start of text.

>    PRINT iStartAt
> 
> END
> 
> The above code is an overly simplified version of my original. Repeated 
>   pressing of the Find button causes the code to loop over and over again
> incrementing the variable iStartAt each time.
> 
> The console printout for multiple Find presses is as follows:
> 
> True      45        (Class 0x80e46b8)
> 170
> True      45        (Class 0x80e46b8)
> 13865

> True      45        (Class 0x80e46b8)     <<<<     End file loop [added]
> 6
> True      45        (Class 0x80e46b8)
> 170
> True      45        (Class 0x80e46b8)
> 13865
> True      45        (Class 0x80e46b8)     <<<<     End file loop [added]
> 6
> 
> The found text is at 170 and 13865. In this instance the 6 probably 
> represents the length of the search text ("change"). No matching text is 
> found at position 6.
> 
> I think that the search should end at the end of the string or at the 
> end of the text in the textarea with a return error such as 1 - Found 
> and 0 - Not Found.
> 
> I originally tried this using a direct INSTR search of textareaHelp.Text 
> from text in a textbox but the looping caused a
> 
> "QTextCursor::gotoParagraph Index: -1 out of range"
> 
> console error. I substituted a string hoping that I could get around the 
> problem but it showed up here also.
> 
> Can anyone point me in the right direction or redirect my efforts.
> 
> As always, I ask. What am I doing wrong?
> 
> Thanks
> 
> Paul
> 

So next will do better job ?

   sTemp = textareaHelp.Text
   iTemp = Instr(sTemp, "change", iStartAt) - 1
   PRINT ERROR, ERROR.CODE, ERROR.CLASS

if iTemp=0 then
  ' keep iTemp at 0 and do not change iStartAt
  print "no more found" 
else
   iStartAt = iTemp + Len("change")
endif

   PRINT iStartAt

---
Ron




More information about the User mailing list