Page 1 of 1

[Solved] Calc get value from txt

Posted: Fri Apr 16, 2021 12:14 pm
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

Re: Calc get value from txt

Posted: Fri Apr 16, 2021 3:00 pm
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.

Re: Calc get value from txt

Posted: Fri Apr 16, 2021 4:09 pm
by Nelomf
Thank's

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

Manuel