希望我能够很好地解释这一点,让有人指出我正确的方向 - 我会尽量简明扼要 - 是的 - 这是VB.Net的另一个初学者,以防万一不显示。
我有一个表单,我正在执行以下操作:
OpenFileDialog
选择文本文件,并使用StreamReader
将未格式化的文件内容显示为ListBox1
ListBox1.SelectedItems.Count
和ListBox1.Items.Remove(ListBox1.SelectedItem)
ListBox
按钮上的剩余内容我在ListBox中最终得到的内容类似于以下内容:
0,Text,9,MoreText,23,EvenMoreText,19
1,Text,16,MoreText,23,EvenMoreText,23
2,Text,32,MoreText,23,EvenMoreText,16
3,Text,5,MoreText,23,EvenMoreText,21
......接下来还有多行。
我正在尝试使用新按钮 来实现以下 ,但不知道该怎么做:
1。将上面提到的每一行放入一个数组中 2.从同一位置的每一行中选择特定值(例如:值为19,23,16和21的“最后位置”) 3.对提取的值运行平均计算以显示到TextBox
这是我的代码:
Imports System.IO
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim ResultDialogResult As DialogResult
With OpenFileDialog1
.InitialDirectory = Application.StartupPath
.Filter = "All files (*.*)|*.*"
.ShowDialog()
TextBox1.Text = OpenFileDialog1.FileName
If ResultDialogResult = Windows.Forms.DialogResult.Cancel Or .FileName = "" Then
Exit Sub
End If
Dim InReader As New StreamReader(.FileName)
Do While Not InReader.EndOfStream
ListBox1.Items.Add(InReader.ReadLine)
Loop
ListBox1.SelectionMode = SelectionMode.MultiExtended
InReader.Close()
End With
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Do While (ListBox1.SelectedItems.Count > 0)
ListBox1.Items.Remove(ListBox1.SelectedItem)
Loop
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
Dim IndexInteger As Integer = ListBox1.SelectedIndex
Dim Results =
(
From T In ListBox1.Items
Select System.Text.RegularExpressions.Regex.Replace(CStr(T), "[""]", "")
).ToArray
ListBox1.Items.Clear()
ListBox1.Items.AddRange(Results)
If IndexInteger <> -1 Then
ListBox1.SelectedIndex = IndexInteger
End If
End Sub
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
Dim ResultDialogResult As DialogResult
Dim OutWriter As StreamWriter
With SaveFileDialog1
.InitialDirectory = Application.StartupPath
.DefaultExt = "axf"
.ShowDialog()
If .FileName = "" Then
Exit Sub
End If
If ResultDialogResult = Windows.Forms.DialogResult.Cancel Then
Exit Sub
End If
OutWriter = New StreamWriter(.FileName)
For Each Item As String In ListBox1.Items
OutWriter.WriteLine(Item)
Next
OutWriter.Close()
End With
End Sub
Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
' Here is where I require steps 1, 2 and 3 for new button as outlined above
End Sub
Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click
ListBox1.Items.Clear()
TextBox1.Clear()
End Sub
Private Sub Button7_Click(sender As Object, e As EventArgs) Handles Button7.Click
Me.Close()
End Sub
End Class
目前我还有其他所有工作,这是我所困扰的最后一部分。
如果有人能够指出我正确的方向,或者更好地指出我想要学习的代码示例,我们将非常感激。