[Solved] Calc get value from txt

Creating a macro - Writing a Script - Using the API

[Solved] Calc get value from txt

Postby Nelomf » Fri Apr 16, 2021 12:14 pm

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   Expand viewCollapse view
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
Nelomf
 
Posts: 22
Joined: Wed Nov 06, 2019 4:29 pm

Re: Calc get value from txt

Postby cwolan » Fri Apr 16, 2021 3:00 pm

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   Expand viewCollapse view
While iRun =1

Wend

Comment or remove those two lines.
You may also consider whether you do need others lines related to updating.
OpenOffice 4.1.10, LibreOffice 7.1.5.2
Windows 7 64-bit
cwolan
 
Posts: 12
Joined: Sun Feb 07, 2021 3:44 pm

Re: Calc get value from txt

Postby Nelomf » Fri Apr 16, 2021 4:09 pm

Thank's

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

Manuel
Openoffice 4, Windows 7
Nelomf
 
Posts: 22
Joined: Wed Nov 06, 2019 4:29 pm


Return to Macros and UNO API

Who is online

Users browsing this forum: Google [Bot] and 7 guests