When I out of home, I take my laptop. Recently, my Inter one had a Monitor crash (it does not works anymore).
So, when I have time, I check some code / write some code on a MacBook Pro M1. So I do yesterday.
In this case, I wanted to add a Search into a TextArea new feature. I took for an example in the “Introduction to Programming with Xojo.pdf” v4 (API2).
I found code that used IndexOf.
Back home, I tried to convert it to Standard API and failed. At last, I used InStr.
But I want to understand what happened / why I failed. Here’s the code and a screen shot at my demo function.
So, the line I failed to convert to Standard API is:
FoundAt = Source_String.IndexOf(Search_Loc, Search_String)
Code from the PB_Search PushButton:
Sub Action() Handles Action Var Found_Loc As Integer Var Source_String As String Var Search_String As String Var FoundAt As Integer // Get the Source String Source_String = TA.Text // Get the Search String Search_String = TF_Search.Text // Set the focus to the Search TextArea TA.SetFocus() // Search the String FoundAt = Source_String.IndexOf(Search_Loc, Search_String) // Report the location of the found text If FoundAt > 0 Then // Show the found occurence TA.VerticalScrollPosition = TA.LineNumber(FoundAt) // Highlight the found occurence TA.SelectionStart = FoundAt TA.SelectionLength = Len(Search_String) // I found one L_Info.Text = Search_String + " found at: " + Str(FoundAt) + "." // Update the Search Position Search_Loc = FoundAt + 1 Else // Not found L_Info.Text = Search_String + " was not found, sorry." End End Sub
How Many returns the number of found “Search_String” (as you can read in the screen shot). I also use IndexOf there.