Option Explicit
Private Type Rec
Matricola As String
Nome As String
Cognome As String
Classe As String
End Type
Dim R As Rec
Dim ultimorec As String
Private Sub Aggiungi_Click()
Txtnome.Text = ""
Txtcognome.Text = ""
Txtmatricola.Text = ""
Txtclasse.Text = ""
Txtnome.Enabled = True
Txtcognome.Enabled = True
Txtmatricola.Enabled = True
Txtclasse.Enabled = True
End Sub
Private Sub Form_Load()
Percorso.Text = NomeFile
Visualizza.Value = True
Open NomeFile For Random As #1 Len = Len(R)
If LOF(1) = 0 Then
MsgBox (" File vuoto !!"), vbOKOnly, " Information !!"
Else: Caricalistamatricole
End If
End Sub
Sub Caricalistamatricole()
lstmatricole.Clear
Get #1, 1, R
While Not (EOF(1))
lstmatricole.AddItem R.Matricola
Get #1, , R
Wend
lstmatricole.ListIndex = 0
End Sub
Sub Ordinafile()
Dim i As Integer
Dim j As Integer
Dim r1 As Rec
Dim r2 As Rec
ultimorec = LOF(1) / Len(R)
For i = 1 To ultimorec - 1
For j = i + 1 To ultimorec
Get #1, i, r1
Get #1, j, r2
If (r1.Matricola > r2.Matricola) Then
Put #1, i, r2
Put #1, j, r1
End If
Next j
Next i
End Sub
Sub Disattiva()
Txtnome.Enabled = False
Txtcognome.Enabled = False
Txtmatricola.Enabled = False
Txtclasse.Enabled = False
End Sub
Sub Attiva()
Txtnome.Enabled = True
Txtcognome.Enabled = True
Txtmatricola.Enabled = False
Txtclasse.Enabled = True
End Sub
Private Sub lstmatricole_Click()
Dim x As Integer
x = lstmatricole.ListIndex + 1
Get #1, x, R
Txtnome.Text = R.Nome
Txtcognome.Text = R.Cognome
Txtclasse.Text = R.Classe
Txtmatricola.Text = R.Matricola
End Sub
Private Sub Modifica_Click()
If (Modifica.Enabled = True) And (lstmatricole.ListCount > 0) Then
Attiva
Else: MsgBox ("Nessuna matricola presente!!"), vbOKOnly, " Information !!"
Aggiungi.Value = True
End If
Dim x As Integer
x = lstmatricole.ListIndex + 1
Txtcognome.Text = R.Cognome
Txtnome.Text = R.Nome
Txtclasse.Text = R.Classe
Txtmatricola.Text = R.Matricola
End Sub
Private Sub Pulisci_Click()
Txtnome.Text = ""
Txtcognome.Text = ""
Txtmatricola.Text = ""
Txtclasse.Text = ""
End Sub
Private Sub prec_Click()
If (lstmatricole.ListCount > 0) Then
If lstmatricole.ListIndex = 0 Then
lstmatricole.ListIndex = lstmatricole.ListCount - 1
Else: lstmatricole.ListIndex = lstmatricole.ListIndex - 1
End If
Else: MsgBox ("Nessuna matricola presente!!"), vbOKOnly, " Information !!"
End If
End Sub
Private Sub primo_Click()
If (lstmatricole.ListCount > 0) Then
lstmatricole.ListIndex = 0
Else: MsgBox ("Nessuna matricola presente!!"), vbOKOnly, " Information !!"
End If
End Sub
Private Sub succ_Click()
If (lstmatricole.ListCount > 0) Then
If lstmatricole.ListIndex = lstmatricole.ListCount - 1 Then
lstmatricole.ListIndex = 0
Else: lstmatricole.ListIndex = lstmatricole.ListIndex + 1
End If
Else: MsgBox ("Nessuna matricola presente!!"), vbOKOnly, " Information !!"
End If
End Sub
Private Sub ultimo_Click()
If (lstmatricole.ListCount > 0) Then
lstmatricole.ListIndex = lstmatricole.ListCount - 1
Else: MsgBox ("Nessuna matricola presente!!"), vbOKOnly, " Information !!"
End If
End Sub
Private Sub Salva_Click()
If (Aggiungi.Value = True) Then
ultimorec = LOF(1) / Len(R)
R.Matricola = Txtmatricola.Text
R.Classe = Txtclasse.Text
R.Cognome = Txtcognome.Text
R.Nome = Txtnome.Text
Put #1, ultimorec + 1, R
Ordinafile
Caricalistamatricole
Txtnome.Text = ""
Txtcognome.Text = ""
Txtmatricola.Text = ""
Txtclasse.Text = ""
Else:
R.Nome = Txtnome.Text
R.Cognome = Txtcognome.Text
R.Classe = Txtclasse.Text
lstmatricole.AddItem R.Matricola
Put #1, lstmatricole.ListIndex + 1, R
lstmatricole.Clear
Ordinafile
Caricalistamatricole
End If
End Sub
Private Sub Uscita_Click()
Close #1
Form1.Hide
End Sub
Private Sub Visualizza_Click()
If (Visualizza.Enabled = True) Then
Disattiva
End If
End Sub