I have probably a trivial problem related to reading the date from the DateField control.
On the form in Base there is a DateField control named let's say "data_ur". The field is connected to the corresponding field in the table. The form works correctly, I can view, add and edit records. However, I want to add some logic using a Basic script and here I have a problem.
How can I read and write the date to such a field from a Basic script?
I have no problem with typical text fields, but I can't get along with the date field.
I will be grateful for a few lines of code example in Basic how to read and write the date to such a field.
[Solved] Reading and writing date from/to DateField via Basic
[Solved] Reading and writing date from/to DateField via Basic
Last edited by Hypno on Fri May 12, 2023 2:00 pm, edited 2 times in total.
LibreOffice 7.2.2.1 (x64), Windows 10
-
- Volunteer
- Posts: 1558
- Joined: Wed Jun 24, 2015 12:56 am
- Location: Colorado, USA
Re: Reading and writing date from/to DateField via Basic
Go to
https://www.pitonyak.org/oo.php
Download the English Macro Document
Search for Manipulating Dates
For a more complete discussion of Dates download his book "OpenOffice.org Macros Explained.odt V4" which is also available on that web site.
https://www.pitonyak.org/oo.php
Download the English Macro Document
Search for Manipulating Dates
For a more complete discussion of Dates download his book "OpenOffice.org Macros Explained.odt V4" which is also available on that web site.
If your problem has been solved, please edit this topic's initial post and add "[Solved]" to the beginning of the subject line
Apache OpenOffice 4.1.14 & LibreOffice 7.6.2.1 (x86_64) - Windows 10 Professional- Windows 11
Apache OpenOffice 4.1.14 & LibreOffice 7.6.2.1 (x86_64) - Windows 10 Professional- Windows 11
Re: Reading and writing date from/to DateField via Basic
[Tutorial] Date-Time Conversion in StarBasic includes a function to convert anything into anything else.
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
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Re: Reading and writing date from/to DateField via Basic
Libreoffice 7.4 on Debian 12 (Bookworm) (on RaspberryPI4)
Libreoffice 24.8… flatpak on Debian 12 (Bookworm) (on RaspberryPI4)
Re: Reading and writing date from/to DateField via Basic
I guess I didn't describe the problem clearly enough.
In the OO Base application I have a form, on it I have a "Date Field" type control. The form is based on a data table, and this control is based on a date field from that table. The standard form handling works as it should, but I want to make some additional function that will modify the value of this control to display the date.
For example, the control contains the date of birth, and I want to modify this date with the Basic script, and of course I expect that this change will be saved in the table where the original value came from.
In the case of the txt field, the matter is simple, I read the value of the Text property and I have the content of the window, i.e.:
PESEL = oForm.getByName("fmtpesel").Text
When I want to save something new, I do the opposite, i.e
oForm.getByName("fmtpesel").Text = PESEL
I want to do the same with the "Date Field" form, but I just don't know how...
Which property to read or which method to use for writing and which for reading?
My problem is not with Basic syntax and functions but with this particular date display control.
In the OO Base application I have a form, on it I have a "Date Field" type control. The form is based on a data table, and this control is based on a date field from that table. The standard form handling works as it should, but I want to make some additional function that will modify the value of this control to display the date.
For example, the control contains the date of birth, and I want to modify this date with the Basic script, and of course I expect that this change will be saved in the table where the original value came from.
In the case of the txt field, the matter is simple, I read the value of the Text property and I have the content of the window, i.e.:
PESEL = oForm.getByName("fmtpesel").Text
When I want to save something new, I do the opposite, i.e
oForm.getByName("fmtpesel").Text = PESEL
I want to do the same with the "Date Field" form, but I just don't know how...
Which property to read or which method to use for writing and which for reading?
My problem is not with Basic syntax and functions but with this particular date display control.
LibreOffice 7.2.2.1 (x64), Windows 10
Re: Reading and writing date from/to DateField via Basic
Hello,
find attached a version without using CDateFromUnoDate or CDateToUnoDate, because AOO doesn't support these functions, only LO has them.
My approach is not to read or write to the control itself, but reading or writing directly to the underlying table using following code:
R
find attached a version without using CDateFromUnoDate or CDateToUnoDate, because AOO doesn't support these functions, only LO has them.
My approach is not to read or write to the control itself, but reading or writing directly to the underlying table using following code:
Code: Select all
Sub read_Date
oForm = ThisComponent.Drawpage.Forms.getbyName("MainForm")
oDate = oForm.Columns.getbyName("DATE").getDate
'print CDateFromUnoDate(oDate) 'Only LO
print "Year: " & oDate.year & " Month: " & oDate.month &" Day: " & oDate.day
End Sub
Sub write_Date
Dim dDate as new com.sun.star.util.Date
sDate = Inputbox("Enter Date", "Input","MM/DD/YYYY")
aDate = split (sDate,"/")
dDate.month = aDate(0)
dDate.day = aDate(1)
dDate.year = aDate(2)
'dDate = CDateToUnoDate(sDate)'only LO
oForm = ThisComponent.Drawpage.Forms.getbyName("MainForm")
oDate = oForm.Columns.getbyName("DATE").updateDate(dDate)
if oForm.isnew then oForm.insertRow else oForm.updateRow
End Sub
- Attachments
-
- RW_DATES.odb
- (18.31 KiB) Downloaded 343 times
- MMove 1.0.6
- Extension for easy, exact positioning of shapes, pictures, controls, frames ...
- my current system
- Windows 10 AOO, LOLinux Mint AOO, LO
Re: Reading and writing date from/to DateField via Basic
This is the information I was waiting for...
I'll have a look but I tried the getDate method and it didn't work. Either some bug or something with the versions, I'm using LibreOffice 7.5.2.2
Let me ask you one question, I'm looking for some document detailing and discussing properties, methods and events for controls. Ideally, the document should be with examples for Basic. I feel like I've looked through thousands of web pages and haven't found anything like this. Or can you recommend a book on the subject?
I used to write entire applications for Access, recently I've been programming PDF forms and now I'm struggling with OO Base and Basic.
Thanks for the hint!
I'll have a look but I tried the getDate method and it didn't work. Either some bug or something with the versions, I'm using LibreOffice 7.5.2.2
Let me ask you one question, I'm looking for some document detailing and discussing properties, methods and events for controls. Ideally, the document should be with examples for Basic. I feel like I've looked through thousands of web pages and haven't found anything like this. Or can you recommend a book on the subject?
I used to write entire applications for Access, recently I've been programming PDF forms and now I'm struggling with OO Base and Basic.
Thanks for the hint!
LibreOffice 7.2.2.1 (x64), Windows 10
Re: [Solved] Reading and writing date from/to DateField via Basic
There is no Bug, you made a miststake somewhere else.I'll have a look but I tried the getDate method and it didn't work. Either some bug or something with the versions, I'm using LibreOffice 7.5.2.2
For that reason, i sent a sample which you did not even loaded down.
EDIT 05/14/2023:
https://www.pitonyak.org/oo.phpOr can you recommend a book on the subject?
the same as UnklDonald418 already mentioned above.
In addition use MRI or Xray
- MMove 1.0.6
- Extension for easy, exact positioning of shapes, pictures, controls, frames ...
- my current system
- Windows 10 AOO, LOLinux Mint AOO, LO