Visual Basic - necesito leer un archivo

Life is soft - evento anual de software empresarial
 
Vista:

necesito leer un archivo

Publicado por Luis Fernando Gomez (18 intervenciones) el 08/10/2005 02:08:05
como hago para cuando en un txtbox ingrese un codigo y el un comanbotom le de buscar , este me busque el archivo.txt y leea linea por linea hasta encontrar el codigo que busco y lo inserte en un lisbox.
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

RE:necesito leer un archivo

Publicado por Cecilia Colalongo (3116 intervenciones) el 08/10/2005 14:59:26
Puedes leer el archivo, pasarlo a un String y luego manipularlo por filas:

Archivo = FileToString("MiArchivo.txt")
Lineas = Split(Archivo,vbCrLf)

Luego Lineas es un vector que contiene cada fila del archivo, para buscar la coincidencia puedes hacer:

For i=LBound(Lineas) To UBound(Lineas)

If Lineas(i)=Text1.Text Then
List1.AddItem Lineas(i)
Exit For
End If

Next i

La función para pasar un archivo a un String es:

Public Function FileToString(FileName As String) As String
On Error GoTo ErrorHandler

Dim hlngFile As Long, strFile As String

hlngFile = FreeFile

Open FileName For Binary Access Read As hlngFile

FileToString = vbNullString

strFile = String(FileLen(FileName), " ")

Get hlngFile, , strFile

Close hlngFile

FileToString = strFile

Exit Function
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

RE:necesito leer un archivo

Publicado por Ana Garijo (40 intervenciones) el 10/10/2005 16:48:58
YO USE ESTO PERO CON RICHTBOX
Criterio = RchTexto.Find(Busqueda, 0, Len(RchTexto.Text))
EN LA VAR Criterio SE RECOGE LA POSICIÓN, SI ES -1 NO SE ENCONTRÓ.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar