Opening a file in my program
Opening a file in my program
Opening a file in my program
Opening a file in my program
Opening a file in my program
Opening a file in my program Opening a file in my program Opening a file in my program Opening a file in my program Opening a file in my program Opening a file in my program Opening a file in my program Opening a file in my program
Opening a file in my program Opening a file in my program
Opening a file in my program
Go Back  Xtreme Visual Basic Talk > > > Opening a file in my program


Reply
 
Thread Tools Display Modes
  #21  
Old 09-13-2005, 11:12 AM
trinkus79's Avatar
trinkus79 trinkus79 is offline
Centurion
 
Join Date: Jan 2004
Location: Portland, OR
Posts: 161
Default file from program


here is a saved file from my program, you should be able to open it in word and see a little square character after the word "section" on the 16th line.That is where it messes up when I try to open the file in my prog. The file should have the .prs ext, but it wouldn't let me attach that.
Attached Files
File Type: txt tester.txt (461 Bytes, 5 views)
Reply With Quote
  #22  
Old 09-13-2005, 04:57 PM
wayneph's Avatar
waynephOpening a file in my program wayneph is offline
Web Junkie

Retired Moderator
* Expert *
 
Join Date: Apr 2004
Location: D/FW, Texas, USA
Posts: 8,393
Default

It looks like Rich Text Boxes only use LineFeed and not Carriage Return Line Feed.

This should do the replace that you're looking for: strSpecial.Replace(ControlChars.Lf,"-**-")

Then just replace it back when you read it in.
__________________
-- wayne, MSSM Retired
> SELECT * FROM users WHERE clue > 0
0 rows returned
Reply With Quote
  #23  
Old 09-13-2005, 06:13 PM
sgt_pinky's Avatar
sgt_pinky sgt_pinky is offline
Contributor
 
Join Date: Feb 2004
Location: Melbourne, Australia
Posts: 633
Default

RichTextBox definitely supports ControlChars.CrLf.

Are you sure you aren't just using ControlChars.Cr (or vbCr) somewhere, instead of ControlChars.CrLf?

Maybe have a close look at your TextBox controls. If you have any TextBoxes with Multiline set to false, then they won't support a Carriage Return and Line Feed.

The problem is definitely a bug in your code somewhere.
Reply With Quote
  #24  
Old 09-14-2005, 11:41 AM
trinkus79's Avatar
trinkus79 trinkus79 is offline
Centurion
 
Join Date: Jan 2004
Location: Portland, OR
Posts: 161
Default I am a Genius!!!!....somtimes.... :)

Well, I figured it out....

I had a richtextbox on my form to start with multiline set to true. When I saved my program to a file, it would put all the text from the richtextbox on one line, but with those funny square characters in it.

Pinky had mentioned something about textboxes with multiline...so I decided to test something just to see....

I swapped out my richtextbox for a regular textbox with multiline set to true, and when I saved my program, it put whatever was in the textbox into the file just the way it looked in the program... i.e.

In Program:
"This
is
a
test"
In File:
"This
is
a
test"

Since I couldnt get the string.replace() to work with the richtextbox, I decided to try it with the regular text box. VIOLA!!! it worked!!!

thanks for the help guys
Save Code
Code:
Dim strSpecial As String strSpecial = Me.txtSpecial.Text strSpecial = Me.txtSpecial.Text.Replace(ControlChars.CrLf, "-**-") With SFD1 .DefaultExt = ".prs" .Filter = "Production Request Sheet|*.prs|All Files|*.*" .InitialDirectory = "C:\BWFsheets\Production_Sheets" .AddExtension = True .Title = "Production Request Sheet - Save" End With If txtReporter.Text.Length = 0 Then MessageBox.Show("Please enter your name", "Reporter Name", MessageBoxButtons.OK) Exit Sub Else If System.IO.Directory.Exists("C:\BWFSheets\Production_Sheets") = False Then System.IO.Directory.CreateDirectory("C:\BWFSheets\Production_Sheets") End If If SFD1.ShowDialog = DialogResult.OK Then Dim fsStream As New FileStream(SFD1.FileName, FileMode.Create, FileAccess.ReadWrite) Dim swWriter As New StreamWriter(fsStream) Try swWriter.WriteLine(strSpecial) swWriter.Close() MessageBox.Show("File Saved in: " & SFD1.FileName, "File Saved", MessageBoxButtons.OK) Catch ex As IOException MessageBox.Show(ex.Message) End Try End If End If
Open Code
Code:
Dim arrInput(60) As String Dim intInCnt With OFD1 .DefaultExt = ".prs" .Filter = "Production Request Sheet|*.prs|All Files|*.*" .InitialDirectory = "A:\" .AddExtension = True .Title = "Production Request Sheet Open File" End With If OFD1.ShowDialog = DialogResult.OK Then Dim fsStream As New FileStream(OFD1.FileName, FileMode.Open, FileAccess.Read) Dim srReader As New StreamReader(fsStream) Try While srReader.Peek > -1 For intInCnt = 0 To 60 arrInput(intInCnt) = srReader.ReadLine() Next Me.txtSpecial.Text = arrInput(15).Replace("-**-", ControlChars.CrLf) End While srReader.Close() Me.Refresh() MsgBox("File Open Successful", MsgBoxStyle.OKOnly, "Production Request Sheet Open") Catch ex As Exception MsgBox(ex.Message) End Try End If
Well now that I got it working, just one last question....
I have an Icon for my filetype and it works and everything, except if you right click the file and do "open with." It shows the Icon, but it doesn't put the program name next to it...anyone know if that's a setting somewhere in the setup stuff?
thanks
Reply With Quote
  #25  
Old 09-14-2005, 09:46 PM
sgt_pinky's Avatar
sgt_pinky sgt_pinky is offline
Contributor
 
Join Date: Feb 2004
Location: Melbourne, Australia
Posts: 633
Default

Yeah, I have this problem too. Never managed to work it out though.
Reply With Quote
  #26  
Old 09-14-2005, 10:31 PM
jo0lsOpening a file in my program jo0ls is offline
Senior Contributor

Forum Leader
* Expert *
 
Join Date: Feb 2005
Location: London
Posts: 1,050
Default

The funny char (hex editor shows it is an LF) was appearing because you were adding all the lines of text in the rtb with one writeline statement:
Code:
' Dim strSpecial As String strSpecial = Me.rtfInstructions.Text swWriter.WriteLine(strSpecial)
Try this:
Code:
' ' Add fascinating text: Me.RichTextBox1.Text = "Blah blah" & Environment.NewLine & _ "Blah Blah Blah Blah" & Environment.NewLine & _ "Blah Blah Blah Blah" & Environment.NewLine & _ "Blah Blah Blah Blah" & Environment.NewLine & _ "Blah Blah Blah Blah" & Environment.NewLine ' Create an instance of StreamWriter to write text to a file. Dim sw As StreamWriter = New StreamWriter("c:\TestFile.txt") ' Add all the text in rich tb in one writeline statement: sw.WriteLine(Me.RichTextBox1.Text) ' Add them one at a time For i As Integer = 0 To Me.RichTextBox1.Lines.Length - 1 sw.WriteLine(Me.RichTextBox1.Lines(i)) Next sw.Close()
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
Opening a file in my program
Opening a file in my program
Opening a file in my program Opening a file in my program
Opening a file in my program
Opening a file in my program
Opening a file in my program Opening a file in my program Opening a file in my program Opening a file in my program Opening a file in my program Opening a file in my program Opening a file in my program
Opening a file in my program
Opening a file in my program
 
Opening a file in my program
Opening a file in my program
 
-->