Correct my loop

stefonalfaro

Member
Joined
Dec 3, 2007
Messages
16
Programming Experience
Beginner
What im trying to do is to create 200 text files in my documens with each file having a different name...
text1.txt
text2.txt
text3.txt
text4.txt
text5.txt .......

So here is my code, if some one could correct it I would greatly appreciate it.
VB.NET:
Dim amount As Integer = "1"
        Dim FILE_NAME As String = "C:\Users\Stefon\Documents\test" & amount & ".txt"
       


        For amount = 1 To 200
            Dim objWriter As New System.IO.StreamWriter(FILE_NAME, True)
            objWriter.Write("HI")
            objWriter.Close()

        Next amount
 
Er.. OK, i understand your thinking, but you need to know that strings are immutable and once created do not change.

.NET does NOT make that string using the "amount" vairaible and then later think "oh! the amount variable has changed.. i'd better update every string that was ever made with it"

Given that I assert you must recreate the string EXPLICITLY, you should be able to work out the problem
 
Back
Top