Ask Your Question
0

LO on Linux Mint: Macro working in OO no longer works

asked 2019-11-09 23:19:26 +0100

MaxG gravatar image

updated 2019-11-10 01:37:48 +0100

Six weeks ago I migrated from Windows 10 to Linux Miint. I was using OpenOffice on Windows, and am now using LibreOffice on Mint. One file has a macro to import updated records from a text file on another Linux machine into Calc. This macro no longer works. The other machine (rpi32) is 'mapped' as:

# [2019-11-10 07:37] maxg@maxg-pc-mint ~ $ 
la /home/maxg/rpi32/sppro/
total 32
drwxr-xr-x 2 1001 1001 4096 Jun 25 21:11 .
drwxr-xr-x 6 1001 1001 4096 Aug  4 11:33 ..
-rwx------ 1 1001 1001 7531 Nov 10 02:02 PowerFlowSummaryLog.txt

The text file is listed above (PowerFlowSummaryLog.txt)

The macro is:

Sub DataFromFile
  ' reading txt, and adding lines not in the spreadhseet into first/next empty row
  ' all indexes start at zero
  ' 
  ' 190120 MaxG v1.1 - clean-up and documentation
  ' 190120 MaxG v1.0 - added: write all missing TXT records to next empty spreadsheet rows
  ' 190119 MaxG v0.2 - added: write array for last TXT row
  ' 190118 MaxG v0.1 - PoC; read TXT, write raw line

  ' establish environment
  myWorkBook   = ThisComponent
  'targetSheet  = myWorkBook.Sheets(3)   ' 3 = sheet 4
  targetSheet  = myWorkBook.Sheets.getByName("PowerFlow")
  targetColumn = targetSheet.Columns(0) ' column A
  sourceText   = FreeFile

  Select Case getGUIType
    Case 1: sourceFile = convertToURL("\\RPI32\maxg\sppro\PowerFlowSummaryLog.txt")
    case 4: sourceFile = convertToURL("/home/maxg/sppro/PowerFlowSummaryLog.txt")
  End Select


  Dim eRgs  As Object                  ' ?
  Dim u     As Integer                 ' ?

  eRgs = targetColumn.queryEmptyCells  ' get empty cells
  u    = eRgs.Count - 1                ' u seems to be always 0; why?

  ' catch error: if no rows left, and exit program
  If u < 0 Then 
    MsgBox("No empty row in column.")
    Exit Sub
  End If

  Dim getFirstEmptyRow As Integer      ' in spreadsheet
  Dim lastNonEmptyRow  As Integer      ' in spreadsheet

  ' determine the first empty row in column
  getFirstEmptyRowInColumn = Split(eRgs.RowDescriptions(0), " ")

  ' extract first empty row
  firstEmptyRow = cInt(getFirstEmptyRowInColumn(1)) - 1

  ' set last non-empty row
  lastNonEmptyRow = firstEmptyRow - 1

  Dim oLastSheetDate   As Object       ' object last date in the spreadsheet
  Dim lastSheetDate    As Date         ' last date in the spreadsheet
  Dim rowAdanceCounter As Integer      ' row advance counter; to increment row position by one per date
  Dim txtDate          As Date         ' date from row in text file

  ' get the last date from the sheet
  oLastSheetDate = targetSheet.getCellByPosition(0, lastNonEmptyRow)
  'MsgBox "oLastSheetDate | row=" & oLastSheetDate.getValue & " | " & lastNonEmptyRow + 1

  lastSheetDate = oLastSheetDate.getValue
  rowAdanceCounter = 0                 ' init to 0, increment in import loop

  Open sourceFile For Input As sourceText

  ' go through source text file line by line until EOF
  While Not EOF(sourceText)
    ' get one line at a time
    Line Input #sourceText, currentLine

    ' turn text values delimited by TAB into an array
    arrCurrentLine = Split(currentLine, Chr(9))

    ' get date of line
    txtDate = arrCurrentLine(0)
    'MsgBox "txtDate=" & txtDate

    If txtDate > lastSheetDate Then
      ' now put data into the spreadsheet
      'MsgBox "txtDate > lastSheetDate -> row to add"

      Dim numItems As Integer          ' number of array items
      Dim cell As Object               ' cell to work with
      Dim i As Integer                 ' foor loop counter

      i = 0
      numItems = Ubound(arrCurrentLine)

      ' run through the text line array and place one value in cells moving ...
(more)
edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted
1

answered 2019-11-09 23:55:09 +0100

Opaque gravatar image

updated 2019-11-10 00:04:51 +0100

Hello

your list commands shows path: /home/maxg/rpi32/sppro/

while your case statement doesn't contain ../rpi32/..
case 4: sourceFile = convertToURL("/home/maxg/sppro/PowerFlowSummaryLog.txt")

and thus should probably read:
case 4: sourceFile = convertToURL("/home/maxg/rpi32/sppro/PowerFlowSummaryLog.txt")
to find the sourceFile

Hope that helps

If the answer is correct or helped you to solve your problem, please click the check mark (✔) next to the answer.

edit flag offensive delete link more
2

answered 2019-11-10 01:35:24 +0100

MaxG gravatar image

updated 2019-11-10 01:36:33 +0100

Ouch, this hurts... I corrected the missing path part... ... and tried again to no avail. Then I thought why not open that source file directly?!

So I did and got this: image description

... which points to a file permission problem... looking into it... ... fixed!

Now all is working as designed.

Thanks :)

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2019-11-09 23:19:26 +0100

Seen: 37 times

Last updated: Nov 10