如何使用文本文件中的值进行计算
How to use a value from text file to do a calculation
我正在尝试使用存储在我的文本文件中的值进行计算以重置我的 PLC 计数器。以下是我到目前为止所做的。
Dim PileValue_txt As String = "C:\test.txt"
Dim Value As New System.IO.StreamReader(PileValue_txt)
ValueTextbox1.Text = Value.ReadToEnd
Value.Close()
Convert.ToIntCInt32(Value)
LastValue = Value
If 9999 < LastValue Then
CounterValue = 32000 * 1000 'Counter will reset
End if
但是它在 (If 9999 < LastValue)
上引发了异常
Error Message: Operator is not defined for type ‘integer’ and ‘system.io.streamreader’
我的代码有什么问题?
您已将 Value
声明为 StreamReader
并且使用 ReadLine()
方法将内容分配给 ValueTextBox1
。
你必须使用
LastValue = CInt(ValueTextbox1.Text)
而不是
Convert.ToIntCInt32(Value)
LastValue = Value
您可以在Whosebug documentation部分
阅读更多关于阅读文本内容的内容
我正在尝试使用存储在我的文本文件中的值进行计算以重置我的 PLC 计数器。以下是我到目前为止所做的。
Dim PileValue_txt As String = "C:\test.txt"
Dim Value As New System.IO.StreamReader(PileValue_txt)
ValueTextbox1.Text = Value.ReadToEnd
Value.Close()
Convert.ToIntCInt32(Value)
LastValue = Value
If 9999 < LastValue Then
CounterValue = 32000 * 1000 'Counter will reset
End if
但是它在 (If 9999 < LastValue)
Error Message: Operator is not defined for type ‘integer’ and ‘system.io.streamreader’
我的代码有什么问题?
您已将 Value
声明为 StreamReader
并且使用 ReadLine()
方法将内容分配给 ValueTextBox1
。
你必须使用
LastValue = CInt(ValueTextbox1.Text)
而不是
Convert.ToIntCInt32(Value)
LastValue = Value
您可以在Whosebug documentation部分
阅读更多关于阅读文本内容的内容