Toon posts:

[vb] File input ordenen op kwartaal

Pagina: 1
Acties:

Verwijderd

Topicstarter
Ik kwam erachter dat mijn vorgige brobleem simpel is op te lossen met een combobox. Maar nu zit ik met een echt probleem.

Als ik alleen de waarden van een bepaald kwartaal in de lijst zet en dan bij het updaten van de lijst het bestand weer save(zie hieronder) dan ben ik alle andere info kwijt, dus met de volgende code kan het niet, met line input heb ik ook het een en ander geprobeert maar dit lukt niet. Hoe kan ik de code aanpassen dat ik niet het hele bestand leeg gooi? Met append kan ik er wel naar toe schrijven maar dan staan alle waarden die ik er naartoe schrijf er twee keer in. Ik d8 dat er een mogelijkheid is om het op te lossen door append te gebruiken en tijdens het invoeren uit het bestand de invoer uit het bestand te verwijderen, dus een soort kopiëren naar het programma en de bron verwijderen. Weet iemand hoe ik bepaalde bytes, of regels uit een bestand kan gooien?

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
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



edit:
Vorig probleem opgelost, zie code hieronder:

code:
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
52
53
54
55
56
57
Private Sub Form_Load()
Dim Newmutatie As ListItem
Dim Nummer As Integer
Dim dblTotaal As Double
Dim intMaand As Integer
Dim intMaandNow As Integer
Dim intJaar As Integer
Dim KwNr As Integer
Dim ConfigOK As Boolean

Nummer = 1
Open App.Path & "\inkomsten.ini" For Input As #1
Open App.Path & "\config.ini" For Input As #2
If Not EOF(2) Then
Input #2, kwartaalconfig(1), kwartaalconfig(2), kwartaalconfig(3), kwartaalconfig(4)
Else
MsgBox "Het configuratiebestand ontbreekt, het programma wordt afgesloten"
End
End If
Do While Not EOF(1)
    Input #1, strKey, strText, strValue, strDatum
    intMaand = Format(strDatum, "MM")
    intJaar = Format(strDatum, "yyyy")
    intMaandNow = (Format(Date, "MM"))
    Do While Not ConfigOK = True
        KwNr = KwNr + 1
        kwartaalconfig(0) = Left(kwartaalconfig(KwNr), 2)
        If intMaandNow = kwartaalconfig(0) Then ConfigOK = True
        kwartaalconfig(0) = Mid(kwartaalconfig(KwNr), 4, 2)
        If intMaandNow = kwartaalconfig(0) Then ConfigOK = True
        kwartaalconfig(0) = Mid(kwartaalconfig(KwNr), 7, 2)
        If intMaandNow = kwartaalconfig(0) Then ConfigOK = True
        Format kwartaalconfig(0), "00"
    Loop
    ConfigOK = False
    cmbKwartaal.ListIndex = KwNr - 1
    KwNr = 0
    Do While Not ConfigOK = True
        KwNr = KwNr + 1
        kwartaalconfig(0) = Left(kwartaalconfig(KwNr), 2)
        If intMaand = kwartaalconfig(0) Then ConfigOK = True
        kwartaalconfig(0) = Mid(kwartaalconfig(KwNr), 4, 2)
        If intMaand = kwartaalconfig(0) Then ConfigOK = True
        kwartaalconfig(0) = Mid(kwartaalconfig(KwNr), 7, 2)
        If intMaand = kwartaalconfig(0) Then ConfigOK = True
        Format kwartaalconfig(0), "00"
    Loop
    If cmbKwartaal.ListIndex = KwNr - 1 Then
        Set Newmutatie = lstMutaties.ListItems.Add(, strKey, strText)
        Newmutatie.SubItems(1) = strValue
        Newmutatie.SubItems(2) = strDatum
        If Right(strKey, Len(strKey) - 3) > intMaxkeynr Then intMaxkeynr = Right(strKey, Len(strKey) - 3)
    End If
Loop
Close #1
Call Module1.CalcTotal
End Sub

[ Voor 69% gewijzigd door Verwijderd op 27-03-2003 09:09 ]


  • johnwoo
  • Registratie: Oktober 1999
  • Laatst online: 23:42

johnwoo

3S-GTE

Er zijn verschillende mogelijkheden:
1. Als je in je bestand velden van vaste lengte gebruikt, kun je em For Random of For Binary openen en de records direct in de file wijzigen. Nieuwe records append je aan het eind. Voor het verwijderen van records zal je toch wat extra code nodig hebben; je kunt een te verwijderen record bijvoorbeeld overschrijven met een nieuw toe te voegen record, maar als er niks toegevoegd hoeft te worden zal je toch methode 2 moeten gebruiken.

2. Gebruik 2 files: je originele file lees je in, en je schrijft naar een temp-file. Kom je in je originele file een record tegen dat verwijderd dient te worden, dan schrijf je die niet in je temp-file. Je kan ook meteen records aanpassen, en nieuwe records gooi je weer aan het einde. Tenslotte sluit je beide files weer, delete je je originele file, en rename je je temp-file naar de naam van je originele file :)

3. Je zou kunnen overwegen een database te gebruiken, dan ben je van het hele geblaat af :) Nadeel is dan wel weer dat je programma van die database afhankelijk is (complexere installatieprocedure, compatibiliteitsgebeuren enz). Als het een klein programma is is dit wel overkill. QuickBasic had vroeger heel handige support voor flat-files met data records.

4200Wp ZO + 840Wp ZW + 1680Wp NW | 14xIQ7+ + 1xDS3-L | MTVenusE | HWP1


Verwijderd

Topicstarter
Bedankt Johnwoo :)
Ik heb het als volgt getracht op te lossen:
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
Private Sub Command1_Click()
Open App.Path & "\input.ini" For Output As #1
Open App.Path & "\temp.ini" For Input As #2
    Do While Not EOF(2)
     Input #2, strString, intInteger
     Write #1, strString, intInteger
    Loop
    nr = 1
    If Not ListView1.ListItems.Count = 0 Then
        Do While Not nr > ListView1.ListItems.count
            strString = ListView1.ListItems(nr).Text
            intInteger = CInt(ListView1.ListItems(nr).ListSubItems(1).Text)
            Write #1, strString, intInteger
            nr = nr + 1
        Loop
    End If
Close #2
Close #1
nr = 1
End Sub

Private Sub Form_Load()
Open App.Path & "\input.ini" For Input As #1
Open App.Path & "\temp.ini" For Output As #2
Do While Not EOF(1)
    Input #1, strString, intInteger
    If intInteger > 3 Then
        Set Newmutatie = ListView1.ListItems.Add(, "key" & CStr(intInteger), strString)
        Newmutatie.SubItems(1) = intInteger
    Else
        Write #2, strString, intInteger
    End If
Loop
Close #2
Close #1
End Sub

edit:

Sorry, dit werkt, ik heb 'm ff verandert zoals het moet. :)

[ Voor 14% gewijzigd door Verwijderd op 28-03-2003 11:51 ]