Ask Your Question
0

Calc Calendar BASIC Error [closed]

asked 2014-09-01 08:36:40 +0100

asteynberg gravatar image

I have a calendar menu implemented in my timesheet spreadsheet. Up until Libreoffice 4.1.0.4 everything worked fine, with all versions after that and even the latest version I'm getting a "BASIC runtime error"Libreoffice Error.jpg

Anyone have ideas how I can fix this?

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by Alex Kemp
close date 2016-03-14 03:03:07.858052

3 Answers

Sort by » oldest newest most voted
0

answered 2014-09-01 09:33:24 +0100

karolus gravatar image

updated 2014-09-01 09:53:39 +0100

why don't you simply copy and paste your code instead of these silly screenshots ??

the Date -property has changed to a Struct

change this part to:

if oCell.Value = 0 then
    oControl.Date.Year  =  year( now() )
    oControl.Date.Month =  month( now() )
    oControl.Date.Day   =  day( now() )
edit flag offensive delete link more
0

answered 2014-09-10 10:28:39 +0100

asteynberg gravatar image

updated 2014-09-11 18:57:22 +0100

karolus gravatar image

hi karolus

sorry did not even think to paste the code, makes much more sense! i did paste in your new code, but still gives me the same error? Im on libreoffice 4.3.0.4

REM  *****  BASIC  *****
Option Explicit

REM ##############################
REM  These routines allow calc users to use calendar date form widgets to
REM  enter dates into spreadsheet cells. Only cells which have a cell style
REM  name that begins with "Calendar" (e.g. Calendar, CalendarLong, Calendar02,...)
REM  will be enabled for calendar widget input
REM
REM  To enable a calc document to use this tool, tie the "EnableCalendarCellFormats"
REM  subroutine to the Open Document event (see menu Tools -> Customize -> Events)
REM ##############################

Sub EnableCalendarCellFormats

REM exit if this is not a calc spreadsheet
If NOT ThisComponent.supportsService( "com.sun.star.sheet.SpreadsheetDocument" ) Then Exit Sub

REM create a  mouse-click handler to intercept when a user clicks on a spreadsheet cell
Dim xMouseClickHandler
xMouseClickHandler = createUnoListener( "cbMouseClick_", "com.sun.star.awt.XEnhancedMouseClickHandler" )
ThisComponent.CurrentController.addEnhancedMouseClickHandler( xMouseClickHandler )

REM clean up any left-over calendar fields if the user unwittingly saved some in the file
Dim i As Integer
For i = 0 To ThisComponent.Sheets.Count - 1
  sbRemoveDateFields( ThisComponent.Sheets.getByIndex( i ).DrawPage )
Next

End Sub

REM ###############

Function cbMouseClick_mousePressed( aEvent ) As Boolean

REM when the user clicks on a spreadsheet cell, add a calendar widget on top
REM of the cell, sized to the cell's height and width

Dim oCell As Object

REM consume the mouse-click
cbMouseClick_mousePressed = TRUE
oCell = aEvent.Target
If NOT oCell.supportsService( "com.sun.star.table.Cell" ) Then Exit Function

REM remove any existing DateField calendars
sbRemoveDateFields( oCell.Spreadsheet.DrawPage )

REM if not Calendar cell style, bail out
If Left( oCell.CellStyle, 8 ) <> "Calendar" Then Exit Function


REM create a control shape of the right size and position
Dim oControlShape As Object
oControlShape = ThisComponent.createInstance( "com.sun.star.drawing.ControlShape" )
oControlShape.setPosition( oCell.Position )
oControlShape.setSize( oCell.Size )

REM create a control com.sun.star.form.component.DateField
Dim oControl As Object
oControl = ThisComponent.createInstance( "com.sun.star.form.component.DateField" )
oControl.Name = "CalendarFormatter123456"
oControl.Tag = oCell.AbsoluteName
oControl.DropDown = TRUE
oControl.DateFormat = 11 'YYYY-MM-DD

if oCell.Value = 0 then
 oControl.Date.Year  =  year( now() )
 oControl.Date.Month =  month( now() )
 oControl.Date.Day   =  day( now() )
Else
 oControl.Date = cDateToIso( oCell.Value )
End If

REM insert the calendar field on top of the cell
oControlShape.setControl( oControl )
oCell.Spreadsheet.DrawPage.add( oControlShape )

REM add a property change listener on the control's date property
Dim xPropChangeListener As Variant
xPropChangeListener = createUnoListener( "cbDateChange_", _
                         "com.sun.star.beans.XPropertyChangeListener" )
oControl.addPropertyChangeListener( "Date", xPropChangeListener )
cbMouseClick_mousePressed = FALSE

End Function

REM ###############

Sub cbDateChange_propertyChange( aEvent )

REM whenever the calendar widget's date property updates, update the cell value

Dim oCell As Object
If NOT isEmpty( aEvent.NewValue ) Then
oCell = ThisComponent.CurrentController.ActiveSheet.getCellRangeByName( aEvent.Source.Tag )
oCell.Value = cDateFromIso( aEvent.NewValue )
End If

End Sub

REM ###############
REM unused listener call-backs

Sub cbDateChange_disposing()
End Sub

Function cbMouseClick_mouseReleased( aEvent ) As Boolean
cbMouseClick_mouseReleased = TRUE
End Function

Function ...
(more)
edit flag offensive delete link more

Comments

Write below else the similar pattern to the pattern above else

karolus gravatar imagekarolus ( 2014-09-11 19:04:48 +0100 )edit
0

answered 2015-11-16 02:07:47 +0100

Alex Kemp gravatar image

The DateField.Date object member changed from a long value to a ::com::sun::star::util::Date Struct value at 4.1.1. Therefore, you need to use CDateToUnoDate/CDateFromUnoDate functions to transfer values rather than cDateToIso/cDateFromIso functions with post-LO-4.1 macros.

To save a great deal of writing, download & look at the macros in the ODS in Q60894.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2014-09-01 08:36:40 +0100

Seen: 566 times

Last updated: Nov 16 '15