Reading a text file and passing to a Function
Hi All,
Hopefully a quick question,
Im trying to read a number from a text file and pass it to a function.
The "ScanItem" function i am trying to pass the textfile data to already works fine in tests and is below.
However currently it relies on specifying the value to read in in the script.
I would like to pass in the numerics into the scanitem as read from the text file.
Do I need to look at pointers or anything?
Any examples would be a great help.
Thanks for your time!
Pre exisiting ScanItem function
===============================
Sub ScanItem(NUM)
Call Delay(350)
Dim SerialPort, Port, BaudRate, Parity, DataBits, StopBits
Port = "COM11"
BaudRate = 9600
Parity = None
DataBits = 8
StopBits = 1
Call Delay(250)
Set SerialPort = dotNet.System_IO_Ports.SerialPort.zctor(Port, BaudRate, Parity, DataBits, StopBits)
SerialPort.Open
SerialPort.Write NUM & Chr(13)
SerialPort.Close
End Sub
What Ive tried
========================
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Dim fso, MyFile, FileName, TextLine
Set fso = CreateObject("Scripting.FileSystemObject")
' Open the file for output.
FileName = "c:\temp\textfile1.txt"
Set MyFile = fso.OpenTextFile(FileName, ForWriting, True)
' Open the file for input.
Set MyFile = fso.OpenTextFile(FileName, ForReading)
' Read from the file and display the results.
Do While MyFile.AtEndOfStream <> True
TextLine = MyFile.ReadLine
'Document.Write TextLine & "<br />"
Loop
MyFile.Close
ScanItem (TextLine)
Hi,
If that is the case, you can do like below
function test() { ScanItem(getTextFromFile(<filepath>)) } function getTextFromFile(filepath) { if(filepath != null) { try { return aqFile.ReadWholeTextFile(filepath,20); } catch(e) { Log.Error(ex.stack); } } return null; }