Ik ben bezig met een programma waarmee je de winst kan berekenen, de ingevoerde waarden zoals bedragen en namen worden incl. key voor de listbox en datum opgslagen in een .ini bestand. Ik heb twee bestanden gebruikt, een voor de inkomsten en een voor de uitgaven. Het probleem is dat ik wel twee items kan toevoegen maar bij de derde krijg ik de foutmelding Key is not a unique collection Ik ben 3 keer door de hele code gegaan, maar ik kan er maar niet achter komen waar ik de fout in ben gegaan.
Hier wordt het item toegevoegd:
Op deze knop(1) wordt gedrukt om de het form met de bovenstaande code te laden
De onderstaande subroutines gebruik ik om de waarden uit de bestanden te halen en er naartoe te schrijven.
Wanneer ik begin met lege files gaat het bij de derde keer in regel 36 van de module fout
Ik d8 dat het komt omdat de nieuwe items niet onderaan in de lijst worden toegevoegd, daarom heb ik de regel frmMutaties.lstMutaties.ListItems.Count + 1 toegevoegd aan regel 36 maar dat werkt niet
.
Hier wordt het item toegevoegd:
Visual Basic:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
| Private Sub cmdAdd_Click() Dim NewKey As String If IsNumeric(txtValue.Text) = True Then NewKey = "Key" & CStr(CInt(Right(MutatieKey, Len(MutatieKey) - 3) + 1)) Select Case frmMutaties.lblComment(0).Caption Case "Uitgaven" Datum = DTPicker1.Value Open App.Path & "\uitgaven.ini" For Append As #1 Write #1, NewKey, txtName.Text, txtValue.Text, Datum Close #1 Call Module1.UpdateMutaties("Uitgaven") Case "Inkomsten" Datum = DTPicker1.Value Open App.Path & "\inkomsten.ini" For Append As #1 Write #1, NewKey, txtName.Text, txtValue.Text, Datum Close #1 Call Module1.UpdateMutaties("Inkomsten") End Select Unload Me Else End If End Sub |
Op deze knop(1) wordt gedrukt om de het form met de bovenstaande code te laden
Visual Basic:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
| Private Sub cmdAddRemove_Click(Index As Integer) Select Case Index Case 0 lstMutaties.ListItems.Remove (lstMutaties.SelectedItem.Index) Call Module1.SaveMutaties("Inkomsten") cmdAddRemove(0).Enabled = False Case 1 Load frmAddMutatie If lstMutaties.ListItems.Count <> 0 Then frmAddMutatie.MutatieKey = lstMutaties.ListItems(lstMutaties.ListItems.Count).Key Me.Caption = frmAddMutatie.MutatieKey Else frmAddMutatie.MutatieKey = "Key00" End If End Select End Sub |
De onderstaande subroutines gebruik ik om de waarden uit de bestanden te halen en er naartoe te schrijven.
Visual Basic:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
| Public Sub SaveMutaties(Soort As String) Dim Newmutatie As ListItem Dim Nummer As Integer Nummer = 1 Select Case Soort Case "Inkomsten" Open App.Path & "\inkomsten.ini" For Output As #1 If frmMutaties.lstMutaties.ListItems.Count <> 0 Then Do Write #1, frmMutaties.lstMutaties.ListItems(Nummer).Key, frmMutaties.lstMutaties.ListItems(Nummer).Text, frmMutaties.lstMutaties.ListItems(Nummer).SubItems(1), frmMutaties.lstMutaties.ListItems(Nummer).SubItems(2) Nummer = Nummer + 1 Loop Until Nummer > frmMutaties.lstMutaties.ListItems.Count End If Close 1 Case "Uitgaven" Open App.Path & "\uitgaven.ini" For Output As #1 If frmMutaties.lstMutaties.ListItems.Count <> 0 Then Do Write #1, frmMutaties.lstMutaties.ListItems(Nummer).Key, frmMutaties.lstMutaties.ListItems(Nummer).Text, frmMutaties.lstMutaties.ListItems(Nummer).SubItems(1), frmMutaties.lstMutaties.ListItems(Nummer).SubItems(2) Nummer = Nummer + 1 Loop Until Nummer > frmMutaties.lstMutaties.ListItems.Count End If Close 1 End Select End Sub Public Sub UpdateMutaties(Soort As String) frmMutaties.lstMutaties.ListItems.Clear Dim Newmutatie As ListItem Select Case Soort Case "Inkomsten" Open App.Path & "\inkomsten.ini" For Input As #1 Do While Not EOF(1) Input #1, strKey, strText, strValue, strDatum Set Newmutatie = frmMutaties.lstMutaties.ListItems.Add(frmMutaties.lstMutaties.ListItems.Count + 1, strKey, strText) Newmutatie.SubItems(1) = strValue Newmutatie.SubItems(2) = strDatum Loop Close 1 Case "Uitgaven" Open App.Path & "\uitgaven.ini" For Input As #1 Do While Not EOF(1) Input #1, strKey, strText, strValue, strDatum Set Newmutatie = frmMutaties.lstMutaties.ListItems.Add(frmMutaties.lstMutaties.ListItems.Count + 1, strKey, strText) Newmutatie.SubItems(1) = strValue Newmutatie.SubItems(2) = strDatum Loop Close 1 End Select End Sub |
Wanneer ik begin met lege files gaat het bij de derde keer in regel 36 van de module fout
Ik d8 dat het komt omdat de nieuwe items niet onderaan in de lijst worden toegevoegd, daarom heb ik de regel frmMutaties.lstMutaties.ListItems.Count + 1 toegevoegd aan regel 36 maar dat werkt niet
[ Voor 11% gewijzigd door Verwijderd op 26-03-2003 09:02 ]