Hi,
I’m wondering what the easiest way would be to work with (i.e. return to the end user in some format) a large chunk of text.
It may be a silly question, but here’s the scenario:
I’ve got some css code that I want to return to the user, and I’d like to return it to them with the line breaks and tabs that already exist rather than giving it all in 1 line.
I also don’t want to manually insert vbcrlf and vbtab.
I’ve tried sticking the code in text files within visual basic but I think it would be a little cumbersome to retrieve it.
Basically I’d like to do the following:
if a=b then
dim test1 as string = _
"blah blah blah
blah blah blah
blah blah blah
blah blah blah
blah blah blah
blah blah blah
blah blah blah
blah blah blah
blah blah blah"
else
dim test2 as string = _
"blah blah blah
blah blah blah
blah blah blah
blah blah blah
blah blah blah
blah blah blah
blah blah blah
blah blah blah
blah blah blah"
end if
Also, SlitheryImp, could you please explain how I could set up your solution, as having a good knowledge of all possibilities would be very handy for me.
Nothing special really, I have a field defined as ntext: [CSSText] [ntext] NULL
And add a string to it in the usual manner, usually from a TextBox in Code Behind.
Use a Label control, formatted with new-line character:
label1.Text = "How to Format A Windows Forms Label, making it multi-Line: \
";
label1.Text += " * This is indented line 1\
";
label1.Text += " * This is indented line 2\
";
label1.Text += " * A) This is indented line 3\
";
label1.Text += " * B) This is indented line 4\
";
label1.Text = "How to Format A Windows Label, making it multi-Line:" & vbCrLf
label1.Text += " * This is indented line 1 " & vbCrLf
label1.Text += " * This is indented line 2 " & vbCrLf
label1.Text += " * A) This is indented line 3 " & vbCrLf
label1.Text += " * B) This is indented line 4 " & vbCrLf
Bingo! After every " in each line insert a “_”, then you can add it to the Label1.Text = myString, which would add all of the variable data together (a sentence, i.e.). Plus, if you want to start a new line add, “vbCrLf”.
Okay, so in other words, there is no way in vb to specify a large chunk of text split across several lines with a single variable, without having to add " _" for every line?
I don’t believe you
Isn’t there some way to include the contents of a text file or something?
I.e. read a css file line by line, and rebuild the string line by line into a variable.
That would work, but I don’t really know how to include a text file (As it will be installed on an end user’s machine, so I want to keep everything together).
If there is a way to just specify a chunk of text across multiple lines without having to mess around with line continuation characters, that would be preferable, but I’m lead to believe such a feature does not exist
As for the reading from text files, I don’t think the performance hit for my particular use will be noticeable, as it will be less than 100 lines of text.
It’s probably going to be most appropriate but not ideal for me.
How can I include text files with the executable when someone else goes to install it?
As for the text in a database, I don’t think that would really be appropriate, as presumably it wouldn’t take any formatting into account (Such as line break, which is the only formatting I really care about).
So all I need is for someone to help me with the inclusion of text files in a project and how to access them externally (i.e. when someone installs the software, it will have to look in the install location somewhere for these text files), and then I’ll have a solution I can use.
A Text field in the database (or nText) will preserve all formatting (tabs, line breaks etc.), I use it all the time for large chunks of user inputted text.
Okay, if I go in to the solution explorer and add an item (a text file), how can I reference that file in my project? I have a feeling that once I know that I’ll be able to proceed.
pufa I can’t seem to find my included textfile with “my.resources”
Also, SlitheryImp, could you please explain how I could set up your solution, as having a good knowledge of all possibilities would be very handy for me.