How to print text lines in a textbox before using Append.Text in windows form vb.net - vb.net

I am trying to add the contents of my five text boxes in the form to a multi line text box named "TextBox1". However, everytime I change the content of my textboxes, instead of adding another line with the contents it replaces the pre-existing line. How do I make the next line print.
Dim Newline As String
Newline = System.Environment.NewLine
TextBox1.Text = "Plane Truss"
TextBox1.Text = TextBox1.Text & Newline & "JointCoordinates"
TextBox1.AppendText(Newline & Joint# & " " & coordinates1 & " " & bc1 & " " & jointloads1 & " " & settlements1 & " " & jointrotation1)

Is there a way I can convert the whole multiline text box into a .txt
file?
Sure...use the Lines() property of the TextBox and File.WriteAllLines():
System.IO.File.WriteAllLines("c:\some path\folder\file.txt", Result1.Lines)

Related

How Can I join a String "" with a Value in VBA powerpoint

So I have this textbox and a string I want to set a label to the string and the value combined like this:
Lebel1.Caption = "Hello" Textbox1.Text
I don't know what the proper code is.
I guess you are having a Typo issue. Not sure if your control is Lebel or Label.
In this example you can combine a predefined Text and a Control text or Variable. Don't forget to add an space after your words.
Label1.Caption = "Hello " & Textbox1.Text & "."
Label1.Caption = "Hello " & Your variable & "."
Also you can add a line break and also use a Message Box as follows:
Msgbox = "Welcome Message." & Chr(10) & "Hello " & Textbox1.Text & "."

vb.net find and replace text inside a textbox in Word

I have this line of code which does a search and replace in a word document:
oDoc.Content.Find.Execute(FindText:="Invoice", ReplaceWith:="Invoice - Paid: " + paid_date, Replace:=word.WdReplace.wdReplaceAll)
Is there any way, i can do the search and replace inside a specific textbox in word rather than the whole document?
Here is one way to go about it.
For Each oCtl As Shape In doc.Shapes
If oCtl.Type = Microsoft.Office.Core.MsoShapeType.msoTextBox Then
oCtl.TextFrame.TextRange.Text.Replace("Invoice", "Invoice - Paid: " + paid_date)
End If
Next
This essentially searches all the text boxes in your document and replaces "Invoice"
As an attempt to find the name of the textbox try this...
For Each oCtl As Shape In doc.Shapes
If oCtl.Type = Microsoft.Office.Core.MsoShapeType.msoTextBox Then
MsgBox("Name: " & oCtl.Name & vbNewLine & "ID: " & oCtl.ID & vbNewLine & "Title: " & oCtl.Title & vbNewLine & "Text: " & oCtl.TextFrame.TextRange.Text)
End If
Next
This should give you unique or identifiable items of every textbox.
then you could just go like this -
If oCtl.Name = "1234" then oCtl.Text.replace(whatever)
or ID or Title or whatever you decide to choose.

CSV in visual Basic

I am trying to seperate the text box list I have using csv. I am saving it to excel and the titles that I have go into their individual cell, but the text boxes go into one. I want them to be in their seperate cell also.
Also, how can I add new information without overwriting the previous info saved?
Thanks
Dim csvFile As String = My.Application.Info.DirectoryPath & "\HoseData.csv"
Dim outFile As IO.StreamWriter = My.Computer.FileSystem.OpenTextFileWriter(csvFile, False)
outFile.WriteLine("job number, sales order number, date")
outFile.WriteLine(TextBox1.Tex & TextBox2.Text & DateTimePicker1.Text)
outFile.Close()
Console.WriteLine(My.Computer.FileSystem.ReadAllText(csvFile))
You need to add commas in your output:
outFile.WriteLine(TextBox1.Text & "," & TextBox2.Text & "," & DateTimePicker1.Text)
Per the additional requirement of quotes around the DateTimePicker data that was fleshed out in the comments below:
outFile.WriteLine(TextBox1.Text & "," & TextBox2.Text & "," & """" & DateTimePicker1.Text & """")
To append instead of overwrite, as Plutonix mentioned above, use
OpenTextFileWriter(csvFile, True)

Write text to log file Columns

How do I write to the columns in a .log file?
I.e there are columns for "Log Text","Component","Date/Time"
How do I specify these when writing to a file?
I've got half of it working:
dim str As String ="<![LOG[" & message & "]LOG]!><time=""" & Now.ToLongTimeString & """" & " date=""" & Now.ToShortDateString & """ component=""" & component.ToString & """" & " type=""1""" & " Thread=""" & t & """" & ">"
File.AppendAllText(logfile, str & vbCrLf)
But the component, date / time and thread values arent displaying properly.
What am I missing ?
*edited
The file path is "C:\Programdata\server.log"
So some of the text is getting into it in the right place, just not all of it.
So the log text column will get populated with "message" and thread comes in with the number but the date/time and component are empty.
I'd attach a pic but i dont have enough rep :/
In a sentance, Im trying to replicate this:
http://www.jetico.com/web_help/bcwipe6_enterprise/img/log_viewer.jpg
but not all of my columns are displaying data.
Try dividing your data into columns using commas as suggested by #Blackwood, but use string.format as you seem to have lots of extra "" in there
Dim str As String = String.Format("![LOG[{0}]LOG]!,time={1}, <date= {2}, component= {3}, type=1, Thread={4}", Message, Now.ToLongTimeString, Now.ToLongDateString, component.ToString, t)
File.AppendAllText(logfile, Str() & vbCrLf)
I'm not sure what you are doing with the <> tags.
Solved.
This is to do with the format of the data I was trying to write.
Time has to be in the format
Now.ToLongTimeString & "." & Now.Millisecond & "-60"
and date has to be seperated with - instead of /
Dunno why - when viewed the time doesnt go to that length and the date is displayed with "/"
The viewer im using for the log was cmtrace.
This was the line that got it working was ..
<![LOG[" & message & "]LOG]!><time=""" & Now.ToLongTimeString & "." & Now.Millisecond & "-60" & """" & " date=""" & d & """ component=""" & component.ToString & """" & " type=""1" & """ Thread=""" & t &""">

Removing duplicated lines from a textbox and getting the count of the removed lines. (VB.NET)

I am developing a bar management software, i did the most of the job but now i don't know the code to remove the same lines from a textbox and getting the number of the removed lines after they are removed.
My code till now:
For Each saveitem As ListViewItem In Form1.ListView1.Items
RichTextBox1.AppendText(saveitem.Text & vbNewLine)
TextBox3.AppendText(saveitem.SubItems(1).Text & vbNewLine)
Next
RichTextBox1.AppendText(vbNewLine & vbNewLine & "TOTALI:" & " " & Form1.TextBoxX5.Text & vbNewLine & "TOTALI pa TVSH:" & " " & TextBox4.Text)
One possible way :
'get array of individual line of text'
Dim textLines = TextBox3.Text.Split(New String(){vbNewLine}, StringSplitOptions.RemoveEmptyEntries)
Dim totalCount = textLines.Length
Dim noDuplicateCount = textLines.Distinct().Count()
'store number of lines removed'
Dim removedLinesCount = totalCount - noDuplicateCount
'join distinct line of texts by new line into single string'
TextBox3.Text = String.Join(vbNewLine, textLines.Distinct())