一道VB程序题

求大神详解。
2025-04-14 10:45:17
推荐回答(1个)
回答1:

读取文件,并写入数组及升序排序:
Dim file As New System.IO.StreamReader("data1.txt")
        Dim words As String = file.ReadToEnd()
        file.Close()
        Dim b() As String
        Dim temp As Integer
        Dim str1 As String
        str1 = ""
        b = Split(words, " ")
        Dim c() As Integer
 
        Dim l As Integer
        l = UBound(b)
        ReDim c(l)
 
        For i = 1 To l
            c(i) = Val(b(i - 1))
        Next
        For i = 1 To l
            For j = 1 To l - i
                If c(j) < c(j + 1) Then
                    temp = c(j + 1)
                    c(j + 1) = c(j)
                    c(j) = temp
                End If
            Next j
        Next i
        For i = 1 To l
            str1 = str1 & c(i) & " "
        Next
        将升序的数组写入文件:
Dim file As New System.IO.StreamWriter("data1.txt")
file.WriteLine(str1)
file.Close()