Quote from JoaquinFDEZ on May 9, 2020, 6:44 pmHi all.
I have a new problem with retrieve data from a txt file and save it to an arrays .
I show you the example so that you have an idea.
Spanish: Gracias a otros ejemplos que habeís subido he aprendido a recuperar datos de un archivo txt a un listbox, cuando he querido hacer lo mismo con arrays me encuentro con dificultades y me gustaría que vierais mi ejemplo para darme una posible solución. gracias.
Sorry, I can´t upload the txt file. Its would be your data
datafile: data.txt
items: Name1,valorA1,valorB1,Name2,valorA2,valorB2,Name3,valorA3,valorB3,Name4,valorA4,ValorB4,Name5,valorA5,ValorB5
Nota: Upload files son : loadfiletxt-to-arrays
Hi all.
I have a new problem with retrieve data from a txt file and save it to an arrays .
I show you the example so that you have an idea.
Spanish: Gracias a otros ejemplos que habeís subido he aprendido a recuperar datos de un archivo txt a un listbox, cuando he querido hacer lo mismo con arrays me encuentro con dificultades y me gustaría que vierais mi ejemplo para darme una posible solución. gracias.
Sorry, I can´t upload the txt file. Its would be your data
datafile: data.txt
items: Name1,valorA1,valorB1,Name2,valorA2,valorB2,Name3,valorA3,valorB3,Name4,valorA4,ValorB4,Name5,valorA5,ValorB5
Nota: Upload files son : loadfiletxt-to-arrays
Uploaded files:Quote from Gaev on May 9, 2020, 8:29 pm@joaquinfdez
Since the populating of ListBox1 works, I will address the rest of your code ... instead of setting up and loading the data file into [myvar], my code below just populates this variable via a SetVar command.
The problem with your technique for attempting to create arrays using ...
- 1st, 4th, 7th etc. items
- 2nd, 5th, 8th etc. items
- 3rd, 6th, 9th etc. items... is in how you loop through the items ... with your way, with 15 items, the loop has 15 iterations (0 to 14) ... and you are asking for ...
math "[x]*3" 0 [p]
... which can be as high as 42 ... but [myarray] only contains 15 items.
Study this code ...
CreateEmptyArray [rec] CreateEmptyArray [rec1] CreateEmptyArray [rec2] SetVar "[myvar]" "Name1,valorA1,valorB1,Name2,valorA2,valorB2,Name3,valorA3,valorB3,Name4,valorA4,ValorB4,Name5,valorA5,ValorB5" StrParse "[myvar]" "," [myarray] ArrayLen [myarray] [totalitems] Math "[totalitems]/3" "0" "[p]" SetVar [totalitems] [totalitems]-1 Loop 0 [totalitems] [n] ListBoxAddItem "Listbox1" "[myarray([n])]" "[myarray([n])]" EndLoop ListBoxDeleteItem "Listbox1" 1 .... Guarda en el array rec solo los valores Name1,Name2.......Name5 saltando de 3 en 3 loop 0 [p] [x] math "[x]*3" 0 [n] ArrayAddItem "rec" "[myarray([n])]" endloop .Modificando loop para empezar desde 1 Guarda en el array rec1 solo los valores ValorA1,ValorA2,ValorA3...ValorA5 loop 0 [p] [x] math "([x]*3)+1" 0 [n] ArrayAddItem "rec1" "[myarray([n])]" endloop .Modificando loop para empezar desde 2 Guarda en el array rec2 solo los valores ValorB1,ValorB2,ValorB3...ValorB5 loop 0 [p] [x] math "([x]*3)+2" 0 [n] ArrayAddItem "rec2" "[myarray([n])]" endloop... and then adapt it into you button code which populates the array from a file (instead of a SetVar)
Since the populating of ListBox1 works, I will address the rest of your code ... instead of setting up and loading the data file into [myvar], my code below just populates this variable via a SetVar command.
The problem with your technique for attempting to create arrays using ...
- 1st, 4th, 7th etc. items
- 2nd, 5th, 8th etc. items
- 3rd, 6th, 9th etc. items
... is in how you loop through the items ... with your way, with 15 items, the loop has 15 iterations (0 to 14) ... and you are asking for ...
math "[x]*3" 0 [p]
... which can be as high as 42 ... but [myarray] only contains 15 items.
Study this code ...
CreateEmptyArray [rec] CreateEmptyArray [rec1] CreateEmptyArray [rec2] SetVar "[myvar]" "Name1,valorA1,valorB1,Name2,valorA2,valorB2,Name3,valorA3,valorB3,Name4,valorA4,ValorB4,Name5,valorA5,ValorB5" StrParse "[myvar]" "," [myarray] ArrayLen [myarray] [totalitems] Math "[totalitems]/3" "0" "[p]" SetVar [totalitems] [totalitems]-1 Loop 0 [totalitems] [n] ListBoxAddItem "Listbox1" "[myarray([n])]" "[myarray([n])]" EndLoop ListBoxDeleteItem "Listbox1" 1 .... Guarda en el array rec solo los valores Name1,Name2.......Name5 saltando de 3 en 3 loop 0 [p] [x] math "[x]*3" 0 [n] ArrayAddItem "rec" "[myarray([n])]" endloop .Modificando loop para empezar desde 1 Guarda en el array rec1 solo los valores ValorA1,ValorA2,ValorA3...ValorA5 loop 0 [p] [x] math "([x]*3)+1" 0 [n] ArrayAddItem "rec1" "[myarray([n])]" endloop .Modificando loop para empezar desde 2 Guarda en el array rec2 solo los valores ValorB1,ValorB2,ValorB3...ValorB5 loop 0 [p] [x] math "([x]*3)+2" 0 [n] ArrayAddItem "rec2" "[myarray([n])]" endloop
... and then adapt it into you button code which populates the array from a file (instead of a SetVar)
Quote from JoaquinFDEZ on May 9, 2020, 9:14 pmOk !! Thanks @gaev I understand now. I´m very grateful to you
Ok !! Thanks @gaev I understand now. I´m very grateful to you

Quote from luishp on May 10, 2020, 10:41 am@joaquinfdez adjunto tu ejercicio corregido. No había visto que @gaev habia aportado su solución ya. Fíjate que es importante asignar una variable al ListBox o generará un error. Tampoco es necesario utilizar ya ListBoxAddItem (simplemente asígnale un array al ListBox). Los Loops los he simplificado también.
Cualquier duda, me dices.
Saludos!
@joaquinfdez adjunto tu ejercicio corregido. No había visto que @gaev habia aportado su solución ya. Fíjate que es importante asignar una variable al ListBox o generará un error. Tampoco es necesario utilizar ya ListBoxAddItem (simplemente asígnale un array al ListBox). Los Loops los he simplificado también.
Cualquier duda, me dices.
Saludos!
Uploaded files:Quote from JoaquinFDEZ on May 10, 2020, 11:03 amOk una vez más mil gracias a ti también @luishp.
Lo estudiaré e intentaré asimilar conceptos para no marearos mucho. :-)
Ok una vez más mil gracias a ti también @luishp.
Lo estudiaré e intentaré asimilar conceptos para no marearos mucho. :-)