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 make macros?
Goto page Previous  1, 2
 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Writer
View previous topic :: View next topic  
Author Message
dgermann
OOo Advocate
OOo Advocate


Joined: 17 Mar 2003
Posts: 215

PostPosted: Sun Apr 27, 2003 5:42 pm    Post subject: macro you designed Reply with quote

tburcham--

Well, here is what the macro did: Opened a new document, and then entered "20:41:04 04/27/2003". So that looks like success.

I will need to get the exact order and format of the date the way I want, but this is a tremendous start!

Thanks, tburcham, you're noble! Very Happy

BTW, I am using OOo 1.0.1. I will have to upgrade once I figure out a few of these things.

PS: I got it to change the order of the date and time. How would you have it change the format of the date to say, December 31, 2003? Just sign me "Pushing my luck!" Wink
_________________
:-Doug.


Last edited by dgermann on Sun Apr 27, 2003 5:55 pm; edited 1 time in total
Back to top
View user's profile Send private message
dgermann
OOo Advocate
OOo Advocate


Joined: 17 Mar 2003
Posts: 215

PostPosted: Sun Apr 27, 2003 5:52 pm    Post subject: Auto text Reply with quote

John V--

OIC how it can work. That's slick. Wink

On not being able to see the whole of the dialogue box: seems to me that could go on the wish list for the developers--make those boxes respond to the size of the text. My old eyes cannot see the small stuff that is necessary to see the whole dialogue box. Sometimes I even have to get out a magnifying glass! Wink

Thanks for your help, John. You're great!
_________________
:-Doug.
Back to top
View user's profile Send private message
tburcham
General User
General User


Joined: 17 Apr 2003
Posts: 36

PostPosted: Sun Apr 27, 2003 9:51 pm    Post subject: No problem... Reply with quote

Quote:

...How would you have it change the format of the date to say, December 31, 2003? ...

(note: I edited this message and put in improved time format code )


Hi dgermann,
That's no problem. Here's a version that gives the time in 12-hour
format with no seconds, and the date in the format you wanted.

(this code has a "buglet" corrected May 6, 2003)
Code:

'--------------------------------------

'Note: If Writer isn't the top window when this
'is running then this may not work. It runs from
'the Basic editor if I have brought it to the top
'just before going to the editor.
Sub OnStartUp()
Dim oDoc      As Object
Dim oText      As Object
Dim oCursor      As Object
Dim oDisp      As Object
Dim oParser      As Object
Dim oUrl      As New com.sun.star.util.URL
Dim d         As String
Dim t         As String

   '------------------------------------------------
   'get access to the document
   oDoc = ThisComponent.CurrentController.Frame
   oParser = createUnoService("com.sun.star.util.URLTransformer")

   '------------------------------------------------
   'go to end of document
   oUrl.Complete = ".uno:GoToEndOfDoc"
   oParser.parseStrict(oUrl)
   oDisp = oDoc.queryDispatch(oUrl,"",0)
   oDisp.dispatch(oUrl,noargs())

   '------------------------------------------------
   'insert date etc
   oDoc = ThisComponent
   oText = oDoc.Text
   oCursor = oText.createTextCursor
   oCursor.GotoEnd(False)
   
   d = Choose(Month(Now), "January", "February", "March", "April", "May", _
      "June", "July", "August", "September", "October", "November", "December" )

   d = d & Str( Day(Now) ) & ", " & Str( Year(Now) )
   
   t = ":" & LTrim( Format( Minute(Now), "00" ))
   Select Case Hour(Now)
      Case = 0
         t = "12" & t & "AM "
      Case > 12
         t = Str(Hour(Now) - 12 ) & t & "PM "
      Case Else
         t = Str(Hour(Now)) & t & "AM "
   End Select
   
    oText.insertString( oCursor, t & d, True )
   oCursor.GotoEnd(False)
   oText.insertControlCharacter(oCursor, com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK, True )

End Sub 'OnStartUp


tburcham


Last edited by tburcham on Tue May 06, 2003 6:56 pm; edited 2 times in total
Back to top
View user's profile Send private message
dgermann
OOo Advocate
OOo Advocate


Joined: 17 Mar 2003
Posts: 215

PostPosted: Tue May 06, 2003 6:07 pm    Post subject: Reply with quote

tburcham--

You may call me Doug, if you like.

Thanks for doing all this neat programming for all of us.

Now I think I am going to learn something: there is a small buglet in this somewhere. I ran it three times and here is what I got:

Quote:
9:04 4PM May 6, 2003
9:05 5PM May 6, 2003
9:05 5PM May 6, 2003


Notice it seems to pick up the last digit of the minute two times.

Second question: I must be doing something wrong. It does not run when I start a new default document. Is there something I must do to link it to a document? I did whatever you told me to earlier in the thread....

Sorry to take so long to get back to you....
_________________
:-Doug.
Back to top
View user's profile Send private message
tburcham
General User
General User


Joined: 17 Apr 2003
Posts: 36

PostPosted: Tue May 06, 2003 6:53 pm    Post subject: Thanks for pointing out the bug... Reply with quote

dgermann wrote:
tburcham--
Now I think I am going to learn something: there is a small buglet in this somewhere....


Hi Doug,
Thanks for pointing out the bug. I had left some "junk" in
the code from previous versions. I corrected the code in
the original message.
Quote:


...Second question: I must be doing something wrong. It does not run when I start a new default document. Is there something I must do to link it to a document? I did whatever you told me to earlier in the thread....

I thought you wanted it to run when you opened a
document. Attach it to "Create Document" to have it run
for new one.

(added later)
Actually, I just tried that and it's not working. I'm not sure
why yet. In the mean time you could assign it to a key
combination.


tburcham
Back to top
View user's profile Send private message
dgermann
OOo Advocate
OOo Advocate


Joined: 17 Mar 2003
Posts: 215

PostPosted: Thu May 08, 2003 5:54 pm    Post subject: Reply with quote

tburcham--

OK. Thanks for the new code! And I like the idea of a key combination.

Yes! It works. I even played with it a bit and got some spaces changed, and even a comma inserted.

So where can I learn some very simple basics about this kind of programming? You wanna give some tutorials here? Wink
_________________
:-Doug.
Back to top
View user's profile Send private message
tburcham
General User
General User


Joined: 17 Apr 2003
Posts: 36

PostPosted: Wed May 14, 2003 7:28 pm    Post subject: Re: Basic tutoring Reply with quote

Hi Doug,
First, a note on my previous post: the macro runs now when I start a new
file of any type since I set it to run for all "Create document" events instead
of just that particular one. It will be an annoyance unless it's made to disting-
uish between the types.

OO-Help has fairly thorough coverage of the StarBasic language but, you'll
need to study the SDK for dealing with documents and dialog boxes. If there's
something specific you need help with, I'll see what I can do. I just help people
out occasionally in my spare time, so I can't do that consistently. Judging from
that "buglet" in my code I get far too relaxed when I'm off work Smile.

tburcham
Back to top
View user's profile Send private message
dgermann
OOo Advocate
OOo Advocate


Joined: 17 Mar 2003
Posts: 215

PostPosted: Thu May 15, 2003 6:28 pm    Post subject: Reply with quote

tburcham--

Quote:
OO-Help has fairly thorough coverage of the StarBasic language but, you'll
need to study the SDK for dealing with documents and dialog boxes.
Can't seem to find it in the help. I have entered Basic and some other search terms and nothing seems to give me any language. Any idea what I should enter to find the language help pages? Embarassed

What's SDK? Question

Thanks, tburcham!
_________________
:-Doug.
Back to top
View user's profile Send private message
tburcham
General User
General User


Joined: 17 Apr 2003
Posts: 36

PostPosted: Thu May 15, 2003 9:19 pm    Post subject: ...go to "Help about OpenOffice.org Basic" Reply with quote

Hi Doug,

In the OOO 1.03 Help go to the section named "Help about
OpenOffice.org Basic". It covers the language fairly well.

An "SDK" is a "Software Development Kit". You can
download it from the OOO website
here
It contains all the technical information about accessing
documents etc. It was easier for me to just find example
code for what I needed in OOO's built-in macros though.

tburcham
Back to top
View user's profile Send private message
dgermann
OOo Advocate
OOo Advocate


Joined: 17 Mar 2003
Posts: 215

PostPosted: Mon Jun 02, 2003 7:51 pm    Post subject: Reply with quote

Thanks, tburcham.

You have been a big help!
_________________
:-Doug.
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 Writer All times are GMT - 8 Hours
Goto page Previous  1, 2
Page 2 of 2

 
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