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
Agenda - Frmagenda.frm

Frmagenda.frm

Caricato da: Albertking82
Scarica il programma completo

  1. Option Explicit
  2. Public linea As String
  3. Public cont As Integer
  4. Public i As Integer
  5.  
  6. Public Sub init()
  7. 'procedura che pulisce tutte le caselle di testo"
  8. 'all'apertura del form si carica un suono
  9. 'il tasto salva è disabilitato
  10.  Dim n As Integer
  11.   Frmagenda.BackColor = vbGreen
  12.   suono.FileName = App.path & "\drin.wav"
  13.   n = FreeFile
  14.   Txtnome.Text = ""
  15.   Txtcognome.Text = ""
  16.   Txttelefono.Text = ""
  17.   Txtnumero.Text = ""
  18.   Txtcognome.TabIndex = 1
  19.   Txtnome.TabIndex = 2
  20.   Txttelefono.TabIndex = 3
  21.   Txtnumero.TabIndex = 4
  22.   Cmdsalva.Enabled = False
  23.   optnome.Visible = False
  24.   optcognome.Visible = False
  25.   Cmdtrovaper.Visible = False
  26. End Sub
  27. Private Sub cmdesci_Click()
  28. If MsgBox("Sei sicuro di voler abbandonare il programma?", vbQuestion + vbYesNoCancel, "Esci") = vbYes Then
  29.   End
  30. End If
  31. End Sub
  32.  
  33. Private Sub cmdmod_Click()
  34. 'questa procedura mette nella posizione corrente del record
  35. 'l'elemento selezionato dall'utente nella lista'
  36. 'mette il contenuto della riga nella 3 caselle di testo
  37. 'disabilita il bottone modifica
  38.  'Dim space As String, contatto As String
  39.  'Dim numero As Integer
  40.  'numero = FreeFile
  41.  'space = "     "
  42.     'With contatti(cont)
  43.      '.cognome = Trim(LCase(Txtcognome.Text))
  44.      '.nome = Trim(LCase(Txtnome.Text))
  45.      '.tel = Trim(LCase(Txttelefono)) & " \ " & Trim(LCase(Txtnumero.Text))
  46.     ' End With
  47.     'Open path For Append As #numero
  48.       'Print #numero, contatto
  49.     'Close #numero
  50.     'Txtnumero.Text = ""
  51.     'Txtcognome.Text = ""
  52.     'Txtnome.Text = ""
  53.     'Txttelefono.Text = ""
  54.   'cmdmod.Visible = False
  55.  
  56. End Sub
  57.  
  58. Private Sub Cmdsalva_Click()
  59. 'salva il contenuto delle caselle di testo
  60. 'lo scrive in coda al file'
  61. 'pulisce le caselle di testo
  62.  Dim space As String, contatto As String
  63.  Dim numero As Integer
  64.  numero = FreeFile
  65.  space = "     "
  66.   If MsgBox("Sei sicuro di salvare il contatto?", vbQuestion + vbYesNoCancel, "&Salva") = vbYes Then
  67.     cont = cont + 1
  68.     Lblcancella.Enabled = True
  69.     ReDim Preserve contatti(1 To cont) As lista
  70.      With contatti(cont)
  71.      .cognome = Trim(LCase(Txtcognome.Text))
  72.      .nome = Trim(LCase(Txtnome.Text))
  73.      .tel = Trim(LCase(Txttelefono)) & " \ " & Trim(LCase(Txtnumero.Text))
  74.      End With
  75.     contatto = contatti(cont).cognome & contatti(cont).nome _
  76.              & contatti(cont).tel
  77.     listagenda.AddItem contatto
  78.     Label1.Visible = True
  79.     Label2.Visible = True
  80.     Label3.Visible = True
  81.     listagenda.Visible = True
  82.     Open path For Append As #numero
  83.       Print #numero, contatto
  84.     Close #numero
  85.     Txtnumero.Text = ""
  86.     Txtcognome.Text = ""
  87.     Txtnome.Text = ""
  88.     Txttelefono.Text = ""
  89.   Else
  90.     Exit Sub
  91.   End If
  92. End Sub
  93.  
  94. Private Sub Cmdtrovaper_Click()
  95. 'cambia la proprietà caption del form trova
  96. ' a seconda della selezione dell'utente
  97. If optnome.Value = True Then
  98.  Frmtrova.Caption = "Trova Nome"
  99. Else
  100.  Frmtrova.Caption = "Trova Cognome"
  101.  End If
  102. Frmtrova.Show
  103. End Sub
  104.  
  105. Private Sub cmdvedi_Click()
  106. 'legge il contenuto del file
  107. 'e lo scrive nella textbox del form contatti
  108.  Dim nu As Integer, line As String, c As Integer
  109.  Dim tline As String
  110.   nu = FreeFile
  111.   Open path For Input As #nu
  112.    While Not EOF(nu)
  113.     Line Input #nu, line
  114.     Frmcontatti.Txtlista.Text = Frmcontatti.Txtlista.Text & line
  115.    Wend
  116.   Close #nu
  117.    If Trim(Frmcontatti.Txtlista.Text) <> "" Then
  118.      Frmcontatti.Show
  119.      Frmagenda.Enabled = False
  120.    Else
  121.      MsgBox "La lista è vuota!", vbInformation, "Lista vuota"
  122.    End If
  123. End Sub
  124.  
  125. Private Sub Form_Load()
  126. 'percorso del file
  127. 'e procedura iniziale
  128.   path = "c:\agenda.dat"
  129.   Open path For Random As #1
  130.   Close #1
  131.   Call init
  132. End Sub
  133.  
  134. Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
  135. If MsgBox("Sei sicuro di voler abbandonare il programma?", vbQuestion + vbYesNoCancel, "Esci") = vbYes Then
  136.   End
  137.   Else
  138.   Cancel = True
  139. End If
  140.  
  141. End Sub
  142.  
  143. Private Sub Lblcancella_Click()
  144. 'cancella l'elemento selezionato dall'utente
  145. 'ed aggiorna il file riscrivendolo senza l'elemento eliminato
  146.  Dim numero3 As Integer
  147.  Dim r As Integer, j As Integer
  148.   If listagenda.ListIndex <> -1 And listagenda.ListCount <> 0 Then
  149.   r = MsgBox("Sei sicuro di voler eliminare l'elemento selezionato?", vbQuestion + vbYesNo, "Elimina file")
  150.     If r = vbYes Then
  151.        listagenda.RemoveItem listagenda.ListIndex
  152.        numero3 = FreeFile
  153.          Open path For Output As #numero3
  154.            For j = 0 To (listagenda.ListCount - 1)
  155.               Print #numero3, listagenda.List(j)
  156.            Next j
  157.          Close #numero3
  158.     End If
  159.   End If
  160. End Sub
  161.  
  162. Private Sub Lblinserisci_Click()
  163. Call init
  164. Label1.Visible = False
  165. Label2.Visible = False
  166. Label3.Visible = False
  167. listagenda.Visible = False
  168. Txtcognome.SetFocus
  169. End Sub
  170.  
  171. Private Sub Lblmodifica_Click()
  172. Dim newriga As String, b As Integer, j As Integer
  173. Dim lines As String, co As Integer
  174. Dim lista2 As String, lines2 As String, l As String
  175. Dim numero6 As Integer
  176. numero6 = FreeFile
  177. Cmdsalva.Enabled = False
  178. Lblcancella.Enabled = False
  179. cont = cont + 1
  180. ReDim Preserve contatti(1 To cont) As lista
  181. With contatti(cont)
  182.  .cognome = Trim(LCase(Txtcognome.Text))
  183.  .nome = Trim(LCase(Txtnome.Text))
  184.  .tel = Trim(LCase(Txttelefono.Text)) & " \ " & Trim(LCase(Txtnumero.Text))
  185.  End With
  186. newriga = contatti(cont).cognome & contatti(cont).nome & contatti(cont).tel
  187. Frmagenda.listagenda.List(listagenda.ListIndex) = newriga
  188. cont = 0
  189. Open path For Input As #numero6
  190.               Line Input #numero6, l
  191.               cont = cont + 1
  192.               ReDim Preserve contatti(1 To cont) As lista
  193.               With contatti(cont)
  194.                  .cognome = Trim(LCase(Txtcognome.Text))
  195.                  .nome = Trim(LCase(Txtnome.Text))
  196.                  .tel = Trim(LCase(Txttelefono)) & " \ " & Trim(LCase(Txtnumero.Text))
  197.                   End With
  198.            Close #6
  199. Txtnumero.Text = ""
  200. Txttelefono.Text = ""
  201. Txtcognome.Text = ""
  202. Txtnome.Text = ""
  203. Cmdsalva.Enabled = False
  204. 'cmdmod.Visible = True
  205. End Sub
  206.  
  207. Private Sub Lbltrova_Click()
  208. optcognome.Visible = True
  209. optnome.Visible = True
  210. Cmdtrovaper.Visible = True
  211. End Sub
  212.  
  213. Private Sub Optcel_Click()
  214. scelta = "cellulare"
  215. Cmdtrovaper.Enabled = True
  216. End Sub
  217.  
  218. Private Sub listagenda_Click()
  219. Cmdsalva.Enabled = False
  220. If Frmagenda.listagenda.ListIndex > -1 Then
  221.  Lblcancella.Enabled = True
  222.  End If
  223. End Sub
  224.  
  225. Private Sub listagenda_DblClick()
  226. Dim frase As String
  227. Dim j As Integer, numer As Integer
  228.  numer = FreeFile
  229.  Cmdsalva.Enabled = False
  230.  i = Frmagenda.listagenda.ListIndex
  231. If i > -1 Then
  232.   frase = listagenda.List(listagenda.ListIndex)
  233.  If MsgBox("Vuoi modificare il contatto?", vbQuestion + vbYesNoCancel, "Modifica") = vbYes Then
  234.          'frase = listagenda.List(listagenda.ListIndex)
  235.          Lblcancella.Enabled = False
  236.          Txtcognome.Text = Mid(frase, 1, 20)
  237.          Txtnome.Text = Mid(frase, 21, 20)
  238.          Txttelefono.Text = Trim(Mid(frase, 40, 6))
  239.          Txtnumero.Text = Trim(Mid(frase, 46, 20))
  240.          Cmdsalva.Enabled = False
  241.        Close #numer
  242.        End If
  243.   End If
  244. End Sub
  245.  
  246. Private Sub optcognome_Click()
  247. scelta = "cognome"
  248. Cmdtrovaper.Enabled = True
  249. End Sub
  250.  
  251. Private Sub optnome_Click()
  252. scelta = "nome"
  253. Cmdtrovaper.Enabled = True
  254. End Sub
  255.  
  256. Private Sub Txtcognome_Change()
  257. If Cmdsalva.Enabled = False Then
  258.    Cmdsalva.Enabled = False
  259.    End If
  260.  If Txtcognome.Text <> "" And Txtnome.Text <> "" And Txttelefono.Text <> "" And Txtnumero <> "" Then
  261.    Cmdsalva.Enabled = True
  262.  Else
  263.    Cmdsalva.Enabled = False
  264.  End If
  265. End Sub
  266.  
  267. Private Sub Txtnome_Change()
  268. If Cmdsalva.Enabled = False Then
  269.    Cmdsalva.Enabled = False
  270.    End If
  271.   If Txtcognome.Text <> "" And Txtnome.Text <> "" And Txttelefono.Text <> "" And Txtnumero <> "" Then
  272.    Cmdsalva.Enabled = True
  273.  Else
  274.    Cmdsalva.Enabled = False
  275.  End If
  276. End Sub
  277.  
  278. Private Sub Txtnumero_Change()
  279. If Cmdsalva.Enabled = False Then
  280.    Cmdsalva.Enabled = False
  281.    End If
  282. If Not IsNumeric(Txtnumero.Text) Then
  283. Txtnumero.Text = ""
  284. End If
  285.  If Txtcognome.Text <> "" And Txtnome.Text <> "" And Txttelefono.Text <> "" And Txtnumero <> "" Then
  286.    Cmdsalva.Enabled = True
  287.  Else
  288.    Cmdsalva.Enabled = False
  289.  End If
  290. End Sub
  291.  
  292. Private Sub Txtnumero_KeyDown(keycode As Integer, Shift As Integer)
  293. Call controlkeys(keycode)
  294. End Sub
  295.  
  296. Private Sub Txttelefono_Change()
  297. If Cmdsalva.Enabled = False Then
  298.    Cmdsalva.Enabled = False
  299.    End If
  300. If Not IsNumeric(Txttelefono.Text) Then
  301. Txttelefono.Text = ""
  302. End If
  303.  If Txtcognome.Text <> "" And Txtnome.Text <> "" And Txttelefono.Text <> "" And Txtnumero <> "" Then
  304.    Cmdsalva.Enabled = True
  305.  Else
  306.    Cmdsalva.Enabled = False
  307.  End If
  308. End Sub
  309.  
  310. Private Sub Txttelefono_KeyDown(keycode As Integer, Shift As Integer)
  311. Call controlkeys(keycode)
  312. End Sub
  313. Public Sub controlkeys(keycode)
  314. If keycode > 47 And keycode < 58 Then
  315. suono.FileName = App.path & "\bip.wav"
  316. Else
  317. Exit Sub
  318. End If
  319. End Sub