CSV subory

Programovacie jazyky, rady, poradňa...
Vifgas
Amateur
Amateur
Príspevky: 20
Registrovaný: 01 dec 2012, 11:03

CSV subory

Príspevok od používateľa Vifgas »

Ahojte.

Môj program spočíva v tom, že potrebujem z niekoľkých súborov .csv spraviť jeden .csv a popri tom tam niečo pridať. Užívateľ si klikne, načítajú sa dané .csv súbory, ktoré potom exportuje do jedného výsledného. (pripájam program v prílohe, robím to vo Visual Basic.Net a vo Visual Studio 2012 Express)

1. Problém : neviem ako spraviť aby sa nenačítaval prvý riadok z tých csv, pretože to je v každom rovnaká hlavička a tú tam nechcem.

2. Problém : je v tom, že v tých csv ktoré dávam dokopy, nemám stĺpec ID, ktorý do výsledného potrebujem. Každý súbor csv má navyše iné ID. Ak teda prvý súbor csv má 10 záznamov, potrebujem aby mali všetky rovnaké ID aké si zvolím, napr. 124. Načíta sa ďalší csv, napr. 25 záznamov a aby mali ID zase aké si zvolím (546). To potrebujem preto, aby som vedel ktorý záznam je z ktorého csv.

Dúfam, že mi niekto bude vedieť pomôcť.

//autoeditácia príspevku (06 Feb 2013, 11:01)
Tak problem 1 spm uz vyriesil. Este by niekto mohol poradit s 2 :)

//autoeditácia príspevku (07 Feb 2013, 8:28)
NO nenasiel sa nikto,tak uz to mam vyriesene,teraz hadam nieco lahsie...Mam ten subor csv ale ma iny pocet udajov v riadkoch oddelene ; Cize napr prvy riadok ma 10 udajov a druhy riadok 13. Lenze to mi napise : Index was outside the bounds of the array. Co samozrejme chapem,ale neviem ako to osetrit

Kód: Vybrať všetko

        
SetupDataGridView()
        Dim csvpath As String = Application.StartupPath & "\z_cumulated.csv"
        Dim csvpath1 As String = Application.StartupPath & "\z_cumulated1.csv"

        Using MyReader As New Microsoft.VisualBasic.FileIO.TextFieldParser(csvpath)
            MyReader.TextFieldType = FileIO.FieldType.Delimited
            MyReader.SetDelimiters(";")
            Dim currentRow As String()
            Dim riadok As Integer
            riadok = 0
            While Not MyReader.EndOfData
                Application.DoEvents()
                Try
                    currentRow = MyReader.ReadFields()
                    riadok = riadok + 1
                    If (riadok > 1) Then
                        With songsDataGridView
                            .ColumnCount = 62
                            Dim row As String() = New String() {1, currentRow(1), currentRow(2), currentRow(3), currentRow(4), currentRow(5), currentRow(6),
                                                                   currentRow(7), currentRow(8), currentRow(9), currentRow(10), currentRow(11), currentRow(12)}
                            .Rows.Add(row)
                        End With
                    End If
                Catch ex As Microsoft.VisualBasic.FileIO.MalformedLineException
                    MsgBox("Line " & ex.Message & _
                      "is not valid and will be skipped.")
                End Try
            End While
        End Using
Prílohy
ReadCSV-VB2010.zip
(166.51 KiB) 18 stiahnutí
ReadCSV-VB2010-2.zip
(876.9 KiB) 19 stiahnutí
dykeer
Medium Expert
Medium Expert
Používateľov profilový obrázok
Príspevky: 102
Registrovaný: 02 jan 2011, 21:21
Kontaktovať používateľa:

Re: CSV subory

Príspevok od používateľa dykeer »

Tak najprv by si si mal zistiť maximum stĺpcov, ktoré budeš potrebovať do finálneho súboru a potom ak zapisuješ jednotlivé súbory, tak počet stĺpcov doplníš bodkočiarkou na maximum
Vifgas
Amateur
Amateur
Príspevky: 20
Registrovaný: 01 dec 2012, 11:03

Re: CSV subory

Príspevok od používateľa Vifgas »

dykeer napísal:Tak najprv by si si mal zistiť maximum stĺpcov, ktoré budeš potrebovať do finálneho súboru a potom ak zapisuješ jednotlivé súbory, tak počet stĺpcov doplníš bodkočiarkou na maximum
A to myslis akoze rucne doplnit?
dykeer
Medium Expert
Medium Expert
Používateľov profilový obrázok
Príspevky: 102
Registrovaný: 02 jan 2011, 21:21
Kontaktovať používateľa:

Re: CSV subory

Príspevok od používateľa dykeer »

nie rucne, vsak programom zratas pocet bodkociarok v riadku +1 mas pocet stlpcov, napr. 2 bodkociarky = 3 stlpce
takto zistis maximum zo vsetkych suborov a ked budes vkladat jednotlive subory tak budes na konci riadku doplnat bodkociarky do maxima
Vifgas
Amateur
Amateur
Príspevky: 20
Registrovaný: 01 dec 2012, 11:03

Re: CSV subory

Príspevok od používateľa Vifgas »

Vie mi niekto poradit, ked mam nasledujuci kod ako dosiahnut to, aby sa mi do vysledneho suboru zapisovali udaje inkrementalne? Nechcem kazdy den prenasat vela udajov, ked za den pribudnu len 2-3 riadky.

Kód: Vybrať všetko

Dim csvpath21 As String = "\\nm-fs01\it\Backup\IBEA\121z_cumulated.csv"

        '10.41.60.101
        Using MyReader As New Microsoft.VisualBasic.FileIO.TextFieldParser(csvpath1)
            MyReader.TextFieldType = FileIO.FieldType.Delimited
            MyReader.SetDelimiters(";")
            Dim currentRow As String()
            Dim riadok As Integer
            riadok = 0
            While Not MyReader.EndOfData
                Application.DoEvents()
                Try
                    currentRow = MyReader.ReadFields()
                    riadok = riadok + 1
                    If (riadok > 1) Then
                        With songsDataGridView
                            .ColumnCount = 64
                            Dim row As String() = New String() {"21544a", currentRow(1), currentRow(2), currentRow(3), currentRow(4), currentRow(5), currentRow(6),
                                                                       currentRow(7), currentRow(8), currentRow(9), currentRow(10), currentRow(11), currentRow(12),
                                                                       currentRow(13), currentRow(14), currentRow(15), currentRow(16), currentRow(17), currentRow(18),
                                                                       currentRow(19), currentRow(20), currentRow(21), currentRow(22), currentRow(23), currentRow(24),
                                                                       currentRow(25), currentRow(26), currentRow(27), currentRow(28), currentRow(29), currentRow(30),
                                                                       currentRow(31), currentRow(32), currentRow(33), currentRow(34), currentRow(35), currentRow(36),
                                                                       currentRow(37), currentRow(38), currentRow(39), currentRow(40), currentRow(41), currentRow(42),
                                                                       currentRow(43), currentRow(44), currentRow(45), currentRow(46), currentRow(47), currentRow(48),
                                                                       currentRow(49), currentRow(50), currentRow(51), currentRow(52), currentRow(53), currentRow(54),
                                                                       currentRow(55), currentRow(56), currentRow(57), currentRow(58), currentRow(59), currentRow(60),
                                                                       currentRow(61), currentRow(62), currentRow(63)}
                            .Rows.Add(row)
                        End With
                    End If
                Catch ex As Microsoft.VisualBasic.FileIO.MalformedLineException
                    MsgBox("Line " & ex.Message & _
                      "is not valid and will be skipped.")
                End Try
            End While
        End Using
aacid
Hardcore addict
Hardcore addict
Príspevky: 8137
Registrovaný: 22 nov 2006, 21:55
Bydlisko: BA

Re: CSV subory

Príspevok od používateľa aacid »

no ja tam nejak nikde nevidim ze by si nieco zapisoval do suboru, ty zo suboru citas riadky a vypisujes ich do gridu, to je vsetko co tento kod robi.
Vifgas
Amateur
Amateur
Príspevky: 20
Registrovaný: 01 dec 2012, 11:03

Re: CSV subory

Príspevok od používateľa Vifgas »

Tak este jedna otazka trochu inak. Mam dva cvs subory, kazdy nacitany v jednom DataGridView. A do tretieho DataGridView by som chcel nacitat len to, co nemaju tieto dva subory spolocne. Nejaka rada ako nato?

//autoeditácia príspevku (27 Feb 2013, 8:42)
Nenajde sa nikto teda? Toto by som potreboval http://imgupload.sk/viewer.php?file=6pm ... ktfxnq.jpg . 1ka je spraven, 2ka je spravena, len potrebujem do 3ky to, co obsahuje jednotka navyse od 2ky. Proste porovnat kazdy riadok s kazdym...lenze ako :)
aacid
Hardcore addict
Hardcore addict
Príspevky: 8137
Registrovaný: 22 nov 2006, 21:55
Bydlisko: BA

Re: CSV subory

Príspevok od používateľa aacid »

ved proste skontrolujes kazdy riadok oproti tomu istemu riadku v druhom datagride, pokial su data rovnake, nic, pokial nie, pridas ho do tretieho gridu...

to mas jeden for.
Vifgas
Amateur
Amateur
Príspevky: 20
Registrovaný: 01 dec 2012, 11:03

Re: CSV subory

Príspevok od používateľa Vifgas »

jeden for to mam,len mi to nejde dat dokopy,kedze vo VB .net nie som taky zbehnuty...mozes mi to nejako dat dokopy prosimta?budem velmi vdacny
aacid
Hardcore addict
Hardcore addict
Príspevky: 8137
Registrovaný: 22 nov 2006, 21:55
Bydlisko: BA

Re: CSV subory

Príspevok od používateľa aacid »

prepac, ja ale vo VB nerobim vobec...

skus sem ale pastnut ten kod ktorym to porovnavas, napisat co ti tam nejde a nejak hadam poradim.
Vifgas
Amateur
Amateur
Príspevky: 20
Registrovaný: 01 dec 2012, 11:03

Re: CSV subory

Príspevok od používateľa Vifgas »

aacid napísal:prepac, ja ale vo VB nerobim vobec...

skus sem ale pastnut ten kod ktorym to porovnavas, napisat co ti tam nejde a nejak hadam poradim.
Tak praveze zatial neporovnavam nijako,lebo nemozem dat jednoducho row = row1 ... a neviem ako to mam inak spravit

For Each row As DataGridViewRow In songsDataGridView.Rows
For Each row1 As DataGridViewRow In songsDataGridView1.Rows

Next
Next
aacid
Hardcore addict
Hardcore addict
Príspevky: 8137
Registrovaný: 22 nov 2006, 21:55
Bydlisko: BA

Re: CSV subory

Príspevok od používateľa aacid »

no miesto toho aby si pouzival foreach, pouzi len jednoduchy for.

Kód: Vybrať všetko

for (int i = 0; i < songsDataGridView.Rows.Count; i++)
{
if (songsDataGridView.Rows[i] == songsDataGridView1.Rows[i])
{
...
}
}
toto je c# kod a este k tomu ho pisem len tak z hlavy, ako to spravit spravne a vo VB je uz na tebe...
Vifgas
Amateur
Amateur
Príspevky: 20
Registrovaný: 01 dec 2012, 11:03

Re: CSV subory

Príspevok od používateľa Vifgas »

aacid napísal:no miesto toho aby si pouzival foreach, pouzi len jednoduchy for.
}[/code]

toto je c# kod a este k tomu ho pisem len tak z hlavy, ako to spravit spravne a vo VB je uz na tebe...
Ale songDataGridView mi stale pise,ze nemoze byt typu Boolean
aacid
Hardcore addict
Hardcore addict
Príspevky: 8137
Registrovaný: 22 nov 2006, 21:55
Bydlisko: BA

Re: CSV subory

Príspevok od používateľa aacid »

ako ti to pise? ti posle mail vzdy?
musis sa naucit poriadne popisovat problemy, ked chces aby ti niekto pomohol.

vloz sem ten kus kodu, ktory ti nefunguje (nie iba jeden riadok, ale cely blok), potom napis chybu ktoru ti to vyhadzuje a na ktorom riadku.

z toho co si napisal netusim nic, akurat ze niekde sa asi niekde snazis pouzit songDataGridView tam kde by si mal pouzit boolean (asi v tom if-e?
Vifgas
Amateur
Amateur
Príspevky: 20
Registrovaný: 01 dec 2012, 11:03

Re: CSV subory

Príspevok od používateľa Vifgas »

aacid napísal:ako ti to pise? ti posle mail vzdy?
musis sa naucit poriadne popisovat problemy, ked chces aby ti niekto pomohol.

vloz sem ten kus kodu, ktory ti nefunguje (nie iba jeden riadok, ale cely blok), potom napis chybu ktoru ti to vyhadzuje a na ktorom riadku.

z toho co si napisal netusim nic, akurat ze niekde sa asi niekde snazis pouzit songDataGridView tam kde by si mal pouzit boolean (asi v tom if-e?
Pozeram ze to moje .zip co som sem dal nefunguje,boh vie preco...toto je teda cely kod co mam...Ja som svoj problem popisal spravne a dobre uz niekolko krat vyssie. Ale netusim ako to mam vo VB . net napisat a preto sem nemam dat aky kod, kedze ziadny ani nemam k tomu mojmu problemu,potreboval by som ho od niekoho doplnit.Necakal som,ze porovnat 2 DataGridView bude take narocne.

Kód: Vybrať všetko

Public Class Form1

    Dim objDate As Object

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Close()
    End Sub


    Private Sub btnRead_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRead.Click
        SetupDataGridView()
        SetupDataGridView1()
         SetupDataGridView2()
        Dim csvpath As String = "\\nm-fs01\it\Backup\IBEA\z_cumulated.csv"
        Dim csvpath1 As String = "\\nm-fs01\it\Backup\IBEA\101z_cumulated.csv"

        'z
        Using MyReader As New Microsoft.VisualBasic.FileIO.TextFieldParser(csvpath)
            MyReader.TextFieldType = FileIO.FieldType.Delimited
            MyReader.SetDelimiters(";")
            Dim currentRow1 As String()

            Dim riadok As Integer
            riadok = 0
            While Not MyReader.EndOfData
                Application.DoEvents()
                Try
                    currentRow1 = MyReader.ReadFields()
                    riadok = riadok + 1
                    If (riadok > 1) Then
                        With songsDataGridView1
                            .ColumnCount = 64
                            Dim row1 As String() = New String() {currentRow1(0), currentRow1(1), currentRow1(2), currentRow1(3), currentRow1(4), currentRow1(5), currentRow1(6),
                                                                       currentRow1(7), currentRow1(8), currentRow1(9), currentRow1(10), currentRow1(11), currentRow1(12),
                                                                       currentRow1(13), currentRow1(14), currentRow1(15), currentRow1(16), currentRow1(17), currentRow1(18),
                                                                       currentRow1(19), currentRow1(20), currentRow1(21), currentRow1(22), currentRow1(23), currentRow1(24),
                                                                       currentRow1(25), currentRow1(26), currentRow1(27), currentRow1(28), currentRow1(29), currentRow1(30),
                                                                       currentRow1(31), currentRow1(32), currentRow1(33), currentRow1(34), currentRow1(35), currentRow1(36),
                                                                       currentRow1(37), currentRow1(38), currentRow1(39), currentRow1(40), currentRow1(41), currentRow1(42),
                                                                       currentRow1(43), currentRow1(44), currentRow1(45), currentRow1(46), currentRow1(47), currentRow1(48),
                                                                       currentRow1(49), currentRow1(50), currentRow1(51), currentRow1(52), currentRow1(53), currentRow1(54),
                                                                       currentRow1(55), currentRow1(56), currentRow1(57), currentRow1(58), currentRow1(59), currentRow1(60),
                                                                       currentRow1(61), currentRow1(62), currentRow1(63)}

                            .Rows.Add(row1)
                        End With
                    End If
                Catch ex As Microsoft.VisualBasic.FileIO.MalformedLineException
                    MsgBox("Line " & ex.Message & _
                      "is not valid and will be skipped.")
                End Try
            End While
        End Using
        '10.41.60.101
        If IO.File.Exists("\\nm-fs01\it\Backup\IBEA\101z_cumulated.csv") Then

            Using MyReader As New Microsoft.VisualBasic.FileIO.TextFieldParser(csvpath1)
                MyReader.TextFieldType = FileIO.FieldType.Delimited
                MyReader.SetDelimiters(";")
                Dim currentRow As String()

                Dim riadok As Integer

                While Not MyReader.EndOfData
                    Application.DoEvents()
                    Try
                        currentRow = MyReader.ReadFields()
                        riadok = riadok + 1
                        If (riadok > 1) Then
                            With songsDataGridView
                                .ColumnCount = 64
                                Dim row As String() = New String() {"21544a", currentRow(1), currentRow(2), currentRow(3), currentRow(4), currentRow(5), currentRow(6),
                                                                           currentRow(7), currentRow(8), currentRow(9), currentRow(10), currentRow(11), currentRow(12),
                                                                           currentRow(13), currentRow(14), currentRow(15), currentRow(16), currentRow(17), currentRow(18),
                                                                           currentRow(19), currentRow(20), currentRow(21), currentRow(22), currentRow(23), currentRow(24),
                                                                           currentRow(25), currentRow(26), currentRow(27), currentRow(28), currentRow(29), currentRow(30),
                                                                           currentRow(31), currentRow(32), currentRow(33), currentRow(34), currentRow(35), currentRow(36),
                                                                           currentRow(37), currentRow(38), currentRow(39), currentRow(40), currentRow(41), currentRow(42),
                                                                           currentRow(43), currentRow(44), currentRow(45), currentRow(46), currentRow(47), currentRow(48),
                                                                           currentRow(49), currentRow(50), currentRow(51), currentRow(52), currentRow(53), currentRow(54),
                                                                           currentRow(55), currentRow(56), currentRow(57), currentRow(58), currentRow(59), currentRow(60),
                                                                           currentRow(61), currentRow(62), currentRow(63)}
                                .Rows.Add(row)
                            End With
                        End If

                    Catch ex As Microsoft.VisualBasic.FileIO.MalformedLineException
                        MsgBox("Line " & ex.Message & _
                          "is not valid and will be skipped.")
                    End Try
                End While
            End Using
        Else : End If

        Private Sub SetupDataGridView()

        'Me.Controls.Add(songsDataGridView)

        songsDataGridView.ColumnCount = 64
        With songsDataGridView.ColumnHeadersDefaultCellStyle
            .BackColor = Color.Navy
            .ForeColor = Color.Red
            .Font = New Font(songsDataGridView.Font, FontStyle.Bold)
        End With

        With songsDataGridView
            '.Name = "songsDataGridView"
            '.Location = New Point(8, 8)
            '.Size = New Size(500, 250)
            .AutoSizeRowsMode = _
                DataGridViewAutoSizeRowsMode.DisplayedCellsExceptHeaders
            .ColumnHeadersBorderStyle = DataGridViewHeaderBorderStyle.Single
            .CellBorderStyle = DataGridViewCellBorderStyle.Single
            .GridColor = Color.Black
            .RowHeadersVisible = False
            .ColumnHeadersVisible = True

            .Columns(0).Name = "Id"
            .Columns(1).Name = "Start date"
            .Columns(2).Name = "Start time"
            .Columns(3).Name = "Time zone"
            .Columns(4).Name = "End date"
            .Columns(5).Name = "End time"
            .Columns(6).Name = "Jobname"
            .Columns(7).Name = "Batch number"
            .Columns(8).Name = "Total"
            .Columns(9).Name = "Rejected"
            .Columns(10).Name = "Pusher 1"
            .Columns(11).Name = "Pusher 2"
            .Columns(12).Name = "Pusher 3"
            .Columns(13).Name = "Checked"
            .Columns(14).Name = "Recognized def."
            .Columns(15).Name = "Object error"
            .Columns(16).Name = "Surface error"
            .Columns(17).Name = "Field01"
            .Columns(18).Name = "Field02"
            .Columns(19).Name = "Field03"
            .Columns(20).Name = "Field04"
            .Columns(21).Name = "Field05"
            .Columns(22).Name = "Field06"
            .Columns(23).Name = "Field07"
            .Columns(24).Name = "Field08"
            .Columns(25).Name = "Field09"
            .Columns(26).Name = "Field10"
            .Columns(27).Name = "Field11"
            .Columns(28).Name = "Field12"
            .Columns(29).Name = "Field13"
            .Columns(30).Name = "Field14"
            .Columns(31).Name = "Field15"
            .Columns(32).Name = "Field16"
            .Columns(33).Name = "Field17"
            .Columns(34).Name = "Field18"
            .Columns(35).Name = "Field19"
            .Columns(36).Name = "Field20"
            .Columns(37).Name = "Field21"
            .Columns(38).Name = "Field22"
            .Columns(39).Name = "Field23"
            .Columns(40).Name = "Field24"
            .Columns(41).Name = "Field25"
            .Columns(42).Name = "Field26"
            .Columns(43).Name = "Field27"
            .Columns(44).Name = "Field28"
            .Columns(45).Name = "Field29"
            .Columns(46).Name = "Field30"
            .Columns(47).Name = "Field31"
            .Columns(48).Name = "Field32"
            .Columns(49).Name = "Field33"
            .Columns(50).Name = "Field34"
            .Columns(51).Name = "Field35"
            .Columns(52).Name = "Field36"
            .Columns(53).Name = "Field37"
            .Columns(54).Name = "Field38"
            .Columns(55).Name = "Field39"
            .Columns(56).Name = "Field40"
            .Columns(57).Name = "Field41"
            .Columns(58).Name = "Field42"
            .Columns(59).Name = "Field43"
            .Columns(60).Name = "Field44"
            .Columns(61).Name = "Field45"
            .Columns(62).Name = "Field46"
            .Columns(63).Name = "Field47"

            .Columns(0).DefaultCellStyle.Font = New Font(Me.songsDataGridView.DefaultCellStyle.Font, FontStyle.Bold)

            .SelectionMode = DataGridViewSelectionMode.FullRowSelect
            .MultiSelect = False
        End With

    End Sub

    Private Sub SetupDataGridView1()

        'Me.Controls.Add(songsDataGridView)

        songsDataGridView1.ColumnCount = 64
        With songsDataGridView1.ColumnHeadersDefaultCellStyle
            .BackColor = Color.Navy
            .ForeColor = Color.Red
            .Font = New Font(songsDataGridView1.Font, FontStyle.Bold)
        End With

        With songsDataGridView1
            '.Name = "songsDataGridView"
            '.Location = New Point(8, 8)
            '.Size = New Size(500, 250)
            .AutoSizeRowsMode = _
                DataGridViewAutoSizeRowsMode.DisplayedCellsExceptHeaders
            .ColumnHeadersBorderStyle = DataGridViewHeaderBorderStyle.Single
            .CellBorderStyle = DataGridViewCellBorderStyle.Single
            .GridColor = Color.Black
            .RowHeadersVisible = False
            .ColumnHeadersVisible = True

            .Columns(0).Name = "Id"
            .Columns(1).Name = "Start date"
            .Columns(2).Name = "Start time"
            .Columns(3).Name = "Time zone"
            .Columns(4).Name = "End date"
            .Columns(5).Name = "End time"
            .Columns(6).Name = "Jobname"
            .Columns(7).Name = "Batch number"
            .Columns(8).Name = "Total"
            .Columns(9).Name = "Rejected"
            .Columns(10).Name = "Pusher 1"
            .Columns(11).Name = "Pusher 2"
            .Columns(12).Name = "Pusher 3"
            .Columns(13).Name = "Checked"
            .Columns(14).Name = "Recognized def."
            .Columns(15).Name = "Object error"
            .Columns(16).Name = "Surface error"
            .Columns(17).Name = "Field01"
            .Columns(18).Name = "Field02"
            .Columns(19).Name = "Field03"
            .Columns(20).Name = "Field04"
            .Columns(21).Name = "Field05"
            .Columns(22).Name = "Field06"
            .Columns(23).Name = "Field07"
            .Columns(24).Name = "Field08"
            .Columns(25).Name = "Field09"
            .Columns(26).Name = "Field10"
            .Columns(27).Name = "Field11"
            .Columns(28).Name = "Field12"
            .Columns(29).Name = "Field13"
            .Columns(30).Name = "Field14"
            .Columns(31).Name = "Field15"
            .Columns(32).Name = "Field16"
            .Columns(33).Name = "Field17"
            .Columns(34).Name = "Field18"
            .Columns(35).Name = "Field19"
            .Columns(36).Name = "Field20"
            .Columns(37).Name = "Field21"
            .Columns(38).Name = "Field22"
            .Columns(39).Name = "Field23"
            .Columns(40).Name = "Field24"
            .Columns(41).Name = "Field25"
            .Columns(42).Name = "Field26"
            .Columns(43).Name = "Field27"
            .Columns(44).Name = "Field28"
            .Columns(45).Name = "Field29"
            .Columns(46).Name = "Field30"
            .Columns(47).Name = "Field31"
            .Columns(48).Name = "Field32"
            .Columns(49).Name = "Field33"
            .Columns(50).Name = "Field34"
            .Columns(51).Name = "Field35"
            .Columns(52).Name = "Field36"
            .Columns(53).Name = "Field37"
            .Columns(54).Name = "Field38"
            .Columns(55).Name = "Field39"
            .Columns(56).Name = "Field40"
            .Columns(57).Name = "Field41"
            .Columns(58).Name = "Field42"
            .Columns(59).Name = "Field43"
            .Columns(60).Name = "Field44"
            .Columns(61).Name = "Field45"
            .Columns(62).Name = "Field46"
            .Columns(63).Name = "Field47"

            .Columns(0).DefaultCellStyle.Font = New Font(Me.songsDataGridView1.DefaultCellStyle.Font, FontStyle.Bold)

            .SelectionMode = DataGridViewSelectionMode.FullRowSelect
            .MultiSelect = False
        End With

    End Sub

    Private Sub SetupDataGridView2()

        'Me.Controls.Add(songsDataGridView)

        songsDataGridView2.ColumnCount = 64
        With songsDataGridView2.ColumnHeadersDefaultCellStyle
            .BackColor = Color.Navy
            .ForeColor = Color.Red
            .Font = New Font(songsDataGridView2.Font, FontStyle.Bold)
        End With

        With songsDataGridView2
            '.Name = "songsDataGridView"
            '.Location = New Point(8, 8)
            '.Size = New Size(500, 250)
            .AutoSizeRowsMode = _
                DataGridViewAutoSizeRowsMode.DisplayedCellsExceptHeaders
            .ColumnHeadersBorderStyle = DataGridViewHeaderBorderStyle.Single
            .CellBorderStyle = DataGridViewCellBorderStyle.Single
            .GridColor = Color.Black
            .RowHeadersVisible = False
            .ColumnHeadersVisible = True

            .Columns(0).Name = "Id"
            .Columns(1).Name = "Start date"
            .Columns(2).Name = "Start time"
            .Columns(3).Name = "Time zone"
            .Columns(4).Name = "End date"
            .Columns(5).Name = "End time"
            .Columns(6).Name = "Jobname"
            .Columns(7).Name = "Batch number"
            .Columns(8).Name = "Total"
            .Columns(9).Name = "Rejected"
            .Columns(10).Name = "Pusher 1"
            .Columns(11).Name = "Pusher 2"
            .Columns(12).Name = "Pusher 3"
            .Columns(13).Name = "Checked"
            .Columns(14).Name = "Recognized def."
            .Columns(15).Name = "Object error"
            .Columns(16).Name = "Surface error"
            .Columns(17).Name = "Field01"
            .Columns(18).Name = "Field02"
            .Columns(19).Name = "Field03"
            .Columns(20).Name = "Field04"
            .Columns(21).Name = "Field05"
            .Columns(22).Name = "Field06"
            .Columns(23).Name = "Field07"
            .Columns(24).Name = "Field08"
            .Columns(25).Name = "Field09"
            .Columns(26).Name = "Field10"
            .Columns(27).Name = "Field11"
            .Columns(28).Name = "Field12"
            .Columns(29).Name = "Field13"
            .Columns(30).Name = "Field14"
            .Columns(31).Name = "Field15"
            .Columns(32).Name = "Field16"
            .Columns(33).Name = "Field17"
            .Columns(34).Name = "Field18"
            .Columns(35).Name = "Field19"
            .Columns(36).Name = "Field20"
            .Columns(37).Name = "Field21"
            .Columns(38).Name = "Field22"
            .Columns(39).Name = "Field23"
            .Columns(40).Name = "Field24"
            .Columns(41).Name = "Field25"
            .Columns(42).Name = "Field26"
            .Columns(43).Name = "Field27"
            .Columns(44).Name = "Field28"
            .Columns(45).Name = "Field29"
            .Columns(46).Name = "Field30"
            .Columns(47).Name = "Field31"
            .Columns(48).Name = "Field32"
            .Columns(49).Name = "Field33"
            .Columns(50).Name = "Field34"
            .Columns(51).Name = "Field35"
            .Columns(52).Name = "Field36"
            .Columns(53).Name = "Field37"
            .Columns(54).Name = "Field38"
            .Columns(55).Name = "Field39"
            .Columns(56).Name = "Field40"
            .Columns(57).Name = "Field41"
            .Columns(58).Name = "Field42"
            .Columns(59).Name = "Field43"
            .Columns(60).Name = "Field44"
            .Columns(61).Name = "Field45"
            .Columns(62).Name = "Field46"
            .Columns(63).Name = "Field47"

            .Columns(0).DefaultCellStyle.Font = New Font(Me.songsDataGridView2.DefaultCellStyle.Font, FontStyle.Bold)

            .SelectionMode = DataGridViewSelectionMode.FullRowSelect
            .MultiSelect = False
        End With

    End Sub
    Private Sub songsDataGridView_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles songsDataGridView.CellContentClick

    End Sub
    Private Sub Button2_Click_1(sender As Object, e As EventArgs) Handles Button2.Click

        Dim headers = (From header As DataGridViewColumn In songsDataGridView.Columns.Cast(Of DataGridViewColumn)() _
                      Select header.HeaderText).ToArray
        Dim rows = From row As DataGridViewRow In songsDataGridView.Rows.Cast(Of DataGridViewRow)() _
                   Where Not row.IsNewRow _
                   Select Array.ConvertAll(row.Cells.Cast(Of DataGridViewCell).ToArray, Function(c) If(c.Value IsNot Nothing, c.Value, ""))

        Using sw As New IO.StreamWriter("\\nm-fs01\it\Backup\IBEA\z_cumulated.csv")
            sw.WriteLine(String.Join(";", headers))
            For Each r In rows
                sw.WriteLine(String.Join(";", r))
            Next
        End Using
        Process.Start("\\nm-fs01\it\Backup\IBEA\z_cumulated.csv")
    End Sub

    Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click


    End Sub

    Private Sub DataGridView1_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles songsDataGridView1.CellContentClick

    End Sub


    Private Sub DataGridView1_CellContentClick_1(sender As Object, e As DataGridViewCellEventArgs) Handles songsDataGridView2.CellContentClick

    End Sub

    Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click

    End Sub
End Class
aacid
Hardcore addict
Hardcore addict
Príspevky: 8137
Registrovaný: 22 nov 2006, 21:55
Bydlisko: BA

Re: CSV subory

Príspevok od používateľa aacid »

je mi luto, ja som sa snazil pomoct, ale ked to nejde tak to nejde.

napisal som ti postup ako to mas spravit, ze mas spravit for a porovnat to v nom, napisal som ti pseudo kod. ked sa odtial uz nevies sam pohnut, tak mas smolu asi. ja za teba kod pisat nebudem. poradim ti ako postupovat, poradim ti ked budes mat nejaky konkretny problem.

napisal si ze ti songDataGridView pise ze je boolean, tak som ti povedal ze sem mas dat ten kod kde ti to hlasi chybu a chybu samotnu, miesto toho sem pastnes komplet cely program... mne sa ozaj nechce prechadzat hromadu kodu, a uz vobec nie si stahovat subory a pustat ich u seba.
Vifgas
Amateur
Amateur
Príspevky: 20
Registrovaný: 01 dec 2012, 11:03

Re: CSV subory

Príspevok od používateľa Vifgas »

aacid napísal:je mi luto, ja som sa snazil pomoct, ale ked to nejde tak to nejde.

napisal som ti postup ako to mas spravit, ze mas spravit for a porovnat to v nom, napisal som ti pseudo kod. ked sa odtial uz nevies sam pohnut, tak mas smolu asi. ja za teba kod pisat nebudem. poradim ti ako postupovat, poradim ti ked budes mat nejaky konkretny problem.

napisal si ze ti songDataGridView pise ze je boolean, tak som ti povedal ze sem mas dat ten kod kde ti to hlasi chybu a chybu samotnu, miesto toho sem pastnes komplet cely program... mne sa ozaj nechce prechadzat hromadu kodu, a uz vobec nie si stahovat subory a pustat ich u seba.
Tak potom je zbytocne mi aj sem nieco pisat..to ze si tam mam dat for a porovnat kazdy riadok je jasne,taka rada mi moc nepomohla,aj ked si to cenim ze sa aspon niekto ozval. Ale s tym sa dalej nepohnem...cely ten moj kod co potrebujem je par riadkov,takze zase sa vyhovarat nato,ze nebudes za mna pisat kod je tiez odveci.Ten moj program som sem ani nedal cely,len cast...ma to vyse 1 000 riadkov a ja potrebujem mozno 10 riadkov od niekoho tam doplnit s ktorymi si fakt neviem radu.
aacid
Hardcore addict
Hardcore addict
Príspevky: 8137
Registrovaný: 22 nov 2006, 21:55
Bydlisko: BA

Re: CSV subory

Príspevok od používateľa aacid »

nechapem ako si dokazal napisat 1000 riadkov kodu a teraz nezvladnes napisat jeden for...

ked ja neviem co viac chces, s cim si nevies rady, konkretne s cim? vies ze mas spravit for a v nom porovnat riadky, ale nevies ako to spravit? tu je priklad ako spravit for vo VB:
http://www.dotnetperls.com/for-vbnet
nevies ako porovnat dva riadky DataGridView-u? tu je ten DataGridView:
http://msdn.microsoft.com/en-us/library ... dview.aspx
tam si najdem jeho property Rows, zistim ze sa jedna o DataGridViewRowCollection:
http://msdn.microsoft.com/en-us/library ... ction.aspx
odtial zistim ze ma property Count (alebo metodu GetRowCount()).
takze ked uz vies ako spravit for, vies ako tam dostat ten count, staci len to samotne porovnanie.

ta property Rows obsahuje viac DataGridViewRow objektov:
http://msdn.microsoft.com/en-us/library ... ewrow.aspx
cez nu si viem vytiahnut pozadovany Cell (property Cells):
http://msdn.microsoft.com/en-us/library ... cells.aspx
a odtial uz staci len vediet ktory cell presne chces porovnavat (alebo ktore celly), z kazdeho zobrat Value a porovnat ich.
Vifgas
Amateur
Amateur
Príspevky: 20
Registrovaný: 01 dec 2012, 11:03

Re: CSV subory

Príspevok od používateľa Vifgas »

aacid napísal:nechapem ako si dokazal napisat 1000 riadkov kodu a teraz nezvladnes napisat jeden for...

ked ja neviem co viac chces, s cim si nevies rady, konkretne s cim? vies ze mas spravit for a v nom porovnat riadky, ale nevies ako to spravit? tu je priklad ako spravit for vo VB:
http://www.dotnetperls.com/for-vbnet
nevies ako porovnat dva riadky DataGridView-u? tu je ten DataGridView:
http://msdn.microsoft.com/en-us/library ... dview.aspx
tam si najdem jeho property Rows, zistim ze sa jedna o DataGridViewRowCollection:
http://msdn.microsoft.com/en-us/library ... ction.aspx
odtial zistim ze ma property Count (alebo metodu GetRowCount()).
takze ked uz vies ako spravit for, vies ako tam dostat ten count, staci len to samotne porovnanie.

ta property Rows obsahuje viac DataGridViewRow objektov:
http://msdn.microsoft.com/en-us/library ... ewrow.aspx
cez nu si viem vytiahnut pozadovany Cell (property Cells):
http://msdn.microsoft.com/en-us/library ... cells.aspx
a odtial uz staci len vediet ktory cell presne chces porovnavat (alebo ktore celly), z kazdeho zobrat Value a porovnat ich.
Tak uz mam nejaky konkretny kod, na ktorom mi mozes poradit. Kod porovnava 2 dataGridView. Ak sa tie udaje v riadku zhoduju, nema urobit nic a ist na dalsi riadok. Ak sa nezhoduju, ma ho zapisat do tretej dataGridView. Ciastocne to funguje, porovna riadok, najde nezhodu a zapise...potom ked je nasledujuci riadok rovnaky neurobi nic, cize tak ako ma. Ale potom ked sa dalej vyskytne rozdiel, uz ho nezapise do tej 3 dataGridView. Proste najde prvu nezhodu a potom uz ako keby ten cyklus skoncil. Kde je tam prosimta chyba?

Kód: Vybrať všetko

        Dim isFound As Boolean = False
        'Start iterating through datagridview1
        For Each dgv1Row As DataGridViewRow In songsDataGridView.Rows
            'and for each iteration through datagridview1 iterate through all of datagrid2

            For Each dgv2Row As DataGridViewRow In songsDataGridView1.Rows
                'compare each iteration of dgv1 with each iteration of dgv2
                If (dgv1Row.Cells(8).Value = dgv2Row.Cells(8).Value) Then
                    'if there is a match, we don't want to add it so set Found
                    isFound = True
                End If
            Next
            'only add to datagridview3 if isFound = false (meaning there was no
            'match from the current row in dgv1 to any of the rows in dgv2)
            'and reset isFound back to False
            If Not isFound Then
                songsDataGridView2.Rows.Add(dgv1Row.Cells(0).Value, dgv1Row.Cells(1).Value, dgv1Row.Cells(2).Value, dgv1Row.Cells(3).Value, dgv1Row.Cells(4).Value, dgv1Row.Cells(5).Value,
                                            dgv1Row.Cells(6).Value, dgv1Row.Cells(7).Value, dgv1Row.Cells(8).Value)
                isFound = True
            End If
        Next
aacid
Hardcore addict
Hardcore addict
Príspevky: 8137
Registrovaný: 22 nov 2006, 21:55
Bydlisko: BA

Re: CSV subory

Príspevok od používateľa aacid »

za prve, stale pouzivat for each, nie klasicky for ako som ti hovoril a daval ten prvy odkaz:

Kód: Vybrať všetko

For value As Integer = 0 To 5
	    ' Exit condition if the value is three.
	    If (value = 3) Then
		Exit For
	    End If
	    Console.WriteLine(value)
	Next
co sa teraz u teba deje je toto:
zoberies prvy riadok prveho gridu a porovovnavas ho voci kazdemu riadku v druhom gride (pretoze foreach pre druhy grid je vnoreny v tom prvom gride).
no a tie isFound mas totalne popletene, na zaciatku je False, ak su riadky rovnake, das ho na True (a kedze to porovnavas vnorene, tak moze byt konkretny riadok z prveho gridu zhodny s ktorymkolvek z druheho gridu) a potom ho uz nikdy znova nenastavis na False, takze bude uz nikdy ziadny riadok nezapise do tretieho gridu...

skus to takto nejak:

Kód: Vybrať všetko

For i As Integer = 0 To songsDataGridView.Rows.Count
	If (songsDataGridView.Rows(i).Cells(8).Value = songsDataGridView1.Rows(i).Cells(8).Value) Then
		' ked najdes zhodu, nepotrebujes ziadnu isFound premennu, proste das Continue
		Continue
	End If
	
	' nemusis otrocky kopirovat cell po celly, Clone() to spravi za teba
	songsDataGridView2.Rows.Add(songsDataGridView.Rows(i).Clone())
Next
je to napisane len tak do notepadu, bez ziadnej kontroly, asi to budes musiet skontrolovat. tiez si budes musiet osetrit napriklad pripad ze jeden grid ma viac riadkov ako druhy (ak taka moznost teda moze nastat...)
Napísať odpoveď