himynameisbunny
Technical User
I have officially spent more than two hours on this single problem...
I have got it to work for the most part...however I have a little issue - being that when Button 1 is clicked, it will only write to the first 1001 slots of the array, and the RichTextBox I have it writing to will only show those 1001 entries.
However, when sorted, it will show all 2000 entries contained in the array, INCLUDING all the 0 values that weren't written to in the previous step. It will write to the adjacent Rich Text Box as well as to file like this.
A picture of my GUI is attached.
Help would be much appreciated, cheers.
I have got it to work for the most part...however I have a little issue - being that when Button 1 is clicked, it will only write to the first 1001 slots of the array, and the RichTextBox I have it writing to will only show those 1001 entries.
However, when sorted, it will show all 2000 entries contained in the array, INCLUDING all the 0 values that weren't written to in the previous step. It will write to the adjacent Rich Text Box as well as to file like this.
A picture of my GUI is attached.
Help would be much appreciated, cheers.
Code:
Imports System.IO
Public Class Form4
Dim ArrNums(2000) As Integer
Dim r As Random = New Random(0)
Dim i As Integer
Public Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
For Me.i = 0 To ArrNums.Length
ArrNums(i) = r.Next(1, 10000)
RichTextBox1.Text = RichTextBox1.Text & ArrNums(i) & vbCrLf
i = i + 1
Next
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Array.Sort(ArrNums)
For Me.i = 0 To ArrNums.Length
RichTextBox2.Text = RichTextBox2.Text & ArrNums(i) & vbCrLf
i = i + 1
Next
Dim SaveFileDialog As New SaveFileDialog
SaveFileDialog.InitialDirectory = My.Computer.FileSystem.SpecialDirectories.MyDocuments
SaveFileDialog.Filter = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*"
If (SaveFileDialog.ShowDialog(Me) = System.Windows.Forms.DialogResult.OK) Then
Dim FileName As String = SaveFileDialog.FileName
Dim objSW As StreamWriter
Dim objFS As FileStream
objFS = New FileStream(FileName, FileMode.Create)
objSW = New StreamWriter(objFS)
For Me.i = 0 To ArrNums.Length
objSW.WriteLine(ArrNums(i))
i = i + 1
Next
objSW.Close()
objFS.Close()
End If
End Sub
End Class