当我将代码带入另一个项目时,我收到了错误。在一个空白的项目中它工作正常,我真的不知道如何绕过它,这是错误
错误1' System.Data.Index'在这种情况下无法访问,因为它是“朋友”。
Dim DataString As String = txtAdvancedCommand.Text
' Create an array containing from each letter in Textbox
Dim charArray() As Char = DataString.ToCharArray
For index = 0 To charArray.GetUpperBound(0) <-----ERROR on word index
Try
'Now lets send the data
If SerialPort.IsOpen Then
SerialPort.Write(charArray(index) & vbCrLf) <-----ERROR on word index
Else
ConnectSerial()
SerialPort.Write(charArray(index) & vbCrLf) <-----ERROR on word index
End If
Catch e As Exception
txtLog.AppendText(e.Message & vbCrLf)
End Try
Next
现在我带来的项目有一个DLL,我怀疑它与它有关,我无法获取DLL的源代码,所以有另一种解决方法吗?
答案 0 :(得分:0)
尝试:
For index As Integer= 0 To charArray.GetUpperBound(0)
或更好
For index As Integer= 0 To charArray.Length
或更好
Dim DataString As String = txtAdvancedCommand.Text
' Create an array containing from each letter in Textbox
Dim charArray As String() = Array.ConvertAll(DataString.ToCharArray(), Function(c) c.ToString())
Dim output As String = String.Join(vbCrLf, charArray)
If Not SerialPort.IsOpen Then
ConnectSerial()
End If
SerialPort.Write(output)