[Solved] Calc get value from txt

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
Nelomf
Posts: 22
Joined: Wed Nov 06, 2019 4:29 pm

[Solved] Calc get value from txt

Post by Nelomf »

Hello

I've grab a code in this forum to get a striung value from txt file to a calc cell.
The code works well but its constantly fetching the value and i only need to get the value once when opening the calc book.
Could you hep me modifying this code please.

This is the code

Code: Select all

Dim iRun As Integer
iRun =1
While iRun =1
Dim iNumber As Integer
Dim delay As Integer 'delay between updates
Dim sLine As String
Dim aFile As String
Dim update As String
Dim oSheet : oSheet = ThisComponent.Sheets.getByIndex(1)
'Index 0 is Sheet1, Index 1 is Sheet2, etc.
Dim oCell : oCell = oSheet.getCellByPosition(1,0)
'Both row and column indexes start with 0: A1 is 0,0 - A2 is 1,0 - B1 is 0,1
Dim iCell : iCell = oSheet.getCellByPosition(0,1)
delay = 5000
iCell.setString(" ")
wait delay 'wait duration
aFile = "c:\encomendas\Bar.txt"
iNumber = Freefile
Open aFile For Input As iNumber
While not eof(iNumber)
Line Input #iNumber, sLine
If sLine <>"" then

end if
wend
Close #iNumber

oCell.setString(sLine)
rem iCell.setString("*Updating*")
rem wait delay ' Wait duration
Wend
Many Thanks
Last edited by Nelomf on Fri Apr 16, 2021 4:09 pm, edited 2 times in total.
Openoffice 4, Windows 7
cwolan
Posts: 129
Joined: Sun Feb 07, 2021 3:44 pm

Re: Calc get value from txt

Post by cwolan »

The code works well but its constantly fetching the value and i only need to get the value once when opening the calc book.
Then get rid of the outer loop.

Code: Select all

While iRun =1 

Wend
Comment or remove those two lines.
You may also consider whether you do need others lines related to updating.
OpenOffice 1.1.5 – 4.1.15
LibreOffice 6.4.7 – 7.6.5
Windows 7,10,11 64-bit
Nelomf
Posts: 22
Joined: Wed Nov 06, 2019 4:29 pm

Re: Calc get value from txt

Post by Nelomf »

Thank's

Yes i will get rid of the "updating", what i didn't know was the loop.

Manuel
Openoffice 4, Windows 7
Post Reply