check until value in txt change - i'm on vb6

User avatar
SpeakEasy
4StarLounger
Posts: 562
Joined: 27 Jun 2021, 10:46

Re: check until value in txt change - i'm on vb6

Post by SpeakEasy »

Another alternative would be to treat the csv as a database.

User avatar
SpeakEasy
4StarLounger
Posts: 562
Joined: 27 Jun 2021, 10:46

Re: check until value in txt change - i'm on vb6

Post by SpeakEasy »

e.g (you'll need an appropriate schema.ini as well, but that only needs to be created once, and an example is included below)

Code: Select all

Public Sub SAL21()
    Dim myrow As Long
    Dim resultset As Variant
    
    With New Recordset
        .Open "SELECT F2, Sum(F8) AS SumOfF8, Sum(F9) AS SumOfF9 , Sum(F10) AS SumOfF10 FROM test2.csv GROUP BY F2", "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\Downloads\DeleteMe;Extended Properties='text'", adOpenStatic
        resultset = .GetRows
    End With
    
    For myrow = 0 To UBound(resultset, 2)
        Debug.Print "ISTAT: " & resultset(0, myrow) & " MASCHI: " & resultset(1, myrow) & " FEMMINE: " & resultset(2, myrow) & " TOT: " & resultset(3, myrow)
    Next
End Sub
Exam,ple schema.ini

[test2.csv]
ColNameHeader=True
Format=Delimited(;)
Col1=F1 Char
Col2=F2 Char
Col3=F3 Char
Col4=F4 Char
Col5=F5 Char
Col6=F6 Char
Col7=F7 Char
Col8=F8 Integer
Col9=F9 Integer
Col10=F10 Integer

User avatar
sal21
PlatinumLounger
Posts: 4362
Joined: 26 Apr 2010, 17:36

Re: check until value in txt change - i'm on vb6

Post by sal21 »

SpeakEasy wrote:
23 Apr 2024, 13:46
e.g (you'll need an appropriate schema.ini as well, but that only needs to be created once, and an example is included below)

Code: Select all

Public Sub SAL21()
    Dim myrow As Long
    Dim resultset As Variant
    
    With New Recordset
        .Open "SELECT F2, Sum(F8) AS SumOfF8, Sum(F9) AS SumOfF9 , Sum(F10) AS SumOfF10 FROM test2.csv GROUP BY F2", "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\Downloads\DeleteMe;Extended Properties='text'", adOpenStatic
        resultset = .GetRows
    End With
    
    For myrow = 0 To UBound(resultset, 2)
        Debug.Print "ISTAT: " & resultset(0, myrow) & " MASCHI: " & resultset(1, myrow) & " FEMMINE: " & resultset(2, myrow) & " TOT: " & resultset(3, myrow)
    Next
End Sub
Exam,ple schema.ini

[test2.csv]
ColNameHeader=True
Format=Delimited(;)
Col1=F1 Char
Col2=F2 Char
Col3=F3 Char
Col4=F4 Char
Col5=F5 Char
Col6=F6 Char
Col7=F7 Char
Col8=F8 Integer
Col9=F9 Integer
Col10=F10 Integer
TKs!

i can use a where in your query?

User avatar
SpeakEasy
4StarLounger
Posts: 562
Joined: 27 Jun 2021, 10:46

Re: check until value in txt change - i'm on vb6

Post by SpeakEasy »

Yes

User avatar
sal21
PlatinumLounger
Posts: 4362
Joined: 26 Apr 2010, 17:36

Re: check until value in txt change - i'm on vb6

Post by sal21 »

SpeakEasy wrote:
25 Apr 2024, 07:35
Yes
tks.

i have many files is this correct for multi file to use schema.ini:

[Dati_cittadinanza_2023.csv]
ColNameHeader=True
Format=Delimited(;)
Col1=F1 Char
Col2=F2 Char
Col3=F3 Char
Col4=F4 Char
Col5=F5 Char
Col6=F6 Char
Col7=F7 Char
Col8=F8 Integer
Col9=F9 Integer
Col10=F10 Integer

[Dati_cittadinanza_2022.csv]
ColNameHeader=True
Format=Delimited(;)
Col1=F1 Char
Col2=F2 Char
Col3=F3 Char
Col4=F4 Char
Col5=F5 Char
Col6=F6 Char
Col7=F7 Char
Col8=F8 Integer
Col9=F9 Integer
Col10=F10 Integer

[Dati_cittadinanza_2021.csv]
ColNameHeader=True
Format=Delimited(;)
Col1=F1 Char
Col2=F2 Char
Col3=F3 Char
Col4=F4 Char
Col5=F5 Char
Col6=F6 Char
Col7=F7 Char
Col8=F8 Integer
Col9=F9 Integer
Col10=F10 Integer
...

or

[Dati_cittadinanza_2023.csv]
[Dati_cittadinanza_2022.csv]
[Dati_cittadinanza_2021.csv]
ColNameHeader=True
Format=Delimited(;)
Col1=F1 Char
Col2=F2 Char
Col3=F3 Char
Col4=F4 Char
Col5=F5 Char
Col6=F6 Char
Col7=F7 Char
Col8=F8 Integer
Col9=F9 Integer
Col10=F10 Integer

User avatar
SpeakEasy
4StarLounger
Posts: 562
Joined: 27 Jun 2021, 10:46

Re: check until value in txt change - i'm on vb6

Post by SpeakEasy »

The first one - separate entries for each file