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

A Person kztyrvlq at ...966...
Mon Mar 20 01:15:51 CET 2006


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
   PRINT ERROR, ERROR.CODE, ERROR.CLASS
   iStartAt = iTemp + Len("change")
   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






More information about the User mailing list