Writing text to a RichTextBox
I wish to transfer user inputted text from one Form to a second, is the StreamReader the best method? or is their a simpler way of doing it? Cose example would be very much appreciated.
Secondly would the streamReader class be inputted in the Load procedure of the SecondForm to collect the data from the FirstForm?
Cheers
Olly :rolleyes:
Re: Writing text to a RichTextBox
You can reference the controls directly in child forms. The sream reader/writer is used mainly for things external to your program. Give me some of the code you have to create your two forms and I'll help you get this figured out.
Re: Writing text to a RichTextBox
StreamReader is for use with text files, not for reading from another window. The simplest way to do what you want, might be to do it on creation of the second form.
i.e,
VB Code:
Dim f As New Form2
f.Show()
f.RichTextBox1.Text = RichTextBox1.Text
Bill
1 Attachment(s)
Re: Writing text to a RichTextBox
Cheers SevenHalo, I have attached the program I'm creating. As you will see at the inputted data from the first Form is to be exported to the second Form (ReportForm), then within this RichTextBox I have to sort data.
Cheers
Olly
Re: Writing text to a RichTextBox
Sorry to nit-pick, but could you remove the compiled version from the zip? I only need the source code, I can compile it on my end (just a safety precaution for me and other members).
1 Attachment(s)
Re: Writing text to a RichTextBox
Re: Writing text to a RichTextBox
That's nothing but the exe :)
I just need the vbproj, forms and any other dlls or componenets you reference. Basically, anything BUT the exe.
1 Attachment(s)
Re: Writing text to a RichTextBox
Sorry, i'll try again! :)
Re: Writing text to a RichTextBox
Much better, so which controls are you going to write to the ReportForm?
EDIT*****
Alo, when are you wanting it to write to the other form?
Re: Writing text to a RichTextBox
When the user hits the "Purchase btn", i wanted all the txtboxes and listboxes inputted info to be transfered to the RichTextBox1. Within the Form2 load procedure I was then going to attempt to Format and perform calculations etc,
Re: Writing text to a RichTextBox
Put this in the sale's form:
VB Code:
Private WithEvents ReportFormDialog As New ReportForm
Private Sub mnuOpen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuOpen.Click
ReportFormDialog.ShowDialog()
End Sub
Private Sub BtnPurchase_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnPurchase.Click
txtReference.Text = Format(CInt(txtReference.Text), "000000")
ListBox1.Text = Format(CStr(ListBox1.Text), "0")
txtWeight.Text = Format(CInt(txtWeight.Text), "0000")
txtQuantity.Text = Format(CInt(txtQuantity.Text), "0000")
ListBox2.Text = Format(CStr(ListBox2.Text), "0")
txtBuying.Text = Format(CInt(txtBuying.Text), "0000")
txtSale.Text = Format(CInt(txtSale.Text), "0000")
'Populate Second Form
ReportFormDialog.RichTextBox1.Text = "Ref Num: " & txtReference.Text & vbNewLine
ReportFormDialog.RichTextBox1.Text += "Type Code: " & ListBox1.Text & vbNewLine
ReportFormDialog.RichTextBox1.Text += "Weight: " & txtWeight.Text & vbNewLine
ReportFormDialog.RichTextBox1.Text += "Quantity: " & txtQuantity.Text & vbNewLine
ReportFormDialog.RichTextBox1.Text += "Calc Meth: " & ListBox2.Text & vbNewLine
ReportFormDialog.RichTextBox1.Text += "Buying: " & txtBuying.Text & vbNewLine
ReportFormDialog.RichTextBox1.Text += "Sale: " & txtSale.Text
End Sub
Re: Writing text to a RichTextBox
Many thanks.
I have used the following:
'place 24 digits into Sales Text file - Input
FileOpen(1, "Mr Green.txt", OpenMode.Append)
'PrintLine(1, ReportForm)
Do Until EOF(1)
ReportForm = ReportForm & LineInput(1) & vbCrLf
Loop
PrintLine(1, ReportForm)
'joined string digits code here
Ref = ReportForm.Substring(0, 6)
Type = ReportForm.Substring(6, 1)
Weight = ReportForm.Substring(7, 4)
Quantity = ReportForm.Substring(11, 4)
Calc = ReportForm.Substring(15, 1)
Buying = ReportForm.Substring(16, 4)
Sales = ReportForm.Substring(20, 4)
'clear data from form
txtReference.Text = ""
ListBox1.Text = ""
txtWeight.Text = ""
txtQuantity.Text = ""
ListBox2.Text = ""
txtBuying.Text = ""
txtSale.Text = ""
FileClose(1)
However it isn't accepting the ReportForm, can you see where I' going wrong?
Cheers
Re: Writing text to a RichTextBox
* Meant to say have used the following after the 'Populate second Form!
Re: Writing text to a RichTextBox
ooooooookay?
Where did this file come from? I don't have anything in the original app you posted that saved a file, and the example I gave you just had the two objects work together.
Did you want the code to write to the second form or create a textfile? If you're creating a text file, do some XML. I know it's the bloody remains of something that might have resembled a dead horse, but it really is a good way to go instead of text files (ecspecially since you have architecture to your data).
BUt, if you're doing this to generate the data on the second form, don't write it to a file and then read from it (if that's what you're doing).
Catch me up here, I think you might have ran off and added in a couple more ideas I don't know about. I'm trailing a little now.
Re: Writing text to a RichTextBox
Hi, yes I wanted the inputted data to be written within the RichTexBox1 when the user clicked "Purchase". Then the data is deleted from the first form. I have to ensure that the data is writen to the RichTextBox in 24digits. All that I'm required to do once the data has been written to the second form is do a few calculations. Sort text via Print and Tab etc,
Sorry to be a pain
Cheers
Re: Writing text to a RichTextBox
No worries, you're not being a pain. :thumb:
If you don't need to save the information when the application closes, you don't need to write it to a text file at all. The code I gave you populates the richtext on the second form (although, it doesn't display the form unless you ask for it to be displayed).
If you need to do calculations, I would do them on the main form and then write them. Since the data's already parsed on that form, it might be easier then trying to decipher your richtext. Give me an example of the format you want the information to show on ReportForm's richtext.
1 Attachment(s)
Re: Writing text to a RichTextBox
Re: Writing text to a RichTextBox
So you're looking for a way to export a report, not a reusable data source?
In that case, if you're not going to use some of the preassembled reporting apps (Crystal Reports, MS SQL Reporting Services, etc.); it's going to take alot more code on your part. My only recommendation to you is check out "PadLeft" and "PadRight" members of the string type. They should be a little easier to work with than formatting. Formatting is used more for masking values to look like currency or things of that nature. For spacing, I would use the two I mentioned.