2
I’m trying to put the items in positions of a matrix, but I keep getting the error that the variable is outside the matrix limits. I don’t know how to fix the mistake and I need help.
Follows the code:
Dim posicao As String = String.Join("", itens)
Dim separa As String()
Dim contagem As String
contagem = ListBox1.Items.Count
Dim i As Integer
For i = 0 To contagem
separa = Split(posicao, ";")
cpf = separa(0)
nome = separa(1) 'O erro ocorre aqui.
anonasc = separa(2)
Next
TextBox1.Items.Add(cpf & ";" & nome & ";" & anonasc)
The program does not point out code errors. I am analyzing the variable items, which receives lines from a file . txt.
The local_file variable takes the . Filename of an Openfiledialog.
Variable itens
:
Dim local_arquivo As String
itens = (My.Computer.FileSystem.ReadAllText(local_arquivo, System.Text.Encoding.Default)).Replace(vbLf, String.Empty).Split((CChar(vbCr)))
ListBox1.Items.AddRange(itens)
It would be good to put what is the error and where it occurs, what is the data being analyzed (
itens
andListBox1.Items
), etc..– Maniero
All right, I added.
– Catharina Lopes
But what is the content of
itens
?– Maniero
Corrected above.
– Catharina Lopes
I’m talking about the content, not its definition. I’m going to try to respond the way it does.
– Maniero
The content will depend on what is in the file that the user selects.
– Catharina Lopes
Yes, and this is what I want to know to see why the error occurs.
– Maniero
There are three Cpfs, followed by names and year of birth. They are just examples. They are separated by the character ;. 000.000.000-00;Maria da Silva;1995 111.111-11;José de Souza;2005 222.222.222-22;João Antônio;1945
– Catharina Lopes
They are separated by a ENTER, which did not appear when posting the comment.
– Catharina Lopes
Did you notice that the syntax of
Split
is wrong? You saw in my answer the code working?– Maniero
Did any of the answers solve your problem? Do you think you can accept one of them? If you haven’t already, see [tour] how to do this. You would help the community by identifying the best solution for you. You can only accept one of them, but you can vote for any question or answer you find useful on the entire site (if you have enough score).
– Maniero