CINT("+1") returns 0

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
Almax
Posts: 1
Joined: Wed Jun 15, 2022 2:23 pm

CINT("+1") returns 0

Post by Almax »

Guess about the return of:
x = cint("+1")
I Think that return 1 is very sucessful. :bravo:
But my macro return is 0 zero. :crazy:
Apache Open Office 4.1.7 on Windows 10.
 Edit: Changed subject, was cint() with error? 
Make your post understandable by others 
-- MrProgrammer, forum moderator 
Apache Open Office 4.1.7 Windows 10
User avatar
Villeroy
Volunteer
Posts: 31269
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: cint() with error?

Post by Villeroy »

This has been fixed in LibreOffice.

https://www.libreoffice.org/discover/li ... penoffice/
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
JeJe
Volunteer
Posts: 2763
Joined: Wed Mar 09, 2016 2:40 pm

Re: cint() with error?

Post by JeJe »

It treats anything with a "+" as a string that evaluates to 0.

Strip the + or use

Code: Select all

cint(val(("+1"))
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
Bidouille
Volunteer
Posts: 574
Joined: Mon Nov 19, 2007 10:58 am
Location: France

Re: CINT("+1") returns 0

Post by Bidouille »

Helpfile (F1) says for CInt
Expression: Any numeric expression that you want to convert.
JeJe
Volunteer
Posts: 2763
Joined: Wed Mar 09, 2016 2:40 pm

Re: CINT("+1") returns 0

Post by JeJe »

Bidouille - mine says,
CInt Function [Runtime]
Converts any string or numeric expression to an integer.
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
User avatar
Zizi64
Volunteer
Posts: 11352
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: CINT("+1") returns 0

Post by Zizi64 »

This has been fixed in LibreOffice.
Not in my LO 6.1.6, but it works in my portable LO 7.3.2
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
cwolan
Posts: 129
Joined: Sun Feb 07, 2021 3:44 pm

Re: CINT("+1") returns 0

Post by cwolan »

Zizi64 wrote:Not in my LO 6.1.6, but it works in my portable LO 7.3.2
LibreOffice fixed that bug [1] in 7.1
I see CInt() work correctly e.g. in version 7.1.0.2

The entry for CInt() in online Help has been expanded for version 7.3
You may compare: LibreOffice 7.2 Help and LibreOffice 7.3 Help


[1]
Bug 136801 - BASIC: CInt("+2") returns 0
OpenOffice 1.1.5 – 4.1.15
LibreOffice 6.4.7 – 7.6.5
Windows 7,10,11 64-bit
cwolan
Posts: 129
Joined: Sun Feb 07, 2021 3:44 pm

Re: CINT("+1") returns 0

Post by cwolan »

In case of Apache OpenOffice — new Bugzilla issue

Issue 128518 - Basic - Converting "+1" to a number
OpenOffice 1.1.5 – 4.1.15
LibreOffice 6.4.7 – 7.6.5
Windows 7,10,11 64-bit
User avatar
floris v
Volunteer
Posts: 4422
Joined: Wed Nov 28, 2007 1:21 pm
Location: Netherlands

Re: CINT("+1") returns 0

Post by floris v »

A workaround is to make your own custom cint function, that first checks if the argument starts with a + sign, if so deletes it and then feeds the result to the original cint function. Don't expect this bug to get fixed any time soon.
OpenOffice 4.1.11 on Ubuntu; LibreOffice 6.4 on Linux Mint, LibreOffice 7.6.2.1 on Ubuntu
If your problem has been solved or your question has been answered, please edit the first post in this thread and add [Solved] to the title bar.
Nederlandstalig forum
User avatar
Lupp
Volunteer
Posts: 3542
Joined: Sat May 31, 2014 7:05 pm
Location: München, Germany

Re: CINT("+1") returns 0

Post by Lupp »

Somebody's help wrote: CInt Function [Runtime]
Converts any string or numeric expression to an integer.
Yes.
But "any string" may not be recognized as "numeric", even if the user thought it was. CInt(something) generally returns the value 0 if 'something' not was accepted as numeric. Strings starting with a "+" character were not regarded numeric also by the Basic function ISNUMERIC() due to a legacy bug for a long time.
And what is accepted as a "numeric expression" in this specific context isn't explained - and isn't subject to the ODF specifications.
LibreOffice got fixed THIS bug some time ago. However, you shouldn't think the life of bugs generally is too hard in LibO.
The offhand example

Code: Select all

h = CInt("+10000E-3 - 77")
I just tried in Basic under LibO 7.3.3.2 returned neither an error nor a value of 0 or -67 for h, but h = 10 - and so does the less ambitious

Code: Select all

h = CInt("10 - 77")
Programming in Basic you walk over cracky ice. If you need reliable results, you shouldn'tuse functions where any faint doubt exists. The help texts never are precise enough. They aren't sufficiently complete either.

BTW
In the context of formula evaluation in Calc

Code: Select all

= "0" + "+10000E-3 - 77"
is an error, while

Code: Select all

="+10000E-3" -" 77"
evaluates to -67 regarding the specifications concerning automatic type conversion.
In Basic, on the other hand, "10" + "77" makes "1077" because, based on a convention from the stone-age, Basic still uses the operator + also for concatenation if the context allows it.
Overloaded operators are a way to hell.

Write a few extra lines of code instead of trusting in doubtable automatisms.
On Windows 10: LibreOffice 24.2 (new numbering) and older versions, PortableOpenOffice 4.1.7 and older, StarOffice 5.2
---
Lupp from München
JeJe
Volunteer
Posts: 2763
Joined: Wed Mar 09, 2016 2:40 pm

Re: CINT("+1") returns 0

Post by JeJe »

Don't expect this bug to get fixed any time soon.
Likely. Its a trivial bug affecting the tiny subset of macro users (in turn a very small subset of users) who will ever use a "+" at the start of a string... with easy workarounds. Worth knowing about though...
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
Post Reply