Visual Basic.NET - Guardar y Abrir Archivos (de texbox a .txt y .txt a textbox)

 
Vista:

Guardar y Abrir Archivos (de texbox a .txt y .txt a textbox)

Publicado por Josue (3 intervenciones) el 06/06/2020 17:14:34
Mi problema es que quiero que al darle en guardar, el texto del textbox se guarde en un .txt y que al darle en abrir se cargue ese mismo texto en el textBox, pero no se como hacerlo, Hay alguna manera ?
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
Imágen de perfil de Phil Rob
Val: 3.353
Oro
Ha mantenido su posición en Visual Basic.NET (en relación al último mes)
Gráfica de Visual Basic.NET

Guardar y Abrir Archivos (de texbox a .txt y .txt a textbox)

Publicado por Phil Rob (1554 intervenciones) el 07/06/2020 10:03:00
Hola,

No soy seguro de comprender bien tu pregunta.

Si comprendo, el código siguiente muestra un solucione :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
Private Sub EscribirEnElFichero(ByRef NombreYRutaFicheroAEscribir As String, ByRef FaseAEscribir As String)
    Dim FicheroAEscribir = New System.IO.StreamWriter(NombreYRutaFicheroAEscribir, False) ' con FALSE, reemplaza fichero anterior, con TRUE añade.
    FicheroAEscribir.WriteLine(FaseAEscribir)
    FicheroAEscribir.Close()
    FicheroAEscribir.Dispose()
End Sub
 
Private Function LeerEnElFichero(ByRef NombreYRutaFicheroALeer As String) As String
    Dim FicheroALeer = New System.IO.StreamReader(NombreYRutaFicheroALeer, System.Text.Encoding.Default)
    Dim FraseLeida As String = FicheroALeer.Readline()
    FicheroALeer.close()
    FicheroALeer.Dispose()
    Return FraseLeida
End Function

Cuando quieres escribir el contenido de un TextBox, llamas el procedimiento EscribirEnElFichero :
1
EscribirEnElFichero(Nombre_Y_Ruta_Del_Fichero_Que_Gustas, LaTextBox.Text)

Cuando quieres leer el fichero para llegar la TextBox, llamas la funcion LeerEnElFichero :
1
UnaTextBox.Text = LeerEnElFichero(Nombre_Y_Ruta_Del_Fichero_Que_Gusta)

???
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