Visual Basic - cargar texto de un archivo a un text1.text

Life is soft - evento anual de software empresarial
 
Vista:

cargar texto de un archivo a un text1.text

Publicado por AVY (20 intervenciones) el 21/10/2004 21:43:38
ola a todos me gustaria q alguien me dijese el codigo para cargar el texto de un archivo .dat en un text1.text grasias
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:cargar texto de un archivo a un text1.text

Publicado por Ruri (583 intervenciones) el 22/10/2004 03:28:19
Utilizá el ScriptingObject. Para utilizarlo tenés que agregar en las referencias (menú proyecto\referencias) al Microsoft Scripting Runtime, Buscalo en la lista. Si no está utilizá el botón examinar y en System o System32 buscá scrrun.dll (viene con Internet explorer 5 o superior, es opcional en IE 4) se puede redistribuir sin problemas.

Option Explicit
DefLng A-Z

Private Sub cmdLeer_Click()
'Objeto scripting
Dim fso As Scripting.FileSystemObject, TxtStm As
Scripting.TextStream
Set fso = New FileSystemObject
'Abre el archivo de texto, si no existe lo crea
Set TxtStm = fso.OpenTextFile("C:\x.dat",
ForReading, True)
'Lee el archivo desde la primera a la última línea
Do
txtDatos.text=txtdatos.text & vbcrlf & TxtStm.ReadLine
Loop Until (TxtStm.AtEndOfStream) 'AtEndOfStream
es el final del archivo
Salida:
TxtStm.Close
Set TxtStm = Nothing
Set fso = Nothing
If Err.Number < 0 Then MsgBox Err.Description,
vbInformation, App.Title & " - Error de lectura"
End Sub
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:cargar texto de un archivo a un text1.text

Publicado por AVY (20 intervenciones) el 22/10/2004 20:03:35
muxas grasias
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:cargar texto de un archivo a un text1.text

Publicado por Ruri (583 intervenciones) el 22/10/2004 20:31:23

En la última línea, donde dice:
If Err.Number < 0 Then MsgBox Err.Description,
vbInformation, App.Title & " - Error de lectura"

Debería decir
If Err.Number <> 0 Then MsgBox Err.Description,
vbInformation, App.Title & " - Error de lectura"

Saludos Ruri
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