Página 1 de 1

archivo txt a grid

Publicado: 23 Feb 2014 11:46
por carsonzillo
Hola a todos:

Estoy un poco espeso ya que estoy aprendiendo a manejar un plugin que dede el principio no me interesaba mucho y lo estoy practicando. El problema es que no consigo cargar el archivo txt donde tiene una lista de 378 nombres de mapas para probar como quedaria cargado en el grid.

Intento partir la tabla en bloques de 126 filas en 3 columnas en plan lista haciendo looping con la funcion txt readtotable, y no consigo que se cargue 126 en cada columna (son 3 columnas) se ve vacio. Algun error que me este pasando por alto? porque no me da ningun error....

codigo:
Grid.DeleteNonFixedRows("Grid1", true);

bTXT = File.DoesExist("Autoplay\\Docs\\DM_99.txt"); -- Boolean True or False

if bTXT == true then

	tbTextFile = TextFile.ReadToTable("Autoplay\\Docs\\DM_99.txt")
	nMainTable = Table.Count(tbTextFile)-1; -- counts the number of lines in the text file

	if nMainTable > 0 then--- SI NO DA ERROR DE 0 DATOS....

		-- BLOQUE 1 [1-126]
		for i=1, 126 do
			
			Grid.InsertRow("Grid1", -1, true);			
				for j,sColumnData in pairs (tbTextFile) do
					Grid.SetCellText("Grid1", i, 1, sColumnData, true);
				end
				Grid.ExpandLastColumn("Grid1", true);
		end 
		
		-- BLOQUE 2 [127-252]
		for i=127, 252 do
			
			Grid.InsertRow("Grid1", -1, true);			
				for j,sColumnData in pairs (tbTextFile) do
	
					Grid.SetCellText("Grid1", i, 2, sColumnData, true);
				end
				Grid.ExpandLastColumn("Grid1", true);
		end 
		
		
		-- BLOQUE 3 [253-378]
		for i=253, 378 do
			
			Grid.InsertRow("Grid1", -1, true);			
				for j,sColumnData in pairs (tbTextFile) do
					Grid.SetCellText("Grid1", i, 3, sColumnData, true);
				end
				
				Grid.ExpandLastColumn("Grid1", true);
		end 
		
	else
		Dialog.Message("Notice", "Text File has no data", MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1);
	end 
	
	
	
end 


Grid.DeleteRow("Grid1", 1, true);
Grid.SetColumnWidth("Grid1", 4, 130, true);
Grid.SetColumnWidth("Grid1", 5, 150, true);
Grid.SetToolTipsEnabled("Grid1", true);
Y el apz:

http://www.mediafire.com/download/5j241 ... _lista.apz

Publicado: 23 Feb 2014 12:43
por abood1987
the wrong Code is : :)
		-- BLOQUE 1 [1-126]
		for i=1, 126 do
			
			Grid.InsertRow("Grid1", -1, true);			
				for j,sColumnData in pairs (tbTextFile) do
					Grid.SetCellText("Grid1", i, 1, sColumnData, true);
				end
				Grid.ExpandLastColumn("Grid1", true);
		end 
-----------------

the right Code is : ;)
		-- BLOQUE 1 [1-126]
		for i=1, 126 do			
			Grid.InsertRow("Grid1", -1, true);			
			Grid.SetCellText("Grid1", i-1, 0, tbTextFile[i], true);
			Grid.ExpandLastColumn("Grid1", true);
		end

do that on all looping :yeah:

and Make a Grid Line is Both or Insert all items in One Cell as you Like
and tell me what happened after that :friends:

Publicado: 23 Feb 2014 13:13
por abood1987
Look again to the apz after modification :


HIDE: ON
Hidebb Message Hidden Description



the all Code will be as that :
Grid.DeleteNonFixedRows("Grid1", true);

bTXT = File.DoesExist("Autoplay\\Docs\\DM_99.txt"); -- Boolean True or False

if bTXT == true then

	tbTextFile = TextFile.ReadToTable("Autoplay\\Docs\\DM_99.txt")
	nMainTable = Table.Count(tbTextFile)-1; -- counts the number of lines in the text file

	if nMainTable > 0 then--- SI NO DA ERROR DE 0 DATOS....
		-- BLOQUE 1 [1-126]
		for i=1, 126 do		
		  Grid.InsertRow("Grid1", -1, true);			
		  Grid.SetCellText("Grid1", i-1, 0, tbTextFile[i], true);
		  Grid.ExpandLastColumn("Grid1", true);
		end 		
		-- BLOQUE 2 [127-252]
		for i=127, 252 do	
		  Grid.SetCellText("Grid1", i-127, 1, tbTextFile[i], true);
		  Grid.ExpandLastColumn("Grid1", true);
		end 				
		-- BLOQUE 3 [253-378]
		for i=253, 287 do
		  Grid.SetCellText("Grid1", i-253, 2, tbTextFile[i], true);
		  Grid.ExpandLastColumn("Grid1", true);
		end 		
	else
		Dialog.Message("Notice", "Text File has no data", MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1);
	end 			
end 
Grid.DeleteRow("Grid1", 1, true);
Grid.SetColumnWidth("Grid1", 4, 130, true);
Grid.SetColumnWidth("Grid1", 5, 150, true);
Grid.SetToolTipsEnabled("Grid1", true);

and remember you are Put an 287 line on the text file not 378 on your example :)

Publicado: 23 Feb 2014 13:41
por carsonzillo
Lol I dont sleep a lot lately im dumb mode on lol

I did not know that column must begin in Zero? LOl I was like what the ...
As for lines in amount in the txt file same I did not count correctly how many lines do the txt have lol

A question: why did you put the tbTextFile instead to use the string converted from item table if is the same data O.o?

Thanks for the heads up mate!

EDITED: ok I got it you put the comment -- symbol to not needed code lol thanks

Publicado: 23 Feb 2014 13:57
por carsonzillo
code corrected thanks to abood to enlighten me lol:
Grid.DeleteNonFixedRows("Grid1", true);

bTXT = File.DoesExist("Autoplay\\Docs\\DM_99.txt"); -- Boolean True or False

if bTXT == true then

        tbTextFile = TextFile.ReadToTable("Autoplay\\Docs\\DM_99.txt")
        nMainTable = Table.Count(tbTextFile)-1; -- counts the number of lines in the text file

        if nMainTable > 0 then--- SI NO DA ERROR DE 0 DATOS....
                -- BLOQUE 1 [1-126]
                for i=1, 126 do         
                  Grid.InsertRow("Grid1", -1, true);                    
                  Grid.SetCellText("Grid1", i-1, 0, tbTextFile[i], true);
                  Grid.ExpandLastColumn("Grid1", true);
                end             
                -- BLOQUE 2 [127-252]
                for i=127, 252 do       
                  Grid.SetCellText("Grid1", i-127, 1, tbTextFile[i], true);
                  Grid.ExpandLastColumn("Grid1", true);
                end                             
                -- BLOQUE 3 [253-287]
                for i=253, 287 do
                  Grid.SetCellText("Grid1", i-253, 2, tbTextFile[i], true);
                  Grid.ExpandLastColumn("Grid1", true);
                end             
        else
                Dialog.Message("Notice", "Text File has no data", MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1);
        end                     
end 

for ncol=0, 2 do

Grid.DeleteRow("Grid1", 1, true);
Grid.SetColumnWidth("Grid1", ncol, 200, true);
Grid.SetToolTipsEnabled("Grid1", true);
end

Re:

Publicado: 23 Feb 2014 14:56
por abood1987
carsonzillo escribió: A question: why did you put the tbTextFile instead to use the string converted from item table if is the same data O.o?


:pc: if you used the loop for i=1, ....... do ....... then you can used above Code ;)



:pc: if you used the loop for j,sColumnData in pairs (tbTextFile) do ...... then you can used following Code :

Grid.DeleteNonFixedRows("Grid1", true);
bTXT = File.DoesExist("Autoplay\\Docs\\DM_99.txt"); -- Boolean True or False
if bTXT == true then
	tbTextFile = TextFile.ReadToTable("Autoplay\\Docs\\DM_99.txt")
	nMainTable = Table.Count(tbTextFile)-1; -- counts the number of lines in the text file
	if nMainTable > 0 then--- SI NO DA ERROR DE 0 DATOS....
       for j,sColumnData in pairs (tbTextFile) do
         if j>=1 and j<=126 then
           Grid.InsertRow("Grid1", -1, true);
           Grid.SetCellText("Grid1", j-1, 0, sColumnData, true);
          elseif j>=127 and j<=252 then
            Grid.SetCellText("Grid1", j-127, 1, sColumnData, true);   
            if j>=153 and j<=287 then
              Grid.SetCellText("Grid1", j-153, 2, sColumnData, true);
            end
            Grid.ExpandLastColumn("Grid1", true);
         end
       end
	 else
		Dialog.Message("Notice", "Text File has no data", MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1);
	end 			
end 
Grid.DeleteRow("Grid1", 1, true);
Grid.SetColumnWidth("Grid1", 4, 130, true);
Grid.SetColumnWidth("Grid1", 5, 150, true);
Grid.SetToolTipsEnabled("Grid1", true);

Good Luck .............. :friends:

Re: archivo txt a grid

Publicado: 23 Feb 2014 20:23
por Pabloko
Grid pude tomar datos de un archivo CSV separado por comas y saltos de linea
dato1,dato2,dato3
dato4,dato5,dato6

Publicado: 24 Feb 2014 20:27
por carsonzillo
pues si pabloko no cai en la cuenta lol
gracias a los 2

Publicado: 26 Feb 2014 19:19
por tam
thanks

Publicado: 28 Mar 2014 02:59
por a.miguel
interesante

Publicado: 26 Sep 2014 00:20
por comprotodo201480
esta bien, revisando el link