guardar datos txt boton anterior
Hola soy jilo
tengo un problema a la hora de guardar los datos lo hace bien, pero cuando le doy el boton anterior se salta un registro, no se que hago mal.
leer los datos lo hace bien y los botones anterior y siguiente lo hace bien
si me pueden ayudar
gracias
Código:
Private Type TRegistros
Tema As String
Materia As String
NumDia As String
Dia As String
Mes As String
End Type
Dim archivo As String
Private Registros() As TRegistros
Dim posicion, Total As Integer
Private Sub Command1_Click()
' Guardar datos
archivo = App.Path & "\datos.txt"
Open archivo For Append As #1
ReDim Preserve Registros(Total)
With Registros(Total)
.Tema = Text1.Text
.Materia = Text2.Text
.NumDia = Text3.Text
.Dia = Text4.Text
.Mes = Text5.Text
Write #1, .Tema
Write #1, .Materia
Write #1, .NumDia
Write #1, .Dia
Write #1, .Mes
End With
Close #1
End Sub
Private Sub leer()
'leer
archivo = App.Path & "\datos.txt"
Open archivo For Input As #1
While Not EOF(1)
ReDim Preserve Registros(Total)
With Registros(Total)
Input #1, .Tema
Input #1, .Materia
Input #1, .NumDia
Input #1, .Dia
Input #1, .Mes
End With
Total = Total + 1
Wend
Close #1
End Sub
Private Sub Command3_Click()
' siguiente registro
If posicion < UBound(Registros) Then
posicion = posicion + 1
VerRegistro posicion
End If
End Sub
Private Sub Command4_Click()
' Anterior registro
If posicion > 0 Then
posicion = posicion - 1
VerRegistro posicion
End If
End Sub
Private Sub Command6_Click()
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
Text5.Text = ""
Text1.SetFocus
End Sub
Private Sub Form_Load()
On Error Resume Next
leer
VerRegistro 0
End Sub
Private Sub VerRegistro(ByVal posicion As Integer)
With Registros(posicion)
Text1.Text = .Tema
Text2.Text = .Materia
Text3.Text = .NumDia
Text4.Text = .Dia
Text5.Text = .Mes
End With
End Sub
Private Sub Command5_Click()
End
End Sub