Although I did not verify, I believe that you can use commands such as

Open importfile For Input As #1

That said, although this may work, you should not use #1 directly, but rather, you should use the FreeFile statement (even in Excel)

Dim iNumber As Integer
iNumber = FreeFile
Open importfile For Input As #iNumber
Line Input #iNumber, TextLine


This is a little safer.

Also, You can use the TextInputStream, of course, no problems there. In MSO, this is not a possibility, you are stuck with the Open method as shown above.


I am not certain if the other syntax will work if you enable VBA support, but that is probably not there until version 3.0. if I was more industrious, I would check (since I have the beta installed). when you use Cells(0,0), I assume that this assumes the current sheet... I noticed that in your code, you get a sheet by name rather than obtaining the current sheet. You can emulate this using:

Sheet = Doc.CurrentController.ActiveSheet

The documentation project also has a few documents that deal specifically with macros in Calc documents...

The help files demonstrate how to use most of the Basic built-in commands, but it will not cover items that use the internal OOo objects, such as the FilePicker or SimpleFileAccess.


Phil Hibbs wrote:
I've been trying to learn OOo scripting, and so far I've learned a few
things by finding examples. For instance, to open a text file and read
from it, you have to do something like this:

    FilePickerDlg = createUnoService( "com.sun.star.ui.dialogs.FilePicker" )
    FilePickerDlg.appendFilter( "DSX Files", "*.dsx" )
    selected = FilePickerDlg.execute()
    Files = FilePickerDlg.getFiles()
    FileName = ConvertFromURL( Files(0) )
    Doc = StarDesktop.CurrentComponent
    Sheet = Doc.Sheets.getByName("Control")
    SFA = createUnoService( "com.sun.star.ucb.SimpleFileAccess" )
    InFile = SFA.openFileRead( FileName )
    TextInputStream = createUnoService("com.sun.star.io.TextInputStream")
    TextInputStream.setInputStream(InFile)
    TextLine = TextInputStream.readLine()
    Sheet.getCellByPosition(0, 0).String = TextLine

First of all, that's a lot more complex than in Excel:

    importfile = Application.GetOpenFilename("DSX Files (*.dsx), *.dsx")
    Open importfile For Input As #1
    Line Input #1, TextLine
    Cells(0, 0) = TextLine

Secondly, where am I supposed to find out all that createUnoService
stuff? I could only write the above by spending three evenings
searching the interwebs for examples and asking either here or on a
newsgroup.

I think OOo is great, but I'm really struggling with this. Are any of
the other scripting languages easier to use than OOo Basic?

Phil Hibbs.

--
Andrew Pitonyak
My Macro Document: http://www.pitonyak.org/AndrewMacro.odt
My Book: http://www.hentzenwerke.com/catalog/oome.htm
Info:  http://www.pitonyak.org/oo.php
See Also: http://documentation.openoffice.org/HOW_TO/index.html


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to