Oppure

Loading
04/05/12 18:31
Giuan
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 04/05/12 18:39
aaa
04/05/12 18:46
nessuno
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à.
04/05/12 18:56
Giuan
Sisi sicurissimo,parliamo di VB6 tranuquillo
aaa
04/05/12 18:58
nessuno
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à.
06/05/12 13:30
Giuan
Option Explicit
Private Type Rec
Nome     As String * 40
Cognome  As String * 40
Classe   As String * 40
Nummat   As String * 40
End Type
Dim R As Rec
Public Filename As String
Public Stringa As String
Dim ultimoREC As Integer

Private Sub Form_Load()
Drive1.Drive = "C:"
Dir1.Path = Drive1.Drive
File1.Path = Dir1.Path
Txtpercorso = Dir1.Path
End Sub

Private Sub Command1_Click()
If (Option1 = True) Then
Form1.Show
End If

If (Text1.Text = "") And (Option2 = True) Then
MsgBox ("Immetti nome!!"), vbOKOnly, "      Error"

Else: Txtpercorso.Text = Dir1.Path + Text1.Text + ".dat"
      Stringa = Txtpercorso.Text
      Text1.Text = Stringa
      Form1.Show
End If
End Sub

Private Sub Dir1_Change()
File1 = Dir1
Txtpercorso.Text = Dir1.Path + Filename
End Sub

Private Sub Drive1_Change()
Dir1 = Drive1
Txtpercorso.Text = Dir1.Path + Filename
End Sub

Private Sub File1_Click()
Filename = File1
Txtpercorso.Text = Dir1.Path + "\" + Filename
End Sub

Private Sub Option1_Click()
Option1.Enabled = True
If (Option1 = True) Then
Text1.Visible = False
File1.Visible = True
End If
End Sub

Private Sub Option2_Click()
Option2.Enabled = True
If (Option2 = True) Then
File1.Visible = False
Text1.Visible = True
End If
End Sub


Private Sub Txtpercorso_Change()
Stringa = Txtpercorso.Text
End Sub




Dim mystringa As String
Dim lung      As Integer
Dim ult       As Long
Dim filenum   As Integer
Dim posiz     As Long

Private Type Rec
Matricola As String
Nome      As String * 10
Cognome   As String * 10
Classe    As String * 10
End Type
Dim R As Rec

Private Sub Form_Load()
Open Stringa For Random As #1 Len = Len(R)
Get #1, 1, R
List1.AddItem R.Matricola
While (Not EOF(1))
  Get #1, , R
  lstmatricole.AddItem R.Matricola
Wend
  Close
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...
aaa
06/05/12 13:34
nessuno
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à.
06/05/12 13:49
Giuan
Grazie mille,ho risolto...Per altri problemi chiedo qui...Grandissimo :)
aaa
08/05/12 16:06
Giuan
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

Public Filename As String

Private Sub Form_Load()
Option1.Value = True
Drive1.Drive = "C:"
Dir1.Path = Drive1.Drive
File1.Path = Dir1.Path
Txtpercorso = Dir1.Path
End Sub

Private Sub Command1_Click()
If (Option1 = True) Then
Form1.Show
ElseIf (Text1.Text = "") And (Option2 = True) Then
MsgBox ("Immetti nome!!"), vbOKOnly, "      Error"

Else: Txtpercorso.Text = Dir1.Path + "\" + Text1.Text + ".dat"
      NomeFile = Txtpercorso.Text
      Form1.Show
End If
End Sub

Private Sub Dir1_Change()
File1 = Dir1
Txtpercorso.Text = Dir1.Path + "\" + Filename
End Sub

Private Sub Drive1_Change()
Dir1 = Drive1
Txtpercorso.Text = Dir1.Path + "\" + Filename
End Sub

Private Sub File1_Click()
Filename = File1
Txtpercorso.Text = Dir1.Path + "\" + Filename
End Sub

Private Sub Option1_Click()
Option1.Enabled = True
If (Option1 = True) Then
Text1.Visible = False
File1.Visible = True
End If
End Sub

Private Sub Option2_Click()
Option2.Enabled = True
If (Option2 = True) Then
File1.Visible = False
Text1.Visible = True
End If
End Sub


Private Sub Txtpercorso_Change()
NomeFile = Txtpercorso.Text
End Sub


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

Ultima modifica effettuata da Giuan 08/05/12 16:23
aaa