嗨,我想讀取一個數組,但我得到這個錯誤:數組邊界不能出現在類型說明符中,我想獲取數組數據以使對象在行Dim用戶作爲USUARIOS(行(0)).....數組邊界不能出現在類型說明符中
Try
Dim filePath As String
filePath = System.IO.Path.Combine(
My.Computer.FileSystem.SpecialDirectories.MyDocuments, "Clients.txt")
Dim fileReader As System.IO.StreamReader
fileReader = My.Computer.FileSystem.OpenTextFileReader(filePath)
While fileReader.EndOfStream <> True
Dim line As String = fileReader.ReadLine
Dim lineSplit As String() = line.Split("/")
Dim user As Usuarios(line(0))
ComboBox1.Items.Add(line)
MsgBox(line)
End While
Catch ex As Exception
MsgBox("Error, file not found Clientes.txt")
End Try
當前類
Public Class Usuarios
Private _nombre As String
Private _erApellido As String
Private _onApellido As String
Private _Dni As String
Private _movil As Integer
Private _direccion As String
'Private _fecha As Date
'Constructor
Public Sub New(ByVal Nombre As String, ByVal erApellido As String,
ByVal onApellido As String, ByVal Dni As String,
ByVal tel As Integer, ByVal direccion As String)
Me._nombre = Nombre
Me._erApellido = erApellido
Me._onApellido = onApellido
Me._Dni = Dni
Me._movil = tel
Me._direccion = direccion
'Me._fecha = fecha
End Sub
'Getters y Setters
Public Property Nombre() As String
Get
Return _nombre
End Get
Set(ByVal Value As String)
_nombre = Value
End Set
End Property
Public Property erApellido() As String
Get
Return _erApellido
End Get
Set(ByVal Value As String)
_erApellido = Value
End Set
End Property
Public Property onApellido() As String
Get
Return _onApellido
End Get
Set(ByVal Value As String)
_onApellido = Value
End Set
End Property
Public Property Dni() As String
Get
Return _Dni
End Get
Set(ByVal Value As String)
_Dni = Value
End Set
End Property
Public Property Movil() As Integer
Get
Return _movil
End Get
Set(ByVal Value As Integer)
_movil = Value
End Set
End Property
Public Overrides Function ToString() As String
Return String.Format(Me._Dni + "/" + Me._nombre + "/" + Me._erApellido + "/" + Me._onApellido + "/" + String.Format(Me._movil))
End Function
End Class
電流.txt格式名稱/姓/ .... 我的目標,分割包含的信息在.txt上並使用戶對象保存在數組列表中。
parens表明你希望'Usarios'是一個數組,因爲'line'是一個字符串,它沒有多大意義:'Dim user As Usuarios(「Bob/Jones」)'唯一的數組有'lineSplit '。是'Usuarios'類型(類)? – Plutonix
我想得到分裂的信息,使用戶...唯一的辦法是暗arr作爲字符串= {「」.....} – Icaro
好吧,我會猜測然後....你*可能*想要: Dim user as New Usuarios(lineSplit(0))''。 'usr'將只存在於該塊中 - 對象只存在於聲明它們的地方。你也應該打開選項嚴格 – Plutonix