Visual Basic.NET - ficheros en visual basic. net

 
Vista:

ficheros en visual basic. net

Publicado por sandra (6 intervenciones) el 31/01/2006 16:48:35
hola me pueden explicar todo el codigo porque de el no entiendo nada me seria de gran ayuda gracias.
Public Class Form1
Inherits System.Windows.Forms.Form
Private Sub mnu_abrir_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnu_abrir.Click
OpenFileDialog1.Filter = "Archivos de texto (*.TXT)|*.TXT"
OpenFileDialog1.ShowDialog()
fich_abierto = OpenFileDialog1.FileName
If OpenFileDialog1.FileName <> "" Then
Call carga_datos(fich_abierto)
Panel1.Text = fich_abierto
mnu_abrir.Enabled = False
mnu_cerrar.Enabled = True
End If
End Sub
Private Sub mnu_Guardar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnu_guardar.Click
Call guarda_fich(fich_abierto)
StatusBar1.Text = SaveFileDialog1.FileName
mnu_cerrar.Enabled = True

End Sub
Private Sub mnu_Guardacomo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnu_guardar.Click
SaveFileDialog1.Filter = "Archivos de texto (*.TXT)|*.TXT"
SaveFileDialog1.ShowDialog()
If SaveFileDialog1.FileName <> "" Then
Call guarda_fich(SaveFileDialog1.FileName)
StatusBar1.Text = SaveFileDialog1.FileName
mnu_cerrar.Enabled = True
End If
End Sub

Private Sub mnu_cerrar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnu_cerrar.Click

FS.Close()
ListBox1.Items.Clear()
TextBox1.Text = ""
Panel1.Text = ""
mnu_abrir.Enabled = True
End Sub

Private Sub mnu_salir_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnu_salir.Click
End
End Sub

Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
mnu_guardar.Enabled = True
End Sub

Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
dato_activo = ListBox1.SelectedIndex
TextBox1.Text = agenda(dato_activo)
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If Button1.Text = "Modificar" Then
TextBox1.Enabled = True
Button1.Text = "Guardar"
Else
agenda(dato_activo) = TextBox1.Text
Button1.Text = "Modificar"
TextBox1.Enabled = False
Call carga_list(ListBox1)
End If
End Sub

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Panel3.Text = Hour(Now()) & ":" & Minute(Now()) & ":" & Second(Now())
End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Panel2.Text() = Today
Panel4.Text = "AGENDA"
End Sub
End Class

Imports System.IO
Module Module1
Public agenda(30) As String
Public tot_datos As Byte
Public dato_activo As Byte
Public fich_abierto As String
Public FS As FileStream
Public f_Lee As StreamReader
Dim f_Escr As StreamWriter

Public Sub carga_datos(ByVal nombre_f As String)
Dim dato As Object
FS = New FileStream(nombre_f, FileMode.Open)
f_Lee = New StreamReader(FS)
dato = f_Lee.ReadLine()
tot_datos = 0
While dato <> Nothing
agenda(tot_datos) = dato
dato = f_Lee.ReadLine()
tot_datos += 1
End While
f_Lee.Close()
End Sub
Public Sub guarda_fich(ByVal fichero)
Dim dato As Object
Dim i As Byte = 0
FS = New FileStream(fichero, FileMode.Create)
f_Escr = New StreamWriter(FS)
For i = 0 To tot_datos
f_Escr.WriteLine(agenda(i))
Next
f_Escr.Close()
End Sub

Public Sub carga_list(ByVal listado As Object)
Dim i As Byte
listado.Items.Clear()
For i = 0 To tot_datos - 1
listado.Items.Add(agenda(i))
Next
End Sub
End Module
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