Bug 141758 - vba NumberFormat for dates does only work once and never again
Summary: vba NumberFormat for dates does only work once and never again
Status: NEW
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: BASIC (show other bugs)
Version:
(earliest affected)
6.3.0.4 release
Hardware: All Linux (All)
: medium normal
Assignee: Not Assigned
URL:
Whiteboard:
Keywords: bibisectRequest, regression
Depends on:
Blocks: Macro-VBA
  Show dependency treegraph
 
Reported: 2021-04-19 09:15 UTC by Harald Langheinrich
Modified: 2023-05-21 10:34 UTC (History)
4 users (show)

See Also:
Crash report or crash signature:


Attachments
sub RunThis is inthis file (9.08 KB, application/vnd.oasis.opendocument.spreadsheet)
2021-07-08 20:41 UTC, Harald Langheinrich
Details
sub RunThis is in his file (8.88 KB, application/vnd.oasis.opendocument.spreadsheet)
2021-07-08 21:21 UTC, Harald Langheinrich
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Harald Langheinrich 2021-04-19 09:15:54 UTC
Description:
REM  *****  BASIC  *****
Option VBASupport 1
Option Compatible
Option explicit

Sub Datum()
  Dim s_tmp As String, d_date As Date


  s_tmp = InputBox("Plaese insert date :-)", _
                  "Inputbox")
  'check date or string
  If IsDate(s_tmp) Then
    'String into date format
    d_date = s_tmp
    'set Format set Date
    Range("A1").NumberFormat = "dd/mm/yyyy;@"
    Range("A1").Value = d_date
  Else
    'no date insert String 
    Range("A1").NumberFormat = "@"
    Range("A1").Value = s_tmp
  End If
End Sub

Steps to Reproduce:
1.run example twice
2.
3. and enter date for a second time

Actual Results:
runtime error 1

Expected Results:
no error 


Reproducible: Always


User Profile Reset: No



Additional Info:
[Information automatically included from LibreOffice]
Locale: de
Module: BasicIDE
[Information guessed from browser]
OS: Linux (All)
OS is 64bit: yes
Comment 1 Xisco Faulí 2021-04-22 09:48:34 UTC
Thank you for reporting the bug. Please attach a sample document, as this makes it easier for us to verify the bug. 
I have set the bug's status to 'NEEDINFO'. Please change it back to 'UNCONFIRMED' once the requested document is provided.
(Please note that the attachment will be public, remove any sensitive information before attaching it. 
See https://wiki.documentfoundation.org/QA/FAQ#How_can_I_eliminate_confidential_data_from_a_sample_document.3F for help on how to do so.)
Comment 2 Harald Langheinrich 2021-07-08 20:41:03 UTC
Created attachment 173464 [details]
sub RunThis is inthis file

sub RunThis calls two times sub Datum

first time witout error 
second time with error

Why ?
Comment 3 Harald Langheinrich 2021-07-08 21:21:15 UTC
Created attachment 173465 [details]
sub RunThis is in his file

NumberFormat works when entering no date
Comment 4 Buovjaga 2021-07-19 16:11:53 UTC
(In reply to Harald Langheinrich from comment #3)
> Created attachment 173465 [details]
> sub RunThis is in his file
> 
> NumberFormat works when entering no date

If I enter a date in the format dd.mm.yyyy, I get the error immediately and nothing is inserted.

If I enter a date in the format dd/mm/yyyy it works fine both times.

The macro code looks correct (I could be wrong), so let's set to NEW.

NixOS
Version: 7.3.0.0.alpha0+ / LibreOffice Community
Build ID: b1df9c67349cf4cc5be4128d797aefb87f50e38f
CPU threads: 16; OS: Linux 5.13; UI render: default; VCL: x11
Locale: fi-FI (fi_FI.UTF-8); UI: en-US
Calc: threaded
Comment 5 Buovjaga 2021-08-10 18:32:22 UTC
Already seen in oldest of 6.3 bibisect repo, but not yet in latest of 5.0
Comment 6 raal 2021-08-26 15:29:21 UTC
No error in Linux bibisect-44max master, but I get error in bibisect-50max oldest.
Comment 7 Nigel Lee 2022-06-05 13:53:42 UTC
The isdate() function recognises a date entered in dd/mm/yyyy format, but not another cell which adds 1 (day) to that date, which is returned as a number.
(I creted a calendar in Excel, which uses a combination of formulae and formatting to determine subsequent date values by adding 1 (day) or 7 (week) for sequencial rows and columns.
I added code to scan the sheet and compare dates against a list of events (e.g. birthdays) from another sheet, to automatically fill in details in the corresponding position (each 'day' is made up of 3 rows).
It works fine in Excel, but fails in Libre Office VBA, because I use isdate() to skip values before the start, and beyond the end, of the month, and it doesn't recognise a numeric date value!