If Label5.Caption = "0" Then
Open "C:/nomefile.txt" For Output As #1
Print #1, Label5.Caption
Close #1
Else
Randomize
e = 789 'Assegnazione valore alla variabile
f = 34 'Assegnazione valore alla variabile
g = Int((f * 3 + 4 - 6 + e * 1) * Rnd) + e
Label5.Caption = g
Open "c:/nomefile.txt" For Output As #1
Print #1, g
Close #1
End If
If Label5.Caption = "0" Then
Open "C:/nomefile.txt" For Output As #1
Print #1, Label5.Caption
Close #1
Else
Randomize
e = 789 'Assegnazione valore alla variabile
f = 34 'Assegnazione valore alla variabile
g = Int((f * 3 + 4 - 6 + e * 1) * Rnd) + e
Label5.Caption = g
Open "c:/nomefile.txt" For Output As #1
Print #1, g
Close #1
End If
ma mi viene sempre un codice diverso
Te non devi controllare se la label ha un codice diverso(almeno da qll ke ho capito dalla spiegazione che hai dato) ma devi controllare se il file che contiene il codice esiste...facendo così:
if Exists("nomefile") 'Mi sembra che è Exists quello da utilizzare :-| then
'leggi il codice dal file
else
'fai un random e poi salvi il random nel file
end if
If Dir("C:/nomefile.txt") = "" Then
Randomize
e = 789 'Assegnazione valore alla variabile
f = 34 'Assegnazione valore alla variabile
g = Int((f * 3 + 4 - 6 + e * 1) * Rnd) + e
Label5.Caption = g
Open "c:/nomefile.txt" For Output As #1
Print #1, Label5.Caption
Close #1
Else
Open "C:/nomefile.txt" For Output As #1
Print #1, Label5.Caption
Close #1
End If
If Dir("C:/nomefile.txt") = "" Then
Randomize
e = 789 'Assegnazione valore alla variabile
f = 34 'Assegnazione valore alla variabile
g = Int((f * 3 + 4 - 6 + e * 1) * Rnd) + e
Label5.Caption = g
Open "c:/nomefile.txt" For Output As #1
Print #1, Label5.Caption
Close #1
Else
Open "C:/nomefile.txt" For Output As #1
Print #1, Label5.Caption
Close #1
End If
Ma il label 5 non mostra nessun numero.
Vedendo che mi salvava il file in entrambi casi ho provato anche a farlo così:
Private Sub Form_Load()
If Dir("C:/nomefile.txt") = "" Then
Randomize
e = 789 'Assegnazione valore alla variabile
f = 34 'Assegnazione valore alla variabile
g = Int((f * 3 + 4 - 6 + e * 1) * Rnd) + e
Label5.Caption = g
Open "c:/nomefile.txt" For Output As #1
Print #1, Label5.Caption
Close #1
Else
Open ("C:/nomefile.txt") For Input As #1
Label5.Caption = Input(LOF(1), #1)
Close #1
End If
End Sub