Is there a way of putting a block of text (ie a paragraph) without using the label tool?
Thanks
Dim myString As String = "Hello world " + ControlChars.NewLine + _
" trying the next line of code " + ControlChars.NewLine + _
" trying the third line of code..."
Label1.Text = myString
Fixed, this works for me.
Regardless of winform or webform, you can store your very large text in a file and use System.IO.File.File.ReadAllText Method to read that block of text and assign the read text to relevant control.
Related
I am asking the user to select a txt file from a specified folder on a server [This is in PowerPoint 2007], but I need to give them the option of selecting more than one, so I have a bit of conditional code to determine this.
One file selected uses this code:
oShape.TextFrame.TextRange.Text = Text
More than one file selected currently uses this:
oShape.TextFrame.TextRange.Text = oShape.TextFrame.TextRange.Text & vbCrLf & vbCrLf & Text
…but this results in an extra return space above it all in the field, which is a bit untidy.
Could anyone advise me on how I can modify this to only get the returns in between the two texts, but not at the beginning?
I am not entirely sure I got the problem, but I believe this will do:
oShape.TextFrame.TextRange.Text = iif(oShape.TextFrame.TextRange.Text <> "", oShape.TextFrame.TextRange.Text & vbCrLf & vbCrLf, "") & Text
I'm making a program that lets you add student info to an existing CSV text file but whenever I use append text it adds the new info to part of the last line and then a new line.
I want it to do this:
John Doe,29,Male
John Doe,29,Male
It does this instead:
John Doe,29,MaleJo
hn Doe,29,Male
Note: there isn't actually an empty line between each set of info, I just wanted it to be easy to read when I posted it here.
Here is the code for that section:
Dim swVar As IO.StreamWriter = IO.File.AppendText(frmMain.fileName)
swVar.WriteLine(txtName.Text & "," & txtAge.Text & "," & gender)
swVar.Close()
Any help would be appreciated, thanks!
A handy tool in VS2010 (and others) is snippets - right click Insert Snippets... - lots of code patterns for typical tasks. In your case here is a modified snippet:
Sub AddToFile(textToAdd As String, filePath As String)
My.Computer.FileSystem.WriteAllText(filePath, textToAdd, True)
End Sub
You may want to check/add a vbNewLine to the text being added since one is not automatically added as with WriteLine.
Not a direct reply to your stated problem, but an alternate method.
See if something like this works better:
IO.File.AppendText(frmMain.fileName, vbNewLine & txtName.Text & "," & txtAge.Text & "," & gender & vbNewLine)
AppendText will open write and close all in one operation so there's no need for a separate streamwriter. It also doesn't add newlines so those must be added separately
Unless of course you are doing a series of writes to the same file then something like this would probably be more appropriate:
Dim swVar As New IO.StreamWriter(frmMain.fileName, True)
'write your lines here
swVar.WriteLine(txtName.Text & "," & txtAge.Text & "," & gender)
swVar.Close()
So basically I have this:
A WPF window with 1 Button (btn_Convert) and 2 TextBoxes (txtBox_StringValue and txtBox_Result).
In txtBox_StringValue I then paste in a formatted string value:
"This is a Header" & vbCrLf & "======================" & _
vbCrLf & "INFO" & vbCrLf & "======================"
Then when I click btn_Convert I would like the following to happen.
Code:
Dim tempStringValue = txtBox_StringValue.Text
txtBox_Results.Text = tempStringValue
However (obviously), when I do the above the Results TextBox just displays the string again:
"This is a Header" & vbCrLf & "======================" & _
vbCrLf & "INFO" & vbCrLf & "======================"
Instead of:
This is a Header
======================
INFO
So how do I get the value of the string and then strip the containing double-quotes so that the value when assigned acts like it was a variable value set in code, not just passing a string.
From the research I have done I am guessing that I need to use Reflection, however I am not familiar with the Reflection concept and don't know how to approach it.
Any help would be greatly appreciated!
Reflection won't help you in this case. It sounds like what you're talking about is dynamically interpreting some VB.NET source code and output the result of executing that code to another text box. In that case you need to use the Code DOM classes to dynamically build an assembly in memory and execute it.
Good day,
I have been searching for a way to format output using writeline/write (streamwriter)
using RTF tags and wondering if there is a syntax for this, if it exists. I have not
been able to find a resource which clearly explains how to "pretty" up output sent to a
file.
The reason why I am asking is because I want to "print" results from my program into
a file that, at the very least, would be centered, tabbed and even bolded where possible
without requiring the user to go and futz with it. I think I saw that Crystal Reports
won't work with VB 2010 Express and, quite frankly, just want to create a file with
output.
The problem I am having is how I can make output look less like writeline did it
(you know, writeliney-ish) and more like someone took the time to make writeline
look like it did something awesome.
Here's some code to show you what I'm trying to do:
sw.Write(" RATE QUOTATION ")
sw.WriteLine(" ")
sw.WriteLine(" ")
sw.WriteLine(mycompanyname)
sw.WriteLine(mycompanyaddress1 + ControlChars.Tab + "Phone:", companyphone)
sw.WriteLine(mycompanyaddress3 + ControlChars.Tab + "Fax:", companyfax)
sw.WriteLine(cityname, stateprovince, zippostal)
sw.WriteLine("Visit us online at:", websiteaddress)
sw.WriteLine(" ")
sw.WriteLine("Quoted by:", contactname + " " + "E-mail:", contactemail)
sw.Write("Date: ")
sw.WriteLine(DateTime.Now)
sw.WriteLine(" ")
sw.WriteLine(("Customer Name:" + " " + quotename.Text), "Company:" + " " + quotecompany.Text + " " + "Customer E-mail:" + " " + quoteemail.Text)
sw.WriteLine(("Phone:" + " " + quotephone.Text + ControlChars.Tab + "Fax:" + " " + quotefax.Text))
sw.WriteLine(" ")
sw.WriteLine("Shipment Details:")
Is there a way to control writeline in such a way that you can create an RTF via streamwriter and specify formatting tags, like centering and bold, etc? I'm trying to think of a way so that the RTF header information is created when streamwriter starts it's business and prints what I want out. I don't think there's an elegant way to create a PDF either so I'm kind of opting for old school output for now.
Thanks in advance!
A StreamWriter is designed simply for writing data to a stream. There is no reason that it should know what RTF is.
If you want to use StreamWriter, you will need to calculate the RTF yourself.
There may be various RTF libraries online that would be helpful. I suggest googling for some.
As promised, started playing with some code and thought I'd share it, although I'm still trying to figure out why vbNewLine doesn't work. :/
Originally, I was trying to use streamwriter to embed RTF codes, like (\rtf1) and (\b) etc..but these do not work within writeline statements that I tried, such as:
writeline("\b This is in bold \b0")
So by pretending to have a richtext box (rtb), you can create a file that will allow font formatting and other text formatting (albeit still trying to figure out a few things lol),
which may be an alternative to streamwriter if you care about how output appears in a file.
Public Class Form1
Private Property richtextbox1 As Object
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim something As String
Dim somethingelse As String
Dim butwaittheresstillmore As String
something = TextBox1.Text
somethingelse = TextBox2.Text
butwaittheresstillmore = TextBox3.Text
Save1.InitialDirectory = "c:\users\shawn\desktop"
Save1.FileName = " "
Save1.Filter = " RTF file | *.rtf"
Save1.ShowDialog()
Dim rtb As New RichTextBox
rtb.SelectionAlignment = HorizontalAlignment.Center
rtb.Text = something & vbNewLine
rtb.SelectionAlignment = HorizontalAlignment.Left
rtb.Text = somethingelse + (" another field: ") + butwaittheresstillmore
rtb.SelectAll()
rtb.SelectionFont = New Font(New FontFamily("Arial"), 12, FontStyle.Regular,
GraphicsUnit.Pixel)
rtb.SaveFile(Save1.FileName)
End Sub
End Class
I wanted to control the font and alignment and this seems to do the trick, although I'm trying to sort out using "tab" position and line feeds. I see that I can align left, center and right. Anyway, I hope this helps someone who might otherwise want a quick way to make a document where they can control the font.
Thanks!
I would be grateful with some help with reading a text file into a Richtext box. The code I have at present appends the first line of text as I want it but the rest of the lines of text do not alter. I need a loop to read to the end of file and display in Richtext box. the code i have at present is this:-
Dim FILE_NAME As String = "C:\Test.txt"
Dim sr As New System.IO.StreamReader(FILE_NAME)
RichTextBox1.Text = sr.ReadToEnd
Dim sb As New System.Text.StringBuilder(RichTextBox1.Text)
sb.Insert(5, " ")
sb.Insert(12, " ")
sb.Insert(18, " ")
sb.Insert(25, " ")
sb.Insert(29, " ")
sb.Insert(32, " ")
sb.Insert(37, " ")
sb.Insert(44, " ")
sb.Insert(45, " ")
RichTextBox2.Text = sb.ToString
sr.Close()
I think you just want RichTextBox1.LoadFile "C:/test.txt"
that should be a backslash in the file name but my keyboard doesn't have one on this pc
The reason for the spaces is because each line of text that have the same length characters with spaces needs to be seperated to make it more readable.The original text looks like this:-
17915WHITE BLUE 001.900116A T123456111
72451BLACK ORANGE000.500208 B A123456123 'worst case
72455BLACK WHITE 002.703501 C123456124
Needs to look like below.
17915:WHITE BLUE :001.9:001:16:A :T:123456:111
72451:BLACK ORANGE:000.5:002:08: B :A:123456:123
72455:BLACK WHITE :002.7:035:01: :C:123456:124
I can produce the first line to a text file but i cannot reproduce the rest of the lines of text i think i need a loop to keep reading over the text file until the file is read.