Hallo,
ich suche nach einer besseren kürzeren Möglichkeit für nachstehenden Code.
Dieser soll die Label Captions zu Laufzeit ändern und speichern, dami Sie beim nächsten Programmaufruf wieder geändert zu Verfügung stehen.
Ich habe das jetzt so gemacht, es funzt auch nur das Ganze geht bestimmt auch kürzer oder ?
Code für Form1:
Option Explicit
Public ind As Integer
Dim setting As String
Dim F As Integer
Private Sub Command1_Click()
saveSet
Me.Hide
Unload Me
End Sub
Private Sub Command2_Click()
For ind = 0 To Label1.Count - 1
Label1(ind).Caption = "leer"
Next
End Sub
Private Sub Form_Load()
setting = App.Path & "\Setting.txt"
If FileExists(setting) = True Then
readSet
Else
For ind = 0 To Label1.Count - 1
Label1(ind).Caption = "leer"
Next
Call MsgBox("Setting.txt konnte nicht gefunden werden und wurde neu angelegt " & _
"", vbOKOnly + vbExclamation + vbSystemModal + vbDefaultButton1, "Hinweis -" & _
"Setting.txt")
saveSet
End If
End Sub
Private Sub Form_Unload(Cancel As Integer)
saveSet
End Sub
Private Sub Label1_Click(Index As Integer)
ind = (Index)
Load Form2
Form2.Show
End Sub
Public Function saveSet()
'Settings.txt Speichern
Dim F As Integer
F = FreeFile
setting = App.Path & "\Setting.txt"
Open setting For Output As #F
Print #F, Label1(0).Caption
Print #F, Label1(1).Caption
Print #F, Label1(2).Caption
Print #F, Label1(3).Caption
Print #F, Label1(4).Caption
Print #F, Label1(5).Caption
Close F
End Function
Public Function readSet()
setting = App.Path & "\Setting.txt"
'Settings.txt einlesen
Dim F As Integer
Dim Zeile0 As String
Dim Zeile1 As String
Dim Zeile2 As String
Dim Zeile3 As String
Dim Zeile4 As String
Dim Zeile5 As String
F = FreeFile
Open setting For Input As #F
Line Input #F, Zeile0
Line Input #F, Zeile1
Line Input #F, Zeile2
Line Input #F, Zeile3
Line Input #F, Zeile4
Line Input #F, Zeile5
'Settings aus Settings.txt zuordnen
Label1(0).Caption = Zeile0
Label1(1).Caption = Zeile1
Label1(2).Caption = Zeile2
Label1(3).Caption = Zeile3
Label1(4).Caption = Zeile4
Label1(5).Caption = Zeile5
Close F
End Function
Public Function FileExists(ByVal sFile As String) As Boolean
'Der Parameter sFile enthält den zu prüfenden Dateinamen
Dim Size As Long
On Local Error Resume Next
Size = FileLen(sFile)
FileExists = (Err = 0)
On Local Error GoTo 0
End Function Code für Form2:
Option Explicit
Dim n As String
Dim save As String
Private Sub Command1_Click()
Form1.Label1(n).Caption = Text1.Text
save = Form1.saveSet
Me.Hide
Unload Me
End Sub
Private Sub Command2_Click()
Me.Hide
Unload Me
End Sub
Private Sub Form_Load()
n = Form1.ind
End Sub Bin für jede Hilfe dankbar
Grüsse Mike |