I am using the following code to create a dummy file of a specific size.
RemSpace declared as a Long value and is returned in bytes from a separate function in my applciation. I have verified that it returns the correct # in bytes. However, when I execute the following routine, the dummyfile is created, but it never stops the loop. I have to kill it from task manager or it would fill up the HDD. What am I missing here? The line:

Code:
For i As Integer = 1 To RemSpace
should tell the For loop to stop when it reaches the value of RemSpace, which is a long value in bytes. Here is my complete code.
Thanks for any help with this one.


Code:
Public Sub Create_DummyFile()

        Dim RandomClass As New Random()
        Dim RandomNumber As Integer
        RandomNumber = RandomClass.Next()

        'Create the dummyfile to take up the remaining space on the drive
        Dim myStreamWriter As New IO.StreamWriter("C:\dummy.txt")

        For i As Integer = 1 To RemSpace
            myStreamWriter.Write(RandomNumber)
        Next
        myStreamWriter.Close()
        myStreamWriter.Dispose()
        myStreamWriter = Nothing
    End Sub