Each line of textbox to a newline of Textfile?
Each line of textbox to a newline of Textfile?
Each line of textbox to a newline of Textfile?
Each line of textbox to a newline of Textfile?
Each line of textbox to a newline of Textfile?
Each line of textbox to a newline of Textfile? Each line of textbox to a newline of Textfile? Each line of textbox to a newline of Textfile? Each line of textbox to a newline of Textfile? Each line of textbox to a newline of Textfile? Each line of textbox to a newline of Textfile? Each line of textbox to a newline of Textfile? Each line of textbox to a newline of Textfile?
Each line of textbox to a newline of Textfile? Each line of textbox to a newline of Textfile?
Each line of textbox to a newline of Textfile?
Go Back  Xtreme Visual Basic Talk > > > Each line of textbox to a newline of Textfile?


Reply
 
Thread Tools Display Modes
  #1  
Old 08-24-2009, 10:20 PM
HQcool22's Avatar
HQcool22 HQcool22 is offline
Regular
 
Join Date: Jun 2009
Location: Oregon
Posts: 94
Default Each line of textbox to a newline of Textfile?


Hello,
I have a problem, i know i have to use a loop to get each line of the textbox onto a newline of a textfile but i dont know how to figure out how many lines of text the user has entered into a textbox. I tryed using a try statment to loop until it errors, it seems to work sometimes but other times it only takes half of the textbox and adds it to the textfile. And if atmaweapon reads this, i tryed to make better names for variables. Here is my code,

Code:
            Path = ("Meals\" & ComboBox1.SelectedItem & "\" & TextBox1.Text & ".txt")
            File = New System.IO.StreamWriter(Path)
            If ComboBox2.SelectedItem = "1" Then
                File.WriteLine(TextBox1.Text)
                File.WriteLine(ComboBox1.SelectedItem)
                File.WriteLine()
                File.WriteLine("Format = '#  |Name  |Amount'")
                File.WriteLine("Ingredince:" & ComboBox2.SelectedItem)
                File.WriteLine("1. " & INGname1.Text & " | " & INGamount1.SelectedItem & " " & INGmessur1.SelectedItem
                File.WriteLine()
                File.WriteLine("Recipe")
                For x As Integer = 0 To RichTextBox1.GetLineFromCharIndex(100)
                    Dim contents() As String = RichTextBox1.Lines
                    Dim textToWrite As String
                    Try
                        text = contents(LineNum)
                        es.WriteLine(textToWrite)
                    Catch

                    End Try
                    LineNum = LineNum + 1
                Next
                LineNum = 0
I think a fix to this would figuring out how many line of text there are... im not so shure how good it is to run a loop tell it errors for a textfile, but its the only way i could think of.

Thanks for any help,
HQcool22
__________________
I know stuff!
Reply With Quote
  #2  
Old 08-25-2009, 01:29 AM
Roger_Wgnr's Avatar
Roger_Wgnr Roger_Wgnr is offline
CodeASaurus Hex

Forum Leader
* Expert *
 
Join Date: Jul 2006
Location: San Antonio TX
Posts: 2,427
Default

I can think of several approaches but to loop the RichTextBox just use the Lines.
Code:
For Each TextToWrite as String in RichTextBox1.Lines
    Try
       es.WriteLine(textToWrite)
    Catch
    End Try
Next
Also if your going to catch errors you need to provide soe handing method.
Currently if the Write fails you just ignore it you should display a message or provide some error handling.
__________________
Code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live. ~Martin Golding
The user is a peripheral that types when you issue a read request. ~Peter Williams
MSDN Visual Basic .NET General FAQ
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
Each line of textbox to a newline of Textfile?
Each line of textbox to a newline of Textfile?
Each line of textbox to a newline of Textfile? Each line of textbox to a newline of Textfile?
Each line of textbox to a newline of Textfile?
Each line of textbox to a newline of Textfile?
Each line of textbox to a newline of Textfile? Each line of textbox to a newline of Textfile? Each line of textbox to a newline of Textfile? Each line of textbox to a newline of Textfile? Each line of textbox to a newline of Textfile? Each line of textbox to a newline of Textfile? Each line of textbox to a newline of Textfile?
Each line of textbox to a newline of Textfile?
Each line of textbox to a newline of Textfile?
 
Each line of textbox to a newline of Textfile?
Each line of textbox to a newline of Textfile?
 
-->