0

データ(数値形式)でソートしようとしているcsvファイルがあります

csv ファイル: 日付、名前、電話番号、インストラクター名

1308290930、ジム、041231232、寿司

123123423、ジェレミー、12312312、アルバート

私が得るエラーは次のとおりです。文字列「jeremy」から「double」型への変換は有効ではありませんコードのどこにもdoubleについて言及していませんが...

私のコード:

Public Class Form2
    Dim currentRow As String()
    Dim count As Integer
    Dim one As Integer
    Dim two As Integer
    Dim three As Integer
    Dim four As Integer
    'concatenation / and operator
    'casting

    Dim catchit(100) As String
    Dim count2 As Integer
    Dim arrayone(4) As Decimal
    Dim arraytwo(4) As String
    Dim arraythree(4) As Decimal
    Dim arrayfour(4) As String


    Dim array(4) As String

    Dim bigstring As String
    Dim builder As Integer
    Dim twodata As Integer


    Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load




        Using MyReader As New Microsoft.VisualBasic.FileIO.TextFieldParser("D:\completerecord.txt")
            MyReader.TextFieldType = FileIO.FieldType.Delimited
            MyReader.SetDelimiters(",")
            Dim currentRow As String()
            Dim count As Integer
            Dim currentField As String
            count = 0
            While Not MyReader.EndOfData
                Try
                    currentRow = MyReader.ReadFields()

                    For Each currentField In currentRow
                        ' makes one array to contain a record for each peice of text in the file

                        'MsgBox(currentField) '- test of Field Data
                        ' builds a big string with new line-breaks for each line in the file

                        bigstring = bigstring & currentField + Environment.NewLine


                        'build two arrays for the two columns of data
                        If (count Mod 2 = 1) Then

                            arraytwo(two) = currentField
                            two = two + 1

                            'MsgBox(currentField)
                        ElseIf (count Mod 2 = 0) Then
                            arrayone(one) = currentField
                            one = one + 1
                        ElseIf (count Mod 2 = 2) Then
                            arraythree(three) = currentField
                            three = three + 1
                        ElseIf (count Mod 2 = 3) Then
                            arrayfour(four) = currentField
                            four = four + 1



                        End If

                        count = count + 1
                        'MsgBox(count)
                    Next

                Catch ex As Microsoft.VisualBasic.FileIO.MalformedLineException
                    MsgBox("Error Occured, Please contact Admin.")
                End Try
            End While
        End Using
        RichTextBox1.Text = bigstring
        ' MsgBox("test")

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim NoMoreSwaps As Boolean
        Dim counter As Integer

        Dim Temp As Integer
        Dim Temp2 As String
        Dim listcount As Integer
        Dim builder As Integer
        Dim bigString2 As String = ""

        listcount = UBound(arraytwo)
        'MsgBox(listcount)
        builder = 0
        'bigString2 = ""
        counter = 0
        Try

            'this should sort the arrays using a Bubble Sort
            Do Until NoMoreSwaps = True
                NoMoreSwaps = True
                For counter = 0 To (listcount - 1)


                    If arraytwo(counter) > arraytwo(counter + 1) Then
                        NoMoreSwaps = False

                        If arraytwo(counter + 1) > 0 Then

                            Temp = arraytwo(counter)
                            Temp2 = arrayone(counter)

                            arraytwo(counter) = arraytwo(counter + 1)
                            arrayone(counter) = arrayone(counter + 1)

                            arraytwo(counter + 1) = Temp
                            arrayone(counter + 1) = Temp2

                        End If
                    End If

                Next
                If listcount > -1 Then
                    listcount = listcount - 1
                End If

            Loop

            'now we need to output arrays to the richtextbox first we will build a new string
            'and we can save it to a new sorted file
            Dim FILE_NAME As String = "D:\sorted.txt"
            'Location of file^ that the new data will be saved to

            If System.IO.File.Exists(FILE_NAME) = True Then
                Dim objWriter As New System.IO.StreamWriter(FILE_NAME, True)
                'If D:\sorted.txt exists then enable it to be written to

                While builder < listcount
                    bigString2 = bigString2 & arraytwo(builder) & "," & arrayone(builder) + Environment.NewLine

                    objWriter.Write(arraytwo(builder) & "," & arrayone(builder) + Environment.NewLine)

                    builder = builder + 1
                End While
                RichTextBox2.Text = bigString2

                objWriter.Close()
                MsgBox("Text written to log file")
            Else
                MsgBox("File Does Not Exist")
            End If

        Catch ex As Exception
            MsgBox(ex.Message)

        End Try
    End Sub
End Class
4

1 に答える 1