Bug 151901 - Typename() Vartype() argument names do not match that of VBA
Summary: Typename() Vartype() argument names do not match that of VBA
Status: RESOLVED FIXED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: BASIC (show other bugs)
Version:
(earliest affected)
Inherited From OOo
Hardware: All All
: medium normal
Assignee: Not Assigned
URL:
Whiteboard: target:7.6.0
Keywords:
Depends on:
Blocks:
 
Reported: 2022-11-04 14:43 UTC by Alain Romedenne
Modified: 2023-02-27 09:21 UTC (History)
1 user (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 Alain Romedenne 2022-11-04 14:43:05 UTC
Description:
Basic function argument names can be used either by position either by name.
TypeName() Vartype() argument name should be 'VarName' instead of 'Var'

- VBA doc:
https://learn.microsoft.com/en-us/office/vba/language/reference/user-interface-help/typename-function
https://learn.microsoft.com/en-us/office/vba/language/reference/user-interface-help/vartype-function
- libO Basic function signatures:
https://learn.microsoft.com/en-us/office/vba/language/reference/user-interface-help/typename-function

Steps to Reproduce:
Consider the following code:

Sub Main
	Const _Array=8192, _Variant=12
	Dim table(_3 To 5)
	Msgbox "TypeName(table): "&TypeName(var:=table) &Chr(13)& _
		"VarType(table)="&Vartype(var:=table) _
		,,"Array of Variant values"
End Sub



Actual Results:
Typename() Vartype() functions return respectively 'Variant()' and 8204 that is _Array+_Variant

Expected Results:
Typename and Vartype should use 'VarName' instead of 'Var'


Reproducible: Always


User Profile Reset: No

Additional Info:
See https://bugs.documentfoundation.org/show_bug.cgi?id=141474 for more information.
Comment 1 Alain Romedenne 2022-11-04 14:45:33 UTC
Link correction - LibO BASIC function signatures:
https://help.libreoffice.org/7.5/en-US/text/sbasic/shared/03103600.html?DbPAR=BASIC#bm_id3143267
Comment 2 Rafael Lima 2022-11-04 17:09:03 UTC
Indeed, both TypeName and VarType use "Var" as the argument name.

See: https://opengrok.libreoffice.org/xref/core/basic/source/runtime/stdobj.cxx?r=fbaf865f#869

In MS VBA the argument is called varname.

This might be a VBA compatibility issue. The code below does not work:

Option VBASupport 1

Sub TestVarName
    Dim a As Integer
    MsgBox TypeName(varname := a)
End Sub
Comment 3 Rafael Lima 2022-11-04 17:13:32 UTC
@Alain, do you think that changing this argument name might cause backwards compatibility problems?
Comment 4 Alain Romedenne 2022-11-04 17:51:23 UTC
(In reply to Rafael Lima from comment #3)
> @Alain, do you think that changing this argument name might cause backwards
> compatibility problems?

Keyword arguments documentation in help in recent - when I introduced BASIC syntax diagrams around 2020 - although discrepancies date from OOo. Such a risk is quite limited, while supporting the same keywords as VBA provides advantages.

https://gerrit.libreoffice.org/c/help/+/91506 added in 'keyword arguments' for Call statement.
see https://help.libreoffice.org/7.5/en-US/text/sbasic/shared/03090401.html?DbPAR=BASIC#bm_id3154422

tdf#147262 illustrates a recent argument name fix.
Comment 5 Commit Notification 2023-02-26 16:15:07 UTC
Alain Romedenne committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/fd19bc83cfd49937da8585b9ab938b2086ecf74a

tdf#141474 tdf#151901 BASIC functions argument names do not match that of VBA

It will be available in 7.6.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.