|
-
Apr 4th, 2007, 05:05 AM
#1
Thread Starter
New Member
[RESOLVED] [2005][Newbie]StreamWriter.WriteLine() problem
I am trying to make a application that will generate a Fibonacci Sequence.I am new to Visual Basic so I came to a stupid problem.Even I have used the WriteLine() again I can't make it work.I checked my other apps too , that used the same syntax but this doesn't work.
So a little help would be appreciated.
The problem is that even everything works just fine (the progress bar etc) the file generated will be blank.
There are 2 textboxes (filebox and timesbox) , one progress bar (pb1) and one button (startbut)
Code:
Public Class Form1
Private Sub startbut_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles startbut.Click
Dim file As String = filebox.Text
Dim StreamWriter As New System.IO.StreamWriter(file)
Dim i As Integer = 3
Dim times As Integer = timesbox.Text
Dim a As Integer = 1
Dim b As Integer = 1
Dim c As Integer = 2
StreamWriter.WriteLine(1)
StreamWriter.WriteLine(1)
StreamWriter.WriteLine(2)
Do Until i = times
a = c + b
StreamWriter.WriteLine(a)
i = i + 1
pb1.Value = i / times * 100
If i = times Then Exit Do
b = a + c
StreamWriter.WriteLine(b)
i = i + 1
pb1.Value = i / times * 100
If i = times Then Exit Do
c = a + b
StreamWriter.WriteLine(c)
i = i + 1
pb1.Value = i / times * 100
If i = times Then Exit Do
Loop
End Sub
End Class
thank you
EDIT:I have already created a batch file so all the math etc are correct.
EDIT2:Unfortunately I am leaving today for about 5 days so I won't be able to answer you.
Last edited by ChrisSak; Apr 4th, 2007 at 05:16 AM.
-
Apr 4th, 2007, 05:22 AM
#2
Re: [2005][Newbie]StreamWriter.WriteLine() problem
I think it may have something to do with either conversion of your int values from a textbox or more likely the fact that you haven't closed and disposed of the StreamWriter:
vb Code:
Try
Dim file As String = "C:\Temp\weird.txt"
Dim SR As New System.IO.StreamWriter(file)
Dim i As Integer = 3
Dim times As Integer = CInt(Me.filebox.Text)
Dim a As Integer = 1
Dim b As Integer = 1
Dim c As Integer = 2
SR.WriteLine(1)
SR.WriteLine(1)
SR.WriteLine(2)
Do Until i = times
a = c + b
SR.WriteLine(a)
i = i + 1
' pb1.Value = i / times * 100
If i = times Then Exit Do
b = a + c
SR.WriteLine(b)
i = i + 1
' pb1.Value = i / times * 100
If i = times Then Exit Do
c = a + b
SR.WriteLine(c)
i = i + 1
' pb1.Value = i / times * 100
If i = times Then Exit Do
Loop
SR.Close()
SR.Dispose()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
-
Apr 4th, 2007, 09:27 AM
#3
Thread Starter
New Member
Re: [2005][Newbie]StreamWriter.WriteLine() problem
o thx a lot
it worked
I didn't know that I had to close and dispose it.
Thats goes for everything like the StreamWriter or just because I used the DO loop?
Because my other apps that dont use a DO loop work just fine.
-
Apr 4th, 2007, 09:32 AM
#4
Re: [2005][Newbie]StreamWriter.WriteLine() problem
depends on what you mean by everything like the streamWriter but Yes the StreamWriter, StreamReader should be closed and disposed. Think StringWriter and StringReader too. If unsure you could always check the documentation.
Remember to resolve the thread if done (see Tools menu at top of post).
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|