Visual Basic - Cargar y Guardar archivos *.txt

Life is soft - evento anual de software empresarial
 
Vista:

Cargar y Guardar archivos *.txt

Publicado por Jhonatan (1 intervención) el 02/10/2009 05:53:44
ayuda tengo q hacer un programa q carge y guarde un archivo de texto los objetos que voy a utilizar van a ser (text1, command1 y command2)

Text1.MultiLine = True
Command1.Caption = Cargar
Command2.Caption = Guardar

para que carge el archivo de texto que va ser caja1

Private Sub Command1_Click()
Dim x
x = FreeFile
Open App.Path & "\caja1.txt" For Input As x
Do While Not EOF(x)
Line Input #x, Txt
Text1 = Text1 & vbCrLf & Txt
Loop
Close x
End Sub

para que guarde el archivo de texto que va ser caja2

Private Sub Command2_Click()
Open App.Path & "\caja2.txt" For Output As #1
Print #1, Text1.Text
Close #1
End Sub

las formulas funcionan perfectamente pero tengo un problema con la segunda formula es q no me respeta los espacios entre lineas osea que en caja1 yo tengo el texto en varias lineas
que debo hacer para q me agrege linea por linea el contenido del text1 al archivo caja2.txt

para q caja1.txt y caja2.txt sean exactamente iguales
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 y Guardar archivos *.txt

Publicado por juan carlos (518 intervenciones) el 02/10/2009 07:46:48
hola jonathan intentalo asi

Private Sub Command2_Click()
Open "c:\caja1.txt" For Output As #1
Open "c:\caja2.txt" For Output As #2
Print #2, Text1.Text
Print #1, Text1.Text
Close #1
Close #2
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 y Guardar archivos *.txt

Publicado por jorge (35 intervenciones) el 02/10/2009 15:59:54
esto te servira


Dim Fichero, Ficheropath As String

Private Sub Command1_Click()
CommonDialog1.Filter = "texto (*.txt)|*.txt|todos (*.*)|*.*"
CommonDialog1.ShowOpen
Ficheropath = CommonDialog1.FileName
Open Ficheropath For Input As #1
Text1.Text = Input(LOF(1), #1)
Close #1
End Sub

Private Sub Command2_Click()
Open Ficheropath For Output As #1
Print #1, Text1.Text
Close #1
End Sub

Private Sub Command3_Click()
CommonDialog1.DefaultExt = "txt"
CommonDialog1.ShowSave
Fichero = CommonDialog1.FileTitle
Ficheropath = CommonDialog1.FileName
Open Ficheropath For Output As #1
Print #1, Text1.Text
Close #1
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