Bug 137668 - Basic InStr() does not support documented 'Start' argument
Summary: Basic InStr() does not support documented 'Start' argument
Status: RESOLVED INVALID
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: BASIC (show other bugs)
Version:
(earliest affected)
3.3.0 release
Hardware: All All
: medium normal
Assignee: Not Assigned
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-10-21 23:22 UTC by Jim Avera
Modified: 2020-10-22 04:25 UTC (History)
0 users

See Also:
Crash report or crash signature:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jim Avera 2020-10-21 23:22:59 UTC
Description:
The Basic language "InStr" function is documented to have an optional initial argument giving the starting offset for searching.  However any attempt to pass a number for the first argument raises an "Invalid Procedure Call" function.

Seems to be inherited from OO (occurs in LO 3.3)

Either this should be fixed, OR the documentation changed to say the 'start' argument is not supported by Libre Office.  

To save the remaining hair on programmers' heads!

Here is the current (LO 7.x) documentation for the InStr function:

«
InStr ([Start As Long,] Text1 As String, Text2 As String[, Compare])

Parameters:

Start: A numeric expression that marks the position in a string where the search for the specified substring starts. If you omit this parameter, the search starts at the first character of the string. The maximum allowed value is 65535.

Text1: The string expression that you want to search.

Text2: The string expression that you want to search for.

Compare: Optional numeric expression that defines the type of comparison. The value of this parameter can be 0 or 1. The default value of 1 specifies a text comparison that is not case-sensitive. The value of 0 specifies a binary comparison that is case-sensitive.

To avoid a run-time error, do not set the Compare parameter if the first return parameter is omitted.
»

[So it must be intended to work by checking the type of the first argument to see if it is a string or a number]


Steps to Reproduce:
1. Start LO calc
2. Tools->Macros->Organize Macros->Basic
3. Navigate to the current document (e.g. "Untitled1", create a new module, and paste the following Basic code into the empty module:


sub bugdemo
  Dim i
  Dim start as Long
  start = 0
  i = InStr(start, "abc", "b")
  MsgBox "Succeeded, returned " & i
end sub

4. Place cursor inside the above function and click "Run" button on the toolbar

Actual Results:
Popup says "Action not supported; Invalid procedure call"

Expected Results:
Should work, or else be documented to not work.


Reproducible: Always


User Profile Reset: No



Additional Info:
.
Comment 1 Jim Avera 2020-10-21 23:26:59 UTC
I forgot to mention that ading the "Compare" argument does not make it work, so

  InStr(0, "abc", "b", 0)

still raises the "Invalid Procedure Call" error



Version: 6.4.8.0.0+
Build ID: 71a3f015f2ac45ad4a2625a3b6398f5d75feed40
CPU threads: 12; OS: Linux 5.4; UI render: default; VCL: gtk3; 
TinderBox: Linux-rpm_deb-x86_64@86-TDF, Branch:libreoffice-6-4, Time: 2020-10-01_08:33:37
Locale: en-US (en_US.UTF-8); UI-Language: en-US
Calc: threaded
Comment 2 Jim Avera 2020-10-22 00:07:54 UTC
Ach! Never mind.   Start counts from 1, not 0.   

If you pass 0 you get "Invalid Procedure Call"
Comment 3 Mike Kaganski 2020-10-22 04:25:10 UTC
The function is clarified in 7.1 (tdf#136213):

https://help.libreoffice.org/7.1/en-US/text/sbasic/shared/03120401.html