<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title># ivirtual networks &#187; persistencia</title>
	<atom:link href="http://www.informaticavirtual.us/tag/persistencia/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.informaticavirtual.us</link>
	<description>w3: informaticavirtual us</description>
	<lastBuildDate>Fri, 05 Mar 2010 03:19:59 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Des-serializar archivos de texto en Visual Basic .Net</title>
		<link>http://www.informaticavirtual.us/2009/12/11/des-serializar-archivos-de-texto-en-visual-basic-net/</link>
		<comments>http://www.informaticavirtual.us/2009/12/11/des-serializar-archivos-de-texto-en-visual-basic-net/#comments</comments>
		<pubDate>Fri, 11 Dec 2009 02:19:27 +0000</pubDate>
		<dc:creator>Bony</dc:creator>
				<category><![CDATA[# libs []]]></category>
		<category><![CDATA[VB [dot]Net]]></category>
		<category><![CDATA[des-serializacion]]></category>
		<category><![CDATA[persistencia]]></category>
		<category><![CDATA[serializacion]]></category>

		<guid isPermaLink="false">http://www.informaticavirtual.us/?p=34</guid>
		<description><![CDATA[El otro dia en el instituto al que voy a estudiar, el profesor estaba dictando una clase de como usar persistencia con archivos de texto, asi como ya habiamos dado como usarla con archivos binarios, y archivos XML.
Como muchos saben, Visual Basic ofrece muchas funciones, que la mayoria de las veces son buenas para salir [...]]]></description>
			<content:encoded><![CDATA[<p>El otro dia en el instituto al que voy a estudiar, el profesor estaba dictando una clase de como usar persistencia con archivos de texto, asi como ya habiamos dado como usarla con archivos binarios, y archivos XML.</p>
<p>Como muchos saben, Visual Basic ofrece muchas funciones, que la mayoria de las veces son buenas para salir del apuro, o del estress, no se si ustedes han programando en VB .Net, pero les digo.. que es algo que a veces es un lenguaje muy facil, y basico.. con muchas funciones predeterminadas, que no ayudan para nada a crecer como programador, ya que nos quita logica al programa y logica a nuestros cerebros que tendrian que ser los que tendrian que estar pensando la logica de cada funcion, como hacer esto, y como hacer lo otro.</p>
<p>Esto me vino a la cabeza, cuando yo, muy emocionado.. porque el profesor habia dicho que ibamos a usar archivos de texto, y teniamos que levantar datos de un archivo de texto que por ejemplo tuviera los datos asi:</p>
<blockquote><p>datoDelusuario1-datoDelusuario1-datoDelusuario1<br />
datoDelusuario2-datoDelusuario2-datoDelusuario2<br />
datoDelusuario3-datoDelusuario3-datoDelusuario3<br />
datoDelusuario4-datoDelusuario4-datoDelusuario4</p></blockquote>
<p><span id="more-34"></span><br />
Y asi sucesivamente, me brillaron los ojos, dije: &#8220;Si! vamos a hacer funciones de las grosas&#8221;, mientras pensaba todo, muy ilusionado, el profesor.. se pone a escribir en el pizarron como hacerlo&#8230; fueron unas 10 lineas (no mas, seguramente) y ya estaba todo hecho, no necesitabamos ni pensarlo&#8230;</p>
<p>Pero! con la emocion que tenia encima, y aunque el profesor siguiera dictando la clase, fui pensando como hacer el serializador, y luego, cuando pense postearlo en el blog, fue cuando me decidi a hacerlo, y tratar de compartir un poco mis conocimientos de programacion, use alguna que otra funcion predeterminada de Visual Basic, en fin.. no todos somos perfectos, lo que mas me importa es que intenten entender la logica del des-serializador, y tratar de que entiendan como formatearlos para que queden lo mas parecidos a tablas.</p>
<p>Ok, manos a la obra, lo primero, cada dato no tiene mas longitud que 20 caracteres (esto supuestamente lo definimos en el programa con el que creamos el archivo de texto base, el mio se parece a esto:</p>
<blockquote><p>Maltray*2546889*matias.a18@gmail.com<br />
mnosh*55668997788*mnox@gmail.com<br />
bony*455568899*bony@gmail.com<br />
usuario5*contraseña5*mail5@gmail.com</p></blockquote>
<p>Donde * es el caracter separador y la secuencia de datos esta dada asi: usuario*contraseña*email.</p>
<p>Ok, nuestra meta es que el archivo destino, al que le podemos poner cualquier nombre que nosotros quieramos, quede de esta manera:</p>
<p>Maltray             456456456                matias.a18@gmail.com<br />
Mnosh               45645646465            mnosh@gmail.com<br />
&#8230;</p>
<p>Obviamente, mas formateado, vamos a tratar de hacer lo que puedamos con nuestros querios archivos .txt.</p>
<p>Asi que aqui vamos, primero voy a presentarles el modulo, en donde se piden 3 datos:</p>
<ul>
<li>Archivo serializado (ej: D:\Archivo.txt)</li>
<li>Caracter separador (Solo un caracter)</li>
<li>Archivo destino (ej: archivoDesserializado.txt)</li>
</ul>
<div class="codecolorer-container vbnet vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:800px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br /></div></td><td><div class="vbnet codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0600FF;">Sub</span> Main<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">'Declaramos las variables que usaremos..</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">'@rutaArchivo sera la ruta del archivo existente del cual tomaremos datos y los serializaremos</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">'@caracter sera el caracter separador que tenga entre dato y dato</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">'@rutaNuevoArchivo sera la ruta del archivo en el cual guardaremos nuestros datos serializados.</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">'@arr es la coleccion de lineas que tendremos en nuestro archivo, lo recibimos de la funcion Deserializar, </span><br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">'de la clase Serialidor.</span><br />
&nbsp; &nbsp; <span style="color: #0600FF;">Dim</span> rutaArchivo <span style="color: #FF8000;">As</span> <span style="color: #FF8000;">String</span><br />
&nbsp; &nbsp; <span style="color: #0600FF;">Dim</span> caracter <span style="color: #FF8000;">As</span> <span style="color: #FF8000;">String</span><br />
&nbsp; &nbsp; <span style="color: #0600FF;">Dim</span> NuevoArchivo <span style="color: #FF8000;">As</span> <span style="color: #FF8000;">String</span><br />
&nbsp; &nbsp; <span style="color: #0600FF;">Dim</span> arr <span style="color: #FF8000;">As</span> ArrayList<br />
&nbsp; &nbsp; Console.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;### String Reader ###&quot;</span> <span style="color: #008000;">&amp;</span> vbCrLf<span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">'Este Do no saldra del bucle hasta que se le de un archivo que exista, y que su extension sea .txt.</span><br />
&nbsp; &nbsp; <span style="color: #0600FF;">Do</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; Console.<span style="color: #0600FF;">Write</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;Inserte la ruta del archivo .txt que vamos a leer (por ejemplo C:\archivo.txt): &quot;</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; rutaArchivo <span style="color: #008000;">=</span> Console.<span style="color: #0000FF;">ReadLine</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #0600FF;">Loop</span> <span style="color: #0600FF;">While</span> Serializador.<span style="color: #0000FF;">ValidarRutadeArchivo</span><span style="color: #000000;">&#40;</span>rutaArchivo<span style="color: #000000;">&#41;</span> <span style="color: #008000;">=</span> <span style="color: #0600FF;">False</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">'Este Do no saldra del bucle hasta que se le inserte una cadena de texto de 1 caracter.</span><br />
&nbsp; &nbsp; <span style="color: #0600FF;">Do</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; Console.<span style="color: #0600FF;">Write</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;Inserte el caracter separador: &quot;</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; caracter <span style="color: #008000;">=</span> Console.<span style="color: #0000FF;">ReadLine</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #0600FF;">Loop</span> <span style="color: #0600FF;">While</span> caracter.<span style="color: #0000FF;">Length</span> <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span> Or caracter.<span style="color: #0000FF;">Length</span> &gt;<span style="color: #008000;">=</span> <span style="color: #FF0000;">2</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">'Este Do no saldra del bucle hasta que se le inserte un nombre de archivo valido (.txt) y el archivo</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">'no este creado.</span><br />
&nbsp; &nbsp; <span style="color: #0600FF;">Do</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; Console.<span style="color: #0600FF;">Write</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;Inserte el nombre del nuevo archivo serializado: &quot;</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; NuevoArchivo <span style="color: #008000;">=</span> Console.<span style="color: #0000FF;">ReadLine</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #0600FF;">Loop</span> <span style="color: #0600FF;">While</span> Serializador.<span style="color: #0000FF;">ValidarNombredeArchivo</span><span style="color: #000000;">&#40;</span>NuevoArchivo<span style="color: #000000;">&#41;</span> <span style="color: #008000;">=</span> <span style="color: #0600FF;">False</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">'Con los datos antes obtenidos, podemos instanciar nuestro serializador, el cual se encargara de des-serializar</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">'nuestro archivo con cadenas de texto separadas por un caracter, y crear uno nuevo mas ordenado</span><br />
&nbsp; &nbsp; <span style="color: #0600FF;">Dim</span> Serializator <span style="color: #FF8000;">As</span> <span style="color: #FF8000;">New</span> Serializador<span style="color: #000000;">&#40;</span>rutaArchivo, NuevoArchivo, caracter<span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">'Corremos la funcion Deserializar, y obtenemos una lista de elementos.</span><br />
&nbsp; &nbsp; arr <span style="color: #008000;">=</span> Serializator.<span style="color: #0000FF;">Deserializar</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">'Si arr no es nada (lo que quiere decir que habian datos en el archivo, y que no hubo ningun error corriendo</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">'la deserializacion.</span><br />
&nbsp; &nbsp; <span style="color: #0600FF;">If</span> arr <span style="color: #FF8000;">IsNot</span> <span style="color: #FF8000;">Nothing</span> <span style="color: #FF8000;">Then</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">'Serializamos en nuestro nuevo archivo le mandamos a este evento la coleccion de strings que tengamos</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">'dentro de ella, y mostramos mensaje de que todo salio bien.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; Serializator.<span style="color: #0000FF;">Guardar</span><span style="color: #000000;">&#40;</span>arr<span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; Console.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;Archivo des-serializado satisfactoriamente&quot;</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #FF8000;">Else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">'Ocurrio un error al serializar, asi que mostramos un mensaje de que no se pudo realizar satisfactoriamente.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; Console.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;Error al serializar / deserializar el archivo.&quot;</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #0600FF;">End</span> <span style="color: #0600FF;">If</span><br />
&nbsp; &nbsp; Console.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;Presione una tecla para salir del programa...&quot;</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; Console.<span style="color: #0000FF;">ReadKey</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br />
<span style="color: #0600FF;">End</span> <span style="color: #0600FF;">Sub</span></div></td></tr></tbody></table></div>
<p>Bien, ahora que hemos visto como funciona el modulo, les presento la clase Serializador:</p>
<div class="codecolorer-container vbnet vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br />74<br />75<br />76<br />77<br />78<br />79<br />80<br />81<br />82<br />83<br />84<br />85<br />86<br />87<br />88<br />89<br />90<br />91<br />92<br />93<br />94<br />95<br />96<br />97<br />98<br />99<br />100<br />101<br />102<br />103<br />104<br />105<br />106<br />107<br />108<br />109<br />110<br />111<br />112<br />113<br />114<br />115<br />116<br />117<br />118<br />119<br />120<br />121<br />122<br />123<br />124<br />125<br />126<br />127<br />128<br />129<br />130<br />131<br />132<br />133<br />134<br />135<br />136<br />137<br />138<br />139<br />140<br />141<br />142<br />143<br />144<br />145<br />146<br />147<br />148<br />149<br />150<br />151<br />152<br />153<br />154<br />155<br />156<br />157<br />158<br />159<br />160<br />161<br />162<br />163<br />164<br />165<br />166<br />167<br />168<br />169<br /></div></td><td><div class="vbnet codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #008080; font-style: italic;">'Importamos librerias que nos serviran para el manejo de archivos.</span><br />
<span style="color: #0600FF;">Imports</span> System.<span style="color: #0000FF;">IO</span><br />
<span style="color: #0600FF;">Imports</span> System<br />
<br />
<span style="color: #FF8000;">Public</span> <span style="color: #0600FF;">Class</span> Serializador<br />
<br />
&nbsp; &nbsp; <span style="color: #FF8000;">Private</span> mRutaArchivo <span style="color: #FF8000;">As</span> <span style="color: #FF8000;">String</span><br />
&nbsp; &nbsp; <span style="color: #FF8000;">Private</span> mNuevoArchivo <span style="color: #FF8000;">As</span> <span style="color: #FF8000;">String</span><br />
&nbsp; &nbsp; <span style="color: #FF8000;">Private</span> mCaracter <span style="color: #FF8000;">As</span> <span style="color: #FF8000;">String</span><br />
&nbsp; &nbsp; <span style="color: #FF8000;">Private</span> datosPorLinea <span style="color: #FF8000;">As</span> <span style="color: #FF0000;">Integer</span><br />
<br />
&nbsp; &nbsp; <span style="color: #FF8000;">Public</span> <span style="color: #FF8000;">Property</span> RutaArchivo<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #FF8000;">As</span> <span style="color: #FF8000;">String</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #FF8000;">Get</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #FF8000;">Return</span> <span style="color: #FF8000;">Me</span>.<span style="color: #0000FF;">mRutaArchivo</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">End</span> <span style="color: #FF8000;">Get</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #FF8000;">Set</span><span style="color: #000000;">&#40;</span><span style="color: #FF8000;">ByVal</span> value <span style="color: #FF8000;">As</span> <span style="color: #FF8000;">String</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #FF8000;">Me</span>.<span style="color: #0000FF;">mRutaArchivo</span> <span style="color: #008000;">=</span> value<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">End</span> <span style="color: #FF8000;">Set</span><br />
&nbsp; &nbsp; <span style="color: #0600FF;">End</span> <span style="color: #FF8000;">Property</span><br />
<br />
&nbsp; &nbsp; <span style="color: #FF8000;">Public</span> <span style="color: #FF8000;">Property</span> NuevoArchivo<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #FF8000;">As</span> <span style="color: #FF8000;">String</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #FF8000;">Get</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #FF8000;">Return</span> <span style="color: #FF8000;">Me</span>.<span style="color: #0000FF;">mNuevoArchivo</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">End</span> <span style="color: #FF8000;">Get</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #FF8000;">Set</span><span style="color: #000000;">&#40;</span><span style="color: #FF8000;">ByVal</span> value <span style="color: #FF8000;">As</span> <span style="color: #FF8000;">String</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #FF8000;">Me</span>.<span style="color: #0000FF;">mNuevoArchivo</span> <span style="color: #008000;">=</span> value<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">End</span> <span style="color: #FF8000;">Set</span><br />
&nbsp; &nbsp; <span style="color: #0600FF;">End</span> <span style="color: #FF8000;">Property</span><br />
<br />
&nbsp; &nbsp; <span style="color: #FF8000;">Public</span> <span style="color: #FF8000;">Property</span> Caracter<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #FF8000;">As</span> <span style="color: #FF8000;">String</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #FF8000;">Get</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #FF8000;">Return</span> <span style="color: #FF8000;">Me</span>.<span style="color: #0000FF;">mCaracter</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">End</span> <span style="color: #FF8000;">Get</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #FF8000;">Set</span><span style="color: #000000;">&#40;</span><span style="color: #FF8000;">ByVal</span> value <span style="color: #FF8000;">As</span> <span style="color: #FF8000;">String</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #FF8000;">Me</span>.<span style="color: #0000FF;">mCaracter</span> <span style="color: #008000;">=</span> value<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">End</span> <span style="color: #FF8000;">Set</span><br />
&nbsp; &nbsp; <span style="color: #0600FF;">End</span> <span style="color: #FF8000;">Property</span><br />
<br />
&nbsp; &nbsp; <span style="color: #0600FF;">Sub</span> <span style="color: #FF8000;">New</span><span style="color: #000000;">&#40;</span><span style="color: #FF8000;">ByVal</span> rutaArchivo <span style="color: #FF8000;">As</span> <span style="color: #FF8000;">String</span>, <span style="color: #FF8000;">ByVal</span> nuevoArchivo <span style="color: #FF8000;">As</span> <span style="color: #FF8000;">String</span>, <span style="color: #FF8000;">ByVal</span> caracter <span style="color: #FF8000;">As</span> Char<span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #FF8000;">Me</span>.<span style="color: #0000FF;">RutaArchivo</span> <span style="color: #008000;">=</span> rutaArchivo<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #FF8000;">Me</span>.<span style="color: #0000FF;">NuevoArchivo</span> <span style="color: #008000;">=</span> nuevoArchivo<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #FF8000;">Me</span>.<span style="color: #0000FF;">Caracter</span> <span style="color: #008000;">=</span> caracter<br />
&nbsp; &nbsp; <span style="color: #0600FF;">End</span> <span style="color: #0600FF;">Sub</span><br />
<br />
&nbsp; &nbsp; <span style="color: #FF8000;">Public</span> <span style="color: #FF8000;">Shared</span> <span style="color: #0600FF;">Function</span> ValidarRutadeArchivo<span style="color: #000000;">&#40;</span><span style="color: #FF8000;">ByVal</span> rutaArchivo <span style="color: #FF8000;">As</span> <span style="color: #FF8000;">String</span><span style="color: #000000;">&#41;</span> <span style="color: #FF8000;">As</span> <span style="color: #FF0000;">Boolean</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">If</span> <a href="http://www.google.com/search?q=FILE+site:msdn.microsoft.com"><span style="color: #008000;">File</span></a>.<span style="color: #0000FF;">Exists</span><span style="color: #000000;">&#40;</span>rutaArchivo<span style="color: #000000;">&#41;</span> <span style="color: #FF8000;">Then</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #FF8000;">Return</span> <span style="color: #0600FF;">True</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #FF8000;">Else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #FF8000;">Return</span> <span style="color: #0600FF;">False</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">End</span> <span style="color: #0600FF;">If</span><br />
&nbsp; &nbsp; <span style="color: #0600FF;">End</span> <span style="color: #0600FF;">Function</span><br />
<br />
&nbsp; &nbsp; <span style="color: #FF8000;">Public</span> <span style="color: #0600FF;">Function</span> Deserializar<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #FF8000;">As</span> ArrayList<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">'@arch, es el archivo que se nos envio hoy desde el modulo, en el cual trabajaremos en la primera parte de la funcion.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">'@arr, es la coleccion de datos que obtendremos separandolos por el caracter separador.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">'@linea, es la linea de arch en la que estamos.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">'@i, es un contador auxiliar, usado para recorrer caracter por caracter en cada linea de @arch</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">'@datoAux, cargaremos en esta variable dato por dato que vayamos recibiendo.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">'@ret, vamos a guardar en esta coleccion las lineas que va a tener el futuro archivo que creemos.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">'@cantidadLineas, la cantidad de lineas que tiene el archivo que estamos leyendo.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">'@cantidadDatos, la cantidad de datos total que obtenemos del archivo (para poder sacar cuantos datos hay por linea) - la usaremos en conjunto con @cantidadLineas -.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">'@texto, esta variable la usaremos por cuantas lineas tengamos en el archivo que estamos leyendo, nos servira para guardar datos en el array, ya formateados.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">Dim</span> arch <span style="color: #FF8000;">As</span> <span style="color: #FF8000;">New</span> StreamReader<span style="color: #000000;">&#40;</span>RutaArchivo<span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">Dim</span> arr <span style="color: #FF8000;">As</span> <span style="color: #FF8000;">New</span> ArrayList<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">Dim</span> linea <span style="color: #FF8000;">As</span> <span style="color: #FF8000;">String</span> <span style="color: #008000;">=</span> arch.<span style="color: #0000FF;">ReadLine</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">Dim</span> i <span style="color: #FF8000;">As</span> <span style="color: #FF0000;">Integer</span> <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">Dim</span> datoAux <span style="color: #FF8000;">As</span> <span style="color: #FF8000;">String</span> <span style="color: #008000;">=</span> <span style="color: #808080;">&quot;&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">Dim</span> ret <span style="color: #FF8000;">As</span> <span style="color: #FF8000;">New</span> ArrayList<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">Dim</span> cantidadLineas <span style="color: #FF8000;">As</span> <span style="color: #FF0000;">Integer</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">Dim</span> cantidadDatos <span style="color: #FF8000;">As</span> <span style="color: #FF0000;">Integer</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">Dim</span> texto <span style="color: #FF8000;">As</span> <span style="color: #FF8000;">String</span> <span style="color: #008000;">=</span> <span style="color: #808080;">&quot;&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">'mientras la linea que estemos leyendo no este vacia...</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">While</span> <span style="color: #804040;">Not</span> linea <span style="color: #FF8000;">Is</span> <span style="color: #FF8000;">Nothing</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">'con este for recorremos toda la linea</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #FF8000;">For</span> i <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span> <span style="color: #FF8000;">To</span> linea.<span style="color: #0000FF;">Length</span> <span style="color: #008000;">-</span> <span style="color: #FF0000;">1</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">'chequeamos si el caracter en el que estamos parados ahora mismo en la linea es el caracter separador</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">If</span> linea.<span style="color: #0000FF;">Chars</span><span style="color: #000000;">&#40;</span>i<span style="color: #000000;">&#41;</span> <span style="color: #008000;">=</span> Caracter <span style="color: #FF8000;">Then</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">'si lo es, entonces guardamos el dato en el array, sumamos uno a la cantidad de datos y vaciamos datosAux</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; arr.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span>datoAux<span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; datoAux <span style="color: #008000;">=</span> <span style="color: #808080;">&quot;&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cantidadDatos <span style="color: #008000;">+=</span> <span style="color: #FF0000;">1</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #FF8000;">Else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">'Sino, agregamos el caracter a nuestro string datosAux</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; datoAux <span style="color: #008000;">+=</span> linea.<span style="color: #0000FF;">Chars</span><span style="color: #000000;">&#40;</span>i<span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">End</span> <span style="color: #0600FF;">If</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #FF8000;">Next</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">'Agregamos el ultimo dato de la linea, como necesita el caracter separador y el ultimo dato no lo tiene.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; arr.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span>datoAux<span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">'Borramos datosAux</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; datoAux <span style="color: #008000;">=</span> <span style="color: #808080;">&quot;&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">'Leemos otra linea del archivo.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; linea <span style="color: #008000;">=</span> arch.<span style="color: #0000FF;">ReadLine</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">'Agregamos uno a la cantidad de lineas, y uno mas a la cantidad de datos (por el ultimo dato que agregamos).</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cantidadLineas <span style="color: #008000;">+=</span> <span style="color: #FF0000;">1</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cantidadDatos <span style="color: #008000;">+=</span> <span style="color: #FF0000;">1</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">End</span> <span style="color: #0600FF;">While</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">'Obtenemos la cantidad de datos por linea dividiendo la cantidad de datos por la cantidad de lineas, y cerramos</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">'el archivo.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; datosPorLinea <span style="color: #008000;">=</span> cantidadDatos <span style="color: #008000;">/</span> cantidadLineas<br />
&nbsp; &nbsp; &nbsp; &nbsp; arch.<span style="color: #0600FF;">Close</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">'Si array es nada, entonces devolvemos nothing (y desde el modulo, pretenderemos que hubo un error).</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">If</span> arr <span style="color: #FF8000;">Is</span> <span style="color: #FF8000;">Nothing</span> <span style="color: #FF8000;">Then</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #FF8000;">Return</span> <span style="color: #FF8000;">Nothing</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #FF8000;">Else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">'Sino, instanciamos 3 variables que nos ayudaran para guardar los datos bien formateados en la coleccion ret</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">'@j, es el contador que nos ayudara a recorrer @arr.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">'@x, es como decir, el &quot;formateador&quot;, nos ayudara a formatear nuestros datos y agregarle los espacios</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">'necesarios a la derecha para que queden 20 caracteres por dato (suponiendo que los datos no son mas largos</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">'de 19 caracteres).</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">'@y, es la suma de j + 1 para luego poder hacer el MOD satisfactoriamente.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">Dim</span> j <span style="color: #FF8000;">As</span> <span style="color: #FF0000;">Integer</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">Dim</span> x <span style="color: #FF8000;">As</span> <span style="color: #FF0000;">Integer</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">Dim</span> y <span style="color: #FF8000;">As</span> <span style="color: #FF0000;">Integer</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #FF8000;">For</span> j <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span> <span style="color: #FF8000;">To</span> arr.<span style="color: #0000FF;">Count</span> <span style="color: #008000;">-</span> <span style="color: #FF0000;">1</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">'Recorremos la coleccion, y agregamos a nuestra variable @texto el contenido de cada item.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; texto <span style="color: #008000;">+=</span> arr.<span style="color: #0000FF;">Item</span><span style="color: #000000;">&#40;</span>j<span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #FF8000;">For</span> x <span style="color: #008000;">=</span> arr.<span style="color: #0000FF;">Item</span><span style="color: #000000;">&#40;</span>j<span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">ToString</span>.<span style="color: #0000FF;">Length</span> <span style="color: #FF8000;">To</span> <span style="color: #FF0000;">20</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; texto <span style="color: #008000;">+=</span> <span style="color: #808080;">&quot; &quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">'Hasta que el largo de la cadena @texto sea 20, agregaremos un espacio a la cadena.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #FF8000;">Next</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; y <span style="color: #008000;">=</span> j <span style="color: #008000;">+</span> <span style="color: #FF0000;">1</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">If</span> y <span style="color: #804040;">Mod</span> datosPorLinea <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span> <span style="color: #FF8000;">Then</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">'Si y MOD (resto de la division) datos por linea es igual a 0.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ret.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span>texto<span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; texto <span style="color: #008000;">=</span> <span style="color: #808080;">&quot;&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">'Agregamos a @ret la cadena de texto, y vaciamos la variable @texto.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">End</span> <span style="color: #0600FF;">If</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #FF8000;">Next</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">End</span> <span style="color: #0600FF;">If</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">'Retornamos nuestra coleccion.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #FF8000;">Return</span> ret<br />
&nbsp; &nbsp; <span style="color: #0600FF;">End</span> <span style="color: #0600FF;">Function</span><br />
<br />
&nbsp; &nbsp; <span style="color: #FF8000;">Public</span> <span style="color: #0600FF;">Sub</span> Guardar<span style="color: #000000;">&#40;</span><span style="color: #FF8000;">ByVal</span> arr <span style="color: #FF8000;">As</span> ArrayList<span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">'@arch, el archivo que crearemos y en el cual guardaremos los datos formateados.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">Dim</span> arch <span style="color: #FF8000;">As</span> <span style="color: #FF8000;">New</span> StreamWriter<span style="color: #000000;">&#40;</span>NuevoArchivo<span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #FF8000;">For</span> <span style="color: #0600FF;">Each</span> linea <span style="color: #FF8000;">As</span> <span style="color: #FF8000;">String</span> In arr<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">'Recorremos la coleccion que se nos dio cuando recibimos los datos, y por cada item de la coleccion</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">'escribimos una nueva linea con esa cadena y pasamos al siguiente renglon (WriteLine hace eso, si fuera</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">'solo Write escribiria todo en una linea).</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; arch.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span>linea<span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #FF8000;">Next</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">'Cerramos el archivo.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; arch.<span style="color: #0600FF;">Close</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #0600FF;">End</span> <span style="color: #0600FF;">Sub</span><br />
<br />
&nbsp; &nbsp; <span style="color: #FF8000;">Public</span> <span style="color: #FF8000;">Shared</span> <span style="color: #0600FF;">Function</span> ValidarNombredeArchivo<span style="color: #000000;">&#40;</span><span style="color: #FF8000;">ByVal</span> nombre <span style="color: #FF8000;">As</span> <span style="color: #FF8000;">String</span><span style="color: #000000;">&#41;</span> <span style="color: #FF8000;">As</span> <span style="color: #FF0000;">Boolean</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">If</span> nombre.<span style="color: #0000FF;">Contains</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;.&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #FF8000;">Then</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">'Si nombre contiene un . deducimos que se trataria de un archivo.. salvo para las personas que les guste</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">'decir &quot;JA! te cague el programa! si le pongo dos . . se cae!&quot;, y bueno.. todo perfecto no se puede hacer.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">'@datos, un array String que mediante la funcion String.Split obtendremos (si no pasa lo antes mencionado),</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">'dos datos, en la posicion 0 del array, obtendremos el nombre del archivo, y en la 1, la extension..</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">'que es lo que nos importa a nosotros.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">Dim</span> datos<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #FF8000;">As</span> <span style="color: #FF8000;">String</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; datos <span style="color: #008000;">=</span> nombre.<span style="color: #0600FF;">Split</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;.&quot;</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">If</span> datos<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">1</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">=</span> <span style="color: #808080;">&quot;txt&quot;</span> <span style="color: #FF8000;">Then</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">'Si la extension es igual a txt, entonces retornamos true, porque sabemos que se trata de un archivo</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">'de texto..</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #FF8000;">Return</span> <span style="color: #0600FF;">True</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #FF8000;">Else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">'Sino, retornamos false.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #FF8000;">Return</span> <span style="color: #0600FF;">False</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">End</span> <span style="color: #0600FF;">If</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #FF8000;">Else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">'Si no contiene . quiere decir que no contiene extension tampoco, por lo que retornamos false.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #FF8000;">Return</span> <span style="color: #0600FF;">False</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">End</span> <span style="color: #0600FF;">If</span><br />
&nbsp; &nbsp; <span style="color: #0600FF;">End</span> <span style="color: #0600FF;">Function</span><br />
<span style="color: #0600FF;">End</span> <span style="color: #0600FF;">Class</span></div></td></tr></tbody></table></div>
<p>Esta todo explicado dentro de la clase, para probar que funcionara, cree un archivo que se llamaba archivo.txt y contenia lo siguiente:</p>
<blockquote><p>Maltray*2546889*matias.a18@gmail.com<br />
mnosh*55668997788*mnox@gmail.com<br />
bony*455568899*bony@gmail.com<br />
usuario5*contraseniaaaa5*mail5@gmail.com</p></blockquote>
<p>Le puse en caracter separador, *, y en nuevo archivo: note.txt.</p>
<p>El resultado fue, en la carpeta bin/Debug (del proyecto) se creo un archivo note.txt con lo siguiente:</p>
<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Maltray &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;2546889 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;matias.a18@gmail.com <br />
mnosh &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;55668997788 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;mnox@gmail.com &nbsp; &nbsp; &nbsp; <br />
bony &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 455568899 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;bony@gmail.com &nbsp; &nbsp; &nbsp; <br />
usuario5 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; contraseniaaaa5 &nbsp; &nbsp; &nbsp;mail5@gmail.com</div></td></tr></tbody></table></div>
<p>La solucion esta toda en el siguiente zip que les voy a poner, el archivo para des-serializar y probarlo tambien esta ahi, y tambien les dejo el archivo note.txt para que vean bien como quedo.</p>
<p>Recordar que la solucion esta creada con Visual Basic 2008, por lo que, si tenemos uno mas viejo dudo que puedan verlo.</p>
<p><strong>Link: </strong><a href="http://hotfile.com/dl/20229098/5ffbf78/Leer_String.rar.html">http://hotfile.com/dl/20229098/5ffbf78/Leer_String.rar.html</a><br />
<em>Pass: </em>http://www.informaticavirtual.us</p>
<p>En el se encuentran: </p>
<blockquote><p>Leer String (Directorio): Contiene la solucion para Visual Studio 2008<br />
note.txt: El archivo creado por nuestro programa a partir de archivo.txt<br />
archivo.txt: El archivo a des-serializar</p></blockquote>
<p>Espero que les haya gustado, costo un poco hacer este post y este programa, pero despues de todo, salio.</p>
<p>Saludos.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.informaticavirtual.us/2009/12/11/des-serializar-archivos-de-texto-en-visual-basic-net/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
