Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
Libretto contabile - frmLibrettoContabile.frm

frmLibrettoContabile.frm

Caricato da: Antometal
Scarica il programma completo

  1. Option Explicit
  2. Public Ammontare As Long
  3. Public Password As String
  4. Public Nome As String
  5. Public XCorso As String
  6. Public Modifica As Boolean
  7.  
  8. Private Type Intestazione
  9. Nome As String
  10. Password As String
  11. End Type
  12.  
  13. Private Type recLibretto
  14. Data As Date
  15. Denaro As Long
  16. Commento As String * 256
  17. End Type
  18.  
  19. 'FUNCTION SUB  #####################################################################################################
  20.  
  21. Private Sub Salva(Percorso)
  22. Dim Dati As recLibretto
  23. Dim Testa As Intestazione
  24. Dim Oggetti() As String
  25. Dim I As Integer
  26.     If Dir(Percorso) <> "" Then Kill (Percorso)
  27. Me.Caption = CDialog.FileTitle & " - Libretto Contabile"
  28. Open Percorso For Random As 1 Len = Len(Dati)
  29. Modifica = False
  30. Testa.Nome = Nome
  31. Testa.Password = Password
  32. Put 1#, , Testa
  33.     For I = 0 To lstLibretto.ListCount - 1
  34.         Oggetti = Split(lstLibretto.List(I), vbTab)
  35.         Dati.Data = CDate(Replace(Oggetti(0), " ", ""))
  36.         Dati.Denaro = CLng(Replace(Oggetti(1), " ", ""))
  37.         Dati.Commento = Oggetti(2)
  38.         Put 1#, , Dati
  39.     Next I
  40. Close #1
  41. End Sub
  42.  
  43. Private Function Controllo() As Boolean
  44.     If IsDate(txtData) = False Then
  45.         MsgBox "Errore, formato data non valido" & vbCrLf & "Inserisci una date nel formato gg/mm/aaaa", vbExclamation
  46.         txtData = ""
  47.         Controllo = False
  48.         Exit Function
  49.     Else
  50.         Controllo = True
  51.     End If
  52. txtDenaro = Val(txtDenaro)
  53.     If txtDenaro = 0 Or txtDenaro > 1000000 Or txtDenaro < -1000000 Then
  54.         MsgBox "Errore, valore numerico inserito non corretto" & vbCrLf & "Inserisci un valore numerico diverso da 0 e compreso tra 10000 e -10000", vbExclamation
  55.         txtDenaro = ""
  56.         Controllo = False
  57.     Else
  58.         Controllo = True
  59.     End If
  60. End Function
  61.  
  62. Private Function ControlloModifica() As VbMsgBoxResult
  63. Dim Risposta As VbMsgBoxResult
  64.     If Modifica = False Then
  65.         ControlloModifica = vbNo
  66.         Exit Function
  67.     End If
  68. Risposta = MsgBox("I dati in questa finestra sono stati cambiati" & vbCrLf & vbCrLf & "Salvare i dati prima di aprire un altro file?", vbQuestion + vbYesNoCancel)
  69.     If Risposta = vbYes Then flSalvaNome_Click
  70. Modifica = False
  71. ControlloModifica = Risposta
  72. End Function
  73.  
  74. Private Function ControlloUscita() As Boolean
  75. Dim Risposta As VbMsgBoxResult
  76.     If Modifica = True Then
  77.         Risposta = MsgBox("Salvare i dati prima di uscire?", vbQuestion + vbYesNoCancel)
  78.             If Risposta = vbYes Then flSalva_Click
  79.             If Risposta = vbCancel Then ControlloUscita = True
  80.     Else
  81.         End
  82.     End If
  83. End Function
  84.  
  85. Private Sub AggiungiALista(Data As Date, Denaro As String, Commento As String, Posizione As Integer)
  86. Data = Data & Space(10 - Len(Data))
  87. Denaro = Space(8 - Len(Denaro)) & Denaro
  88. Modifica = True
  89. Somma (CLng(Denaro))
  90. lstLibretto.List(Posizione) = Data & vbTab & Denaro & vbTab & Commento
  91. End Sub
  92.  
  93. Private Sub Somma(Denaro As Long)
  94. Ammontare = Ammontare + Denaro
  95. lblAmmontare.Caption = "Ammontare: " & Ammontare
  96. End Sub
  97.  
  98. 'COMMAND BUTTON  ###################################################################################################
  99.  
  100. Private Sub cmdAggiungi_Click()
  101.     If Controllo = True Then AggiungiALista txtData, txtDenaro, txtCommento, lstLibretto.ListCount
  102. End Sub
  103.  
  104. Private Sub cmdElimina_Click()
  105.     If MsgBox("Conferma eliminazione dati", vbQuestion + vbYesNo) = vbYes Then
  106.         lstLibretto_Click
  107.         Somma (txtDenaro)
  108.         lstLibretto.RemoveItem lstLibretto.ListIndex
  109.         Modifica = True
  110.     End If
  111. End Sub
  112.  
  113. Private Sub cmdModifica_Click()
  114.     If Controllo = True Then AggiungiALista txtData, txtDenaro, txtCommento, lstLibretto.ListIndex
  115. End Sub
  116.  
  117. Private Sub cmdInserisci_Click()
  118. Dim I As Integer
  119.     If Controllo = True Then
  120.             For I = lstLibretto.ListCount To lstLibretto.ListIndex Step -1
  121.                 lstLibretto.List(I) = lstLibretto.List(I - 1)
  122.             Next I
  123.         AggiungiALista txtData, txtDenaro, txtCommento, lstLibretto.ListIndex
  124.     End If
  125. End Sub
  126.  
  127. 'MENU FILE  ########################################################################################################
  128.  
  129. Private Sub flApri_Click()
  130. Dim Dati As recLibretto
  131. Dim Testa As Intestazione
  132. Dim Avanzati() As String
  133.     If ControlloModifica = vbCancel Then Exit Sub
  134. CDialog.ShowOpen
  135.     If CDialog.CancelError = True Then Exit Sub
  136. XCorso = CDialog.FileName
  137. Me.Caption = CDialog.FileTitle & " - Libretto Contabile"
  138. Open XCorso For Random As 1 Len = Len(Dati)
  139. Get #1, , Testa
  140. Nome = Testa.Nome
  141. lblNome.Caption = "Intestatario libretto: " & Nome
  142. Password = StrReverse(Testa.Password)
  143.     If Password <> "" Then
  144.         frmPassword.cmdAzione.Caption = "&OK"
  145.         frmPassword.Show 1
  146.             If frmPassword.StatoPassword = False Then GoTo Fine
  147.     End If
  148. lstLibretto.Clear
  149.     Do While EOF(1) = False
  150.         Get 1#, , Dati
  151.         AggiungiALista Dati.Data, CStr(Dati.Denaro), Dati.Commento, lstLibretto.ListCount
  152.     Loop
  153.     If lstLibretto.ListCount <> 0 Then lstLibretto.RemoveItem lstLibretto.ListCount - 1
  154. Modifica = False
  155. Fine:
  156. Close
  157. End Sub
  158.  
  159. Private Sub flEsci_Click()
  160.     If ControlloUscita = False Then End
  161. End Sub
  162.  
  163. Private Sub flNuovo_Click()
  164.     If ControlloModifica = vbCancel Then Exit Sub
  165. txtData = ""
  166. txtDenaro = ""
  167. txtCommento = ""
  168. lstLibretto.Clear
  169. End Sub
  170.  
  171. Private Sub flSalva_Click()
  172.     If XCorso = "" Then
  173.         flSalvaNome_Click
  174.         Exit Sub
  175.     End If
  176. Salva XCorso
  177. End Sub
  178.  
  179. Private Sub flSalvaNome_Click()
  180. CDialog.ShowSave
  181.     If CDialog.CancelError = True Then Exit Sub
  182. XCorso = CDialog.FileName
  183. Salva XCorso
  184. End Sub
  185.  
  186. Private Sub flStampa_Click()
  187. Dim I As Integer
  188. CDialogTxt.ShowSave
  189.     If CDialogTxt.CancelError = True Then Exit Sub
  190. Open CDialogTxt.FileName For Output As 1
  191. Print #1, "LIBRETTO CONTABILE DI: " & Nome & vbTab & "AMMONTARE: " & Ammontare
  192. Print #1, vbCrLf
  193.     For I = 0 To lstLibretto.ListCount - 1
  194.         Print #1, lstLibretto.List(I)
  195.     Next I
  196. Print #1, vbCrLf
  197. Print #1, "Per una migliore visualizzazione del testo si consiglia di utilizzare il caratte: ""Courier New"""
  198. Close
  199. End Sub
  200.  
  201. 'FORM ###############################################################################################################
  202.  
  203. Private Sub Form_Load()
  204. Me.Hide
  205. frmIntestazioneLibretto.Show
  206. lstLibretto_LostFocus
  207. End Sub
  208.  
  209. Private Sub Form_Unload(Cancel As Integer)
  210.     If ControlloUscita = True Then Cancel = 1
  211. End Sub
  212.  
  213. 'LISTA  #############################################################################################################
  214.  
  215. Private Sub lstLibretto_Click()
  216. Dim Dati() As String
  217. Dati = Split(lstLibretto.List(lstLibretto.ListIndex), vbTab)
  218. txtData = Dati(0)
  219. txtDenaro = Dati(1)
  220. txtCommento = Dati(2)
  221. End Sub
  222.  
  223. Private Sub lstLibretto_GotFocus()
  224. cmdElimina.Enabled = True
  225. cmdInserisci.Enabled = True
  226. cmdModifica.Enabled = True
  227.     If lstLibretto.ListIndex = -1 Then lstLibretto_LostFocus
  228. End Sub
  229.  
  230. Private Sub lstLibretto_LostFocus()
  231. cmdElimina.Enabled = False
  232. cmdInserisci.Enabled = False
  233. cmdModifica.Enabled = False
  234.     If lstLibretto.ListIndex <> -1 Then lstLibretto_GotFocus
  235. End Sub
  236.  
  237. 'MENU  ##############################################################################################################
  238.  
  239. Private Sub pasElimina_Click()
  240. frmPassword.cmdAzione.Caption = "Elimina Password"
  241. frmPassword.Show 1
  242. End Sub
  243.  
  244. Private Sub pasInserisci_Click()
  245.     If Password <> "" Then
  246.         MsgBox "Password già esistente!" & vbCrLf & "Prima impostare una nuova password eliminare quella esistente" & vbCrLf & vbCrLf & "In caso di dimenticanza della password contattare il fornitore del programma", vbExclamation
  247.         Exit Sub
  248.     End If
  249. frmPassword.cmdAzione.Caption = "Inserisci Password"
  250. frmPassword.lblPassword.Visible = True
  251. frmPassword.txtPassword(1).Visible = True
  252. frmPassword.Show 1
  253. End Sub
  254.  
  255. Private Sub modNome_Click()
  256. Nome = InputBox("Inserisci il nuovo nome dell' intestatario del Libretto", , Nome)
  257. lblNome.Caption = "Intestatario libretto: " & Nome
  258. Modifica = True
  259. End Sub