现学现卖,查了一下帮助,把1楼的数据存到记事本里,编了如下代码,供参考吧。
在窗体上放了两个Listbox控件和一个按钮控件
Imports System
Imports
Public Class Form2
Private Sub Main()
Try
Using sr As StreamReader = New StreamReader("D:\VS编程\读写文件.txt")
Dim line As String
Do
line = sr.ReadLine()
ListBox1.Items.Add(line)
Console.WriteLine(line)
Loop Until line Is Nothing
sr.Close()
End Using
Catch E As Exception
Console.WriteLine("不能读取文件!")
Console.WriteLine(E.Message)
End Try
End Sub
Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Main()
Dim STR0 As String
Dim J As Integer = ListBox1.Items.Count - 1
Dim AA(J, 2), BB(J, 2) As String
For I As Integer = 0 To J
STR0 = ListBox1.Items(I)
AA(I, 0) = Mid(STR0, 1, InStr(STR0, ",") - 1)
STR0 = Mid(STR0, InStr(STR0, ",") + 1)
AA(I, 1) = Mid(STR0, 1, InStr(STR0, ",") - 1)
AA(I, 2) = Mid(STR0, InStr(STR0, ",") + 1)
Next
BB(0, 0) = AA(0, 0)
BB(0, 1) = AA(0, 1)
BB(0, 2) = AA(0, 2)
For I As Integer = 1 To J
BB(I, 0) = IIf(AA(I, 0) = AA(I - 1, 0), "", AA(I, 0))
BB(I, 1) = IIf(AA(I, 1) = AA(I - 1, 1), "", AA(I, 1))
BB(I, 2) = IIf(AA(I, 2) = AA(I - 1, 2), "", AA(I, 2))
Next
For I As Integer = 0 To J
STR0 = BB(I, 0) + IIf(BB(I, 1).Length > 0, "," + BB(I, 1), "") + IIf(BB(I, 2).Length > 0, "," + BB(I, 2), "")
ListBox2.Items.Add(STR0)
Next
End Sub
End Class