Bug 129436 - Unclear documentation of InStr "Compare" parameter
Summary: Unclear documentation of InStr "Compare" parameter
Status: RESOLVED FIXED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Documentation (show other bugs)
Version:
(earliest affected)
7.0.0.0.alpha0+
Hardware: All All
: medium normal
Assignee: fpy
URL:
Whiteboard: target:25.2.0
Keywords:
Depends on:
Blocks: 146902
  Show dependency treegraph
 
Reported: 2019-12-16 21:05 UTC by Jim Avera
Modified: 2024-09-01 07:05 UTC (History)
2 users (show)

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 2019-12-16 21:05:01 UTC
Description:
The documentation for Basic function "InStr" says

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

What does "return parameter" refer to here?   

Probably the wording should be clarified to give the parameter's name (is it 'Start' ?) and not say "return" unless the parameter is passed by value.

Note: None of the parameters are documented to return anything, although they are passed by reference (since not declared 'ByVal').

Steps to Reproduce:
1. Search for "InStr" in the Help

Actual Results:
.

Expected Results:
.


Reproducible: Always


User Profile Reset: No



Additional Info:
Comment 1 Jim Avera 2019-12-16 21:06:11 UTC
Typo, meant "unless the parameter is passed by reference"
Comment 2 Jim Avera 2019-12-16 21:13:42 UTC
While fixing this, there are a couple of other improvements which could be made:

* Mention whether the first position of a string is 1 or 0.

* Show the result from the code example (currently it just lists the code without saying what the expected result is).
Comment 3 Olivier Hallot 2019-12-16 21:22:50 UTC
In the example of the Help page on InStr, if we ommit Start and define Compare, we get an error. E.g.

iPos = Instr(sInput,"c",0)

Thus I think the word "return" is misleading and should be removed.
Comment 4 Olivier Hallot 2019-12-16 21:31:38 UTC
(In reply to Jim Avera from comment #2)
> While fixing this, there are a couple of other improvements which could be
> made:
> 
> * Mention whether the first position of a string is 1 or 0.

Wrong. For the same example,

 iPos = Instr(4,"Office","f",0)

the result is 0 because the search starts at position 4 and 'f' occurs at 2 and 3. IOW, it will search 'f' in string 'ice'.

> 
> * Show the result from the code example (currently it just lists the code
> without saying what the expected result is).

Agree.
Comment 5 Olivier Hallot 2019-12-16 21:32:37 UTC
correction, string "ce".
Comment 7 fpy 2024-08-01 17:19:53 UTC
apparently the compare parameter is rounded to int, and any non-zero value is considered case insensitive.

 Instr(1, "LibreOffice Calc", "o",  0.4)   ' return 0

 Instr(1, "LibreOffice Calc", "o", -0.5)   ' return 6

see also transliteration "feature" in tdf#148650.
Comment 9 Commit Notification 2024-08-31 16:40:50 UTC
Pierre F committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/help/commit/dc7a2b091a7652d4907391f8e39262b65ae6c780

clarify Instr(). tdf#129436, tdf#139840