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
Visual Basic 6 - Problema con i file.dat
Forum - Visual Basic 6 - Problema con i file.dat

Avatar
Giuan (Normal User)
Newbie


Messaggi: 7
Iscritto: 04/05/2012

Segnala al moderatore
Postato alle 20:31
Venerdì, 04/05/2012
Allora ragazzi,ho dei grossi problemi,dato che sono passato da studiare il c++ al visual basic...Premetto che quello che vi mostrerò,sarà un programmino in grado di salvare,modificare,o aggiungere nome,cognome,numero di matricola degli alunni di una scuola...Il mio problema,per quanto ora io sappia,è che dopo aver creato la struttura,dichiarato il buffer,non riesco a creare il file,o meglio dovrebbe crearmelo,ma mi dà errore sulla dichiarazione del buffer...Non so come procedere...Un aiuto,ma soprattutto ulteriori chiarimenti mi sarebbero molto grati,dato che i professori di oggi,si divertono a non spiegare più nulla...


Ultima modifica effettuata da Giuan il 04/05/2012 alle 20:39
PM Quote
Avatar
nessuno (Normal User)
Guru^2


Messaggi: 6403
Iscritto: 03/01/2010

Segnala al moderatore
Postato alle 20:46
Venerdì, 04/05/2012
Sei sicuro che parliamo di VB6 o no ?


Ricorda che nessuno è obbligato a risponderti e che nessuno è perfetto ...
---
Il grande studioso italiano Bruno de Finetti ( uno dei padri fondatori del moderno Calcolo delle probabilità ) chiamava il gioco del Lotto Tassa sulla stupidità.
PM Quote
Avatar
Giuan (Normal User)
Newbie


Messaggi: 7
Iscritto: 04/05/2012

Segnala al moderatore
Postato alle 20:56
Venerdì, 04/05/2012
Sisi sicurissimo,parliamo di VB6 tranuquillo

PM Quote
Avatar
nessuno (Normal User)
Guru^2


Messaggi: 6403
Iscritto: 03/01/2010

Segnala al moderatore
Postato alle 20:58
Venerdì, 04/05/2012
Okay, allora mostra il codice e l'errore ... no ?


Ricorda che nessuno è obbligato a risponderti e che nessuno è perfetto ...
---
Il grande studioso italiano Bruno de Finetti ( uno dei padri fondatori del moderno Calcolo delle probabilità ) chiamava il gioco del Lotto Tassa sulla stupidità.
PM Quote
Avatar
Giuan (Normal User)
Newbie


Messaggi: 7
Iscritto: 04/05/2012

Segnala al moderatore
Postato alle 15:30
Domenica, 06/05/2012
Codice sorgente - presumibilmente VB.NET

  1. Option Explicit
  2. Private Type Rec
  3. Nome     As String * 40
  4. Cognome  As String * 40
  5. Classe   As String * 40
  6. Nummat   As String * 40
  7. End Type
  8. Dim R As Rec
  9. Public Filename As String
  10. Public Stringa As String
  11. Dim ultimoREC As Integer
  12.  
  13. Private Sub Form_Load()
  14. Drive1.Drive = "C:"
  15. Dir1.Path = Drive1.Drive
  16. File1.Path = Dir1.Path
  17. Txtpercorso = Dir1.Path
  18. End Sub
  19.  
  20. Private Sub Command1_Click()
  21. If (Option1 = True) Then
  22. Form1.Show
  23. End If
  24.  
  25. If (Text1.Text = "") And (Option2 = True) Then
  26. MsgBox ("Immetti nome!!"), vbOKOnly, "      Error"
  27.  
  28. Else: Txtpercorso.Text = Dir1.Path + Text1.Text + ".dat"
  29.       Stringa = Txtpercorso.Text
  30.       Text1.Text = Stringa
  31.       Form1.Show
  32. End If
  33. End Sub
  34.  
  35. Private Sub Dir1_Change()
  36. File1 = Dir1
  37. Txtpercorso.Text = Dir1.Path + Filename
  38. End Sub
  39.  
  40. Private Sub Drive1_Change()
  41. Dir1 = Drive1
  42. Txtpercorso.Text = Dir1.Path + Filename
  43. End Sub
  44.  
  45. Private Sub File1_Click()
  46. Filename = File1
  47. Txtpercorso.Text = Dir1.Path + "\" + Filename
  48. End Sub
  49.  
  50. Private Sub Option1_Click()
  51. Option1.Enabled = True
  52. If (Option1 = True) Then
  53. Text1.Visible = False
  54. File1.Visible = True
  55. End If
  56. End Sub
  57.  
  58. Private Sub Option2_Click()
  59. Option2.Enabled = True
  60. If (Option2 = True) Then
  61. File1.Visible = False
  62. Text1.Visible = True
  63. End If
  64. End Sub
  65.  
  66.  
  67. Private Sub Txtpercorso_Change()
  68. Stringa = Txtpercorso.Text
  69. End Sub





Codice sorgente - presumibilmente VB.NET

  1. Dim mystringa As String
  2. Dim lung      As Integer
  3. Dim ult       As Long
  4. Dim filenum   As Integer
  5. Dim posiz     As Long
  6.  
  7. Private Type Rec
  8. Matricola As String
  9. Nome      As String * 10
  10. Cognome   As String * 10
  11. Classe    As String * 10
  12. End Type
  13. Dim R As Rec
  14.  
  15. Private Sub Form_Load()
  16. Open Stringa For Random As #1 Len = Len(R)
  17. Get #1, 1, R
  18. List1.AddItem R.Matricola
  19. While (Not EOF(1))
  20.   Get #1, , R
  21.   lstmatricole.AddItem R.Matricola
  22. Wend
  23.   Close
  24. End Sub



il primo è il form generale....Il secondo invece è quello che si deve aprire quando clicco su creafile...come appena clicco,l'errore è il seguente:Errore di accesso al percorso file...Sono disperato ragà,aiutatemi per favore...

PM Quote
Avatar
nessuno (Normal User)
Guru^2


Messaggi: 6403
Iscritto: 03/01/2010

Segnala al moderatore
Postato alle 15:34
Domenica, 06/05/2012
Ma

Stringa

che dovrebbe contenere il nome del file (e quindi, secondo buon senso, sarebbe meglio chiamare NomeFile) è pubblica per il Form1 non per il secondo.

Se vuoi usare una variabile pubblica tra Form, inseriscila in un Modulo.


Ricorda che nessuno è obbligato a risponderti e che nessuno è perfetto ...
---
Il grande studioso italiano Bruno de Finetti ( uno dei padri fondatori del moderno Calcolo delle probabilità ) chiamava il gioco del Lotto Tassa sulla stupidità.
PM Quote
Avatar
Giuan (Normal User)
Newbie


Messaggi: 7
Iscritto: 04/05/2012

Segnala al moderatore
Postato alle 15:49
Domenica, 06/05/2012
Grazie mille,ho risolto...Per altri problemi chiedo qui...Grandissimo :)

PM Quote
Avatar
Giuan (Normal User)
Newbie


Messaggi: 7
Iscritto: 04/05/2012

Segnala al moderatore
Postato alle 18:06
Martedì, 08/05/2012
Allora ragazzi il programma procede benino,ma il mio problema ora è un altro...Mi si presenta un errore sulla funzione CARICALISTAMATRICOLE e precisamente su lstmatricole.listindex =0 "Valore di proprietà non valido" !! Allora ragazzi io ho notato quest'altra cosa,che provando a levare questo comando cio mi deve scrivere sul file quando premo il tasto salva,lo fa,ma solo al secondo click..Come mai?? Ora invece,mi presenta un problema del tipo sulla put quando salvo...mi dice lunghezza del record non valida

Codice sorgente - presumibilmente VB.NET

  1. Public Filename As String
  2.  
  3. Private Sub Form_Load()
  4. Option1.Value = True
  5. Drive1.Drive = "C:"
  6. Dir1.Path = Drive1.Drive
  7. File1.Path = Dir1.Path
  8. Txtpercorso = Dir1.Path
  9. End Sub
  10.  
  11. Private Sub Command1_Click()
  12. If (Option1 = True) Then
  13. Form1.Show
  14. ElseIf (Text1.Text = "") And (Option2 = True) Then
  15. MsgBox ("Immetti nome!!"), vbOKOnly, "      Error"
  16.  
  17. Else: Txtpercorso.Text = Dir1.Path + "\" + Text1.Text + ".dat"
  18.       NomeFile = Txtpercorso.Text
  19.       Form1.Show
  20. End If
  21. End Sub
  22.  
  23. Private Sub Dir1_Change()
  24. File1 = Dir1
  25. Txtpercorso.Text = Dir1.Path + "\" + Filename
  26. End Sub
  27.  
  28. Private Sub Drive1_Change()
  29. Dir1 = Drive1
  30. Txtpercorso.Text = Dir1.Path + "\" + Filename
  31. End Sub
  32.  
  33. Private Sub File1_Click()
  34. Filename = File1
  35. Txtpercorso.Text = Dir1.Path + "\" + Filename
  36. End Sub
  37.  
  38. Private Sub Option1_Click()
  39. Option1.Enabled = True
  40. If (Option1 = True) Then
  41. Text1.Visible = False
  42. File1.Visible = True
  43. End If
  44. End Sub
  45.  
  46. Private Sub Option2_Click()
  47. Option2.Enabled = True
  48. If (Option2 = True) Then
  49. File1.Visible = False
  50. Text1.Visible = True
  51. End If
  52. End Sub
  53.  
  54.  
  55. Private Sub Txtpercorso_Change()
  56. NomeFile = Txtpercorso.Text
  57. End Sub



Codice sorgente - presumibilmente VB.NET

  1. Option Explicit
  2. Private Type Rec
  3. Matricola As String
  4. Nome      As String
  5. Cognome   As String
  6. Classe    As String
  7. End Type
  8. Dim R As Rec
  9. Dim ultimorec As String
  10.  
  11. Private Sub Aggiungi_Click()
  12. Txtnome.Text = ""
  13. Txtcognome.Text = ""
  14. Txtmatricola.Text = ""
  15. Txtclasse.Text = ""
  16. Txtnome.Enabled = True
  17. Txtcognome.Enabled = True
  18. Txtmatricola.Enabled = True
  19. Txtclasse.Enabled = True
  20. End Sub
  21.  
  22. Private Sub Form_Load()
  23. Percorso.Text = NomeFile
  24. Visualizza.Value = True
  25. Open NomeFile For Random As #1 Len = Len(R)
  26.   If LOF(1) = 0 Then
  27.    MsgBox ("  File vuoto !!"), vbOKOnly, " Information !!"
  28.     Else: Caricalistamatricole
  29.     End If
  30. End Sub
  31.  
  32. Sub Caricalistamatricole()
  33. lstmatricole.Clear
  34.  Get #1, 1, R
  35.  While Not (EOF(1))
  36.  lstmatricole.AddItem R.Matricola
  37.  Get #1, , R
  38. Wend
  39. lstmatricole.ListIndex = 0
  40. End Sub
  41.  
  42. Sub Ordinafile()
  43. Dim i As Integer
  44. Dim j As Integer
  45. Dim r1 As Rec
  46. Dim r2 As Rec
  47. ultimorec = LOF(1) / Len(R)
  48. For i = 1 To ultimorec - 1
  49.  For j = i + 1 To ultimorec
  50.   Get #1, i, r1
  51.   Get #1, j, r2
  52.   If (r1.Matricola > r2.Matricola) Then
  53.     Put #1, i, r2
  54.     Put #1, j, r1
  55.   End If
  56.     Next j
  57.     Next i
  58.   End Sub
  59. Sub Disattiva()
  60. Txtnome.Enabled = False
  61. Txtcognome.Enabled = False
  62. Txtmatricola.Enabled = False
  63. Txtclasse.Enabled = False
  64. End Sub
  65. Sub Attiva()
  66. Txtnome.Enabled = True
  67. Txtcognome.Enabled = True
  68. Txtmatricola.Enabled = False
  69. Txtclasse.Enabled = True
  70. End Sub
  71.  
  72.  
  73. Private Sub lstmatricole_Click()
  74. Dim x As Integer
  75.  x = lstmatricole.ListIndex + 1
  76.  Get #1, x, R
  77.  Txtnome.Text = R.Nome
  78.  Txtcognome.Text = R.Cognome
  79.  Txtclasse.Text = R.Classe
  80.  Txtmatricola.Text = R.Matricola
  81. End Sub
  82.  
  83. Private Sub Modifica_Click()
  84. If (Modifica.Enabled = True) And (lstmatricole.ListCount > 0) Then
  85. Attiva
  86. Else:  MsgBox ("Nessuna matricola presente!!"), vbOKOnly, "  Information !!"
  87.        Aggiungi.Value = True
  88. End If
  89. Dim x As Integer
  90. x = lstmatricole.ListIndex + 1
  91. Txtcognome.Text = R.Cognome
  92. Txtnome.Text = R.Nome
  93. Txtclasse.Text = R.Classe
  94. Txtmatricola.Text = R.Matricola
  95. End Sub
  96.  
  97. Private Sub Pulisci_Click()
  98. Txtnome.Text = ""
  99. Txtcognome.Text = ""
  100. Txtmatricola.Text = ""
  101. Txtclasse.Text = ""
  102. End Sub
  103.  
  104. Private Sub prec_Click()
  105. If (lstmatricole.ListCount > 0) Then
  106. If lstmatricole.ListIndex = 0 Then
  107.   lstmatricole.ListIndex = lstmatricole.ListCount - 1
  108. Else: lstmatricole.ListIndex = lstmatricole.ListIndex - 1
  109. End If
  110. Else: MsgBox ("Nessuna matricola presente!!"), vbOKOnly, "  Information !!"
  111. End If
  112. End Sub
  113.  
  114. Private Sub primo_Click()
  115. If (lstmatricole.ListCount > 0) Then
  116. lstmatricole.ListIndex = 0
  117. Else: MsgBox ("Nessuna matricola presente!!"), vbOKOnly, "  Information !!"
  118. End If
  119. End Sub
  120. Private Sub succ_Click()
  121. If (lstmatricole.ListCount > 0) Then
  122.  If lstmatricole.ListIndex = lstmatricole.ListCount - 1 Then
  123.   lstmatricole.ListIndex = 0
  124. Else: lstmatricole.ListIndex = lstmatricole.ListIndex + 1
  125. End If
  126.  Else: MsgBox ("Nessuna matricola presente!!"), vbOKOnly, "  Information !!"
  127. End If
  128. End Sub
  129.  
  130.  
  131.  
  132.  
  133.  
  134. Private Sub ultimo_Click()
  135. If (lstmatricole.ListCount > 0) Then
  136. lstmatricole.ListIndex = lstmatricole.ListCount - 1
  137. Else: MsgBox ("Nessuna matricola presente!!"), vbOKOnly, "  Information !!"
  138. End If
  139. End Sub
  140.  
  141. Private Sub Salva_Click()
  142.   If (Aggiungi.Value = True) Then
  143.    ultimorec = LOF(1) / Len(R)
  144.    R.Matricola = Txtmatricola.Text
  145.    R.Classe = Txtclasse.Text
  146.    R.Cognome = Txtcognome.Text
  147.    R.Nome = Txtnome.Text
  148.    Put #1, ultimorec + 1, R
  149.    Ordinafile
  150.    Caricalistamatricole
  151.    Txtnome.Text = ""
  152.    Txtcognome.Text = ""
  153.    Txtmatricola.Text = ""
  154.    Txtclasse.Text = ""
  155.    Else:
  156.          R.Nome = Txtnome.Text
  157.          R.Cognome = Txtcognome.Text
  158.          R.Classe = Txtclasse.Text
  159.          lstmatricole.AddItem R.Matricola
  160.          Put #1, lstmatricole.ListIndex + 1, R
  161.          lstmatricole.Clear
  162.          Ordinafile
  163.          Caricalistamatricole
  164.          
  165.    End If
  166. End Sub
  167.  
  168. Private Sub Uscita_Click()
  169. Close #1
  170. Form1.Hide
  171. End Sub
  172.  
  173. Private Sub Visualizza_Click()
  174. If (Visualizza.Enabled = True) Then
  175.   Disattiva
  176. End If
  177. End Sub


Ultima modifica effettuata da Giuan il 08/05/2012 alle 18:23
PM Quote