Private Type libro
autore As String * 30
titolo As String * 30
prezzo As String * 12
codice As String * 10
genere As String * 20
End Type
Dim vetlibro() As libro
Public strlinea As String
Public stringa As String, filename As String
Public num As Integer, cc As Integer, contatore As Integer
Public linea As String
Public i As Integer
Public Function invettore() As String
Dim cont As Integer, linea As String, i As Integer
cont = 0
Open "c:\libri.dat" For Input As #1
While Not EOF(1)
Line Input #1, linea
cont = cont + 1
Wend
Close #1
Open "c:\libri.dat" For Input As #1
For i = 1 To cont
ReDim Preserve vetlibro(1 To i) As libro
If Not EOF(1) Then
Line Input #1, linea
vetlibro(i).autore = Mid(linea, 1, 20)
vetlibro(i).titolo = Mid(linea, 21, 41)
vetlibro(i).genere = Mid(linea, 41, 61)
vetlibro(i).codice = Mid(linea, 61, 80)
vetlibro(i).prezzo = Mid(linea, 80, 100)
End If
Next i
Close #1
invettore = i
End Function
Private Sub cmdinserisci_Click()
num = num + 1
cc = 0
ReDim Preserve vetlibro(1 To num) As libro
vetlibro(num).autore = UCase(Trim(Txtautore.Text))
vetlibro(num).codice = UCase(Trim(Txtcodice.Text))
vetlibro(num).genere = UCase(Trim(Txtgenere.Text))
vetlibro(num).prezzo = UCase(Trim(Txtprezzo.Text))
vetlibro(num).titolo = UCase(Trim(Txttitolo.Text))
Txtautore.Text = ""
Txtcodice.Text = ""
Txtgenere.Text = ""
Txtprezzo.Text = ""
Txttitolo.Text = ""
strlinea = vetlibro(num).autore & vetlibro(num).titolo & vetlibro(num).genere & vetlibro(num).codice & vetlibro(num).prezzo
Open "c:\libri.dat" For Append As #1
Print #1, strlinea
Close #1
Call invettore
i = invettore - 1
End Sub
Private Sub Command1_Click()
If cc < i Then
cc = cc + 1
Txttitolo.Text = vetlibro(cc).titolo
Txtautore.Text = vetlibro(cc).autore
Txtgenere.Text = vetlibro(cc).genere
Txtcodice.Text = vetlibro(cc).codice
Txtprezzo.Text = vetlibro(cc).prezzo
End If
cmdinserisci.Enabled = False
End Sub
Private Sub Command2_Click()
If cc > 1 Then
cc = cc - 1
Txttitolo.Text = vetlibro(cc).titolo
Txtautore.Text = vetlibro(cc).autore
Txtgenere.Text = vetlibro(cc).genere
Txtcodice.Text = vetlibro(cc).codice
Txtprezzo.Text = vetlibro(cc).prezzo
End If
cmdinserisci.Enabled = False
End Sub
Private Sub Form_Load()
On Error Resume Next
Open "c:\libri.dat" For Input As #1
Close #1
Call invettore
i = invettore - 1
End Sub
Private Sub mnucanctabella_Click()
On Error GoTo err
Dim risposta As Integer
ris = MsgBox("Sei sicuro di rimuovere tutti gli elementi del database? (digitando su ok tutti gli elementi saranno eliminati)", vbExclamation + vbYesNo, "Avviso")
If ris = vbYes Then
Form2.List1.Clear
Open filename For Output As #1
While Not EOF(1)
Print #1, ""
Wend
Else
Cancel = True
Exit Sub
End If
Close #1
err: MsgBox "lista vuota", vbInformation, "Lista"
End Sub
Private Sub mnuesci_Click()
Dim ris As Integer
ris = MsgBox("Vuoi uscire dal programma?", vbQuestion + vbYesNo, "Esci")
If ris = vbYes Then
MsgBox "BY ALBERT KING 13\04\2006!!!", vbInformation, "Creatore"
End
Else
Cancel = True
End If
End Sub
Private Sub mnupulisci_Click()
Txttitolo.Text = ""
Txtautore.Text = ""
Txtgenere.Text = ""
Txtcodice.Text = ""
Txtprezzo.Text = ""
cc = 0
Txttitolo.SetFocus
End Sub
Private Sub mnutabella_Click()
On Error GoTo errore
Open "c:\libri.dat" For Input As #1
While Not EOF(1)
Line Input #1, stringa
Form2.List1.AddItem stringa
Wend
If stringa = " " Then
MsgBox "Il database è vuoto", vbInformation, "info"
Else
Form2.Show
End If
Close #1
errore: MsgBox "Lista vuota", vbInformation, "vuota"
End Sub
Private Sub Txtautore_Change()
If Txttitolo.Text <> "" And Txtprezzo.Text <> "" And Txtautore.Text <> "" Then
cmdinserisci.Enabled = True
Else
cmdinserisci.Enabled = False
End If
End Sub
Private Sub Txtprezzo_Change()
If Txttitolo.Text <> "" And Txtprezzo.Text <> "" And Txtautore.Text <> "" Then
cmdinserisci.Enabled = True
Else
cmdinserisci.Enabled = False
End If
End Sub
Private Sub Txttitolo_Change()
If Txttitolo.Text <> "" And Txtprezzo.Text <> "" And Txtautore.Text <> "" Then
cmdinserisci.Enabled = True
Else
cmdinserisci.Enabled = False
End If
End Sub