谢谢啊,后面还有个button2把所有的奇数都显示在一个列表框中,跪求,谢谢大神
追答Imports System.IO
Public Class Form1
Dim strFilePath As String = "C:\1.txt"
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim a As New Random
Dim sw As StreamWriter = New StreamWriter(strFilePath, False)
Randomize()
For i = 1 To 100
sw.WriteLine(a.Next(100, 999))
sw.Flush()
Next
sw.Close()
sw = Nothing
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim sr As StreamReader = New StreamReader(strFilePath)
Do While Not sr.EndOfStream
Dim a As Integer = Convert.ToInt16(sr.ReadLine)
If a Mod 2 = 1 Then
ListBox1.Items.Add(a.ToString)
End If
Loop
sr.Close()
sr = Nothing
End Sub
End Class
太感谢了太感谢了