Writing Data to File
Writing Data to File
Writing Data to File
Writing Data to File
Writing Data to File
Writing Data to File Writing Data to File Writing Data to File Writing Data to File Writing Data to File Writing Data to File Writing Data to File Writing Data to File
Writing Data to File Writing Data to File
Writing Data to File
Go Back  Xtreme Visual Basic Talk > > > Writing Data to File


Reply
 
Thread Tools Display Modes
  #1  
Old 02-05-2012, 12:56 AM
myklue myklue is offline
Newcomer
 
Join Date: Feb 2012
Posts: 3
Default Writing Data to File


Hey guys, for a school project I have to write data from a listbox to a new file that a user can create. I can create and save a file no problem, but for some reason I can't write anything. I followed the textbook provided but when the file saves, I open it up and it is blank. I'm using fileWriter.WriteLine and I'm just test something basic to write to a file first and I can't do it:

Code:
Private Sub storeFileButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles storeFileButton.Click

        'creates a new file
        Dim result As DialogResult ' stores the file
        Dim fileName As String ' name the file to save the data
        'display window to where the user can save and name the file
        Using fileChooser As New SaveFileDialog()
            result = fileChooser.ShowDialog()
            fileName = fileChooser.FileName ' get specified file name 
        End Using ' automatic call to fileChooser.Dispose()

        If result <> Windows.Forms.DialogResult.Cancel Then
            Try
                fileWriter = New StreamWriter(fileName, True)

            Catch ex As IOException
                MessageBox.Show("Erorrr", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
            End Try

        End If

        fileWriter.WriteLine("Grade Book")


    End Sub
Appreciate any help
Reply With Quote
  #2  
Old 02-05-2012, 01:04 AM
PlausiblyDamp's Avatar
PlausiblyDampWriting Data to File PlausiblyDamp is offline
Ultimate Contributor

Forum Leader
* Expert *
 
Join Date: Nov 2003
Location: Newport, Wales
Posts: 2,058
Default

You will probably need to close the fileWriter after you have finished writing to it.
__________________
Intellectuals solve problems; geniuses prevent them.
-- Albert Einstein

Posting Guidelines Forum Rules Use the code tags
Reply With Quote
  #3  
Old 02-05-2012, 10:29 AM
myklue myklue is offline
Newcomer
 
Join Date: Feb 2012
Posts: 3
Default

........ Wow. all that pain and frustration. I hate those mistakes forgetting the simple things.
Thank you, but I have one final question.

If I want to print all the items in an array of a ListBox how would I do that? Currently I can print the first line of the array:

Code:
            
fileWriter.WriteLine(gradesListBox.Items(1).ToString())
fileWriter.Close()
I figure I could create a loop, but there has got to be a easier and more efficient way right?
Reply With Quote
  #4  
Old 02-05-2012, 11:42 AM
myklue myklue is offline
Newcomer
 
Join Date: Feb 2012
Posts: 3
Default

Oh nevermind, I got it to work! Thanks for the help.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Writing Data to File
Writing Data to File
Writing Data to File Writing Data to File
Writing Data to File
Writing Data to File
Writing Data to File Writing Data to File Writing Data to File Writing Data to File Writing Data to File Writing Data to File Writing Data to File
Writing Data to File
Writing Data to File
 
Writing Data to File
Writing Data to File
 
-->