Language Selection

English French German Italian Portuguese Spanish

OOoBasic crash course: Working with files

Filed under
HowTos

OpenOffice.org's OOoBasic gives users tools to programmatically access and manipulate files. To see how that works, we'll create a simple macro that allows you to save text snippets from the current document in a plain text file. This macro can be used to store text fragments from multiple documents in one text file, or to save deleted passages in an external file in case you need them later.

To build this macro, you can reuse the component that grabs the selected text fragment in the current document. If you've followed the previous installments of the OOoBasic crash course series on creating a lookup macro and working with words, the following code will look familiar:

Sub WriteFile()
Dim oDoc As Object, oText As Object
Dim oCursor As Object
Dim sFileName As String
oDoc=ThisComponent
oText=oDoc.Text
oCursor=oDoc.CurrentController.getViewCursor
If oCursor.String ="" then MsgBox "Please select a word to look up" : End

Notice the sFileName variable, defined as string. This variable points to the file for use in the macro. To specify the file you want, use the following code:

Full Story.

More in Tux Machines

Android Leftovers

GNOME 3.28 Linux Desktop Environment Development Kicks Off with First Snapshot

GNOME developer Javier Jardón is kicking off the development of the GNOME 3.28 desktop environment with the first snapshot, GNOME 3.27.1, which is now available for public testing. Read more

How to manage casual contributors to open source projects

Increasingly, people want to contribute to projects casually—when they want to, rather than adhering to a schedule. This is part of a broader trend of "episodic volunteering" noted by a wide range of volunteer organizations and governments. This has been attributed not only to changes in the workforce, which leave fewer people able to volunteer with less spare time to share, but also to changes in how people perceive the act of volunteering. It is no longer seen as a communal obligation, rather as a conditional activity in which the volunteer also receives benefits. Moreover, distributed revision-control systems and the network effects of GitHub, which standardize the process of making a contribution, make it easier for people to contribute casually to free/libre/open source software (FLOSS) projects. Read more

5 ways to invigorate education with Raspberry Pi

A couple of years ago, I was talking to PayPal senior director of software development Harper Reed at All Things Open in Raleigh, N.C., when he suggested that the best way to invigorate education would be to purchase Raspberry Pis en masse and put them in public libraries. Although many schools have made sizeable investments in classroom technology, those investments have done little to advance students' understanding of how the technology works. That's where the Raspberry Pi comes in, as it's the ideal vehicle to demonstrate the educational efficacy of open source software and open hardware in the classroom. Read more