OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

How to detect an invalid date format in a cell?

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API
View previous topic :: View next topic  
Author Message
topher
General User
General User


Joined: 29 Sep 2004
Posts: 12

PostPosted: Wed Sep 29, 2004 7:54 pm    Post subject: How to detect an invalid date format in a cell? Reply with quote

Can anyone give me a sample code on how to detect if a date in a cell is not in a e.g. 9/30/04 format. I want to detect invalid entries like letters and numbers (e.g. werer, 24434 etc.) and invalid dates like 9/36/04 and invalid formats like 9-3-04.


t.y.
Back to top
View user's profile Send private message
r_vinoya
Super User
Super User


Joined: 03 Dec 2003
Posts: 619
Location: Somewhere in the Philippines

PostPosted: Thu Sep 30, 2004 12:42 am    Post subject: Re: How to detect an invalid date format in a cell? Reply with quote

topher wrote:
Can anyone give me a sample code on how to detect if a date in a cell is not in a e.g. 9/30/04 format. I want to detect invalid entries like letters and numbers (e.g. werer, 24434 etc.) and invalid dates like 9/36/04 and invalid formats like 9-3-04.


t.y.


Hello topher,

Try this:

To check is date is valid:
Code:
PRINT ISDATE(thiscomponent.sheets(0).getcellbyposition(0,0).string) 'returns True if Sheet1.A1 is a valid date entry, text entry


To check if format is invalid:

For Format M/DD/YY:
Code:
If thiscomponent.sheets(0).getcellbyposition(0,0).numberformat<>106 then
 print "invalid format"
endif


Note: You can try experimenting with different numberformat and print it: (msgbox thiscomponent.sheets(0).getcellbyposition(0,0).numberformat) to get the desired code.
_________________
# : - )
Back to top
View user's profile Send private message
DannyB
Moderator
Moderator


Joined: 02 Apr 2003
Posts: 3991
Location: Lawrence, Kansas, USA

PostPosted: Thu Sep 30, 2004 5:59 am    Post subject: Reply with quote

It might also be helpful to look at the first message in this thread....

Calc Examples
http://www.oooforum.org/forum/viewtopic.php?t=4996

and see how I format date cells.
_________________
Want to make OOo Drawings like the colored flower design to the left?
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group