Results 1 to 18 of 18

Thread: Writing text to a RichTextBox

  1. #1

    Thread Starter
    Hyperactive Member Olly79's Avatar
    Join Date
    May 2005
    Posts
    264

    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

  2. #2
    Banned
    Join Date
    Nov 2005
    Posts
    2,367

    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.

  3. #3
    Frenzied Member conipto's Avatar
    Join Date
    Jun 2005
    Location
    Chicago
    Posts
    1,175

    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:
    1. Dim f As New Form2
    2.         f.Show()
    3.         f.RichTextBox1.Text = RichTextBox1.Text

    Bill
    Hate Adobe Acrobat? My Codebank Sumbissions - Easy CodeDom Expression evaluator: (VB / C# ) -- C# Scrolling Text Display

    I Like to code when drunk. Don't say you weren't warned.

  4. #4

    Thread Starter
    Hyperactive Member Olly79's Avatar
    Join Date
    May 2005
    Posts
    264

    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
    Attached Files Attached Files

  5. #5
    Banned
    Join Date
    Nov 2005
    Posts
    2,367

    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).

  6. #6

    Thread Starter
    Hyperactive Member Olly79's Avatar
    Join Date
    May 2005
    Posts
    264

    Re: Writing text to a RichTextBox

    No probs, cheers
    Attached Files Attached Files

  7. #7
    Banned
    Join Date
    Nov 2005
    Posts
    2,367

    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.

  8. #8

    Thread Starter
    Hyperactive Member Olly79's Avatar
    Join Date
    May 2005
    Posts
    264

    Re: Writing text to a RichTextBox

    Sorry, i'll try again!
    Attached Files Attached Files

  9. #9
    Banned
    Join Date
    Nov 2005
    Posts
    2,367

    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?

  10. #10

    Thread Starter
    Hyperactive Member Olly79's Avatar
    Join Date
    May 2005
    Posts
    264

    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,

  11. #11
    Banned
    Join Date
    Nov 2005
    Posts
    2,367

    Re: Writing text to a RichTextBox

    Put this in the sale's form:
    VB Code:
    1. Private WithEvents ReportFormDialog As New ReportForm
    2.     Private Sub mnuOpen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuOpen.Click
    3.         ReportFormDialog.ShowDialog()
    4.     End Sub
    5.  
    6.     Private Sub BtnPurchase_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnPurchase.Click
    7.  
    8.         txtReference.Text = Format(CInt(txtReference.Text), "000000")
    9.         ListBox1.Text = Format(CStr(ListBox1.Text), "0")
    10.         txtWeight.Text = Format(CInt(txtWeight.Text), "0000")
    11.         txtQuantity.Text = Format(CInt(txtQuantity.Text), "0000")
    12.         ListBox2.Text = Format(CStr(ListBox2.Text), "0")
    13.         txtBuying.Text = Format(CInt(txtBuying.Text), "0000")
    14.         txtSale.Text = Format(CInt(txtSale.Text), "0000")
    15.  
    16.         'Populate Second Form
    17.         ReportFormDialog.RichTextBox1.Text = "Ref Num: " & txtReference.Text & vbNewLine
    18.         ReportFormDialog.RichTextBox1.Text += "Type Code: " & ListBox1.Text & vbNewLine
    19.         ReportFormDialog.RichTextBox1.Text += "Weight: " & txtWeight.Text & vbNewLine
    20.         ReportFormDialog.RichTextBox1.Text += "Quantity: " & txtQuantity.Text & vbNewLine
    21.         ReportFormDialog.RichTextBox1.Text += "Calc Meth: " & ListBox2.Text & vbNewLine
    22.         ReportFormDialog.RichTextBox1.Text += "Buying: " & txtBuying.Text & vbNewLine
    23.         ReportFormDialog.RichTextBox1.Text += "Sale: " & txtSale.Text
    24.  
    25.     End Sub

  12. #12

    Thread Starter
    Hyperactive Member Olly79's Avatar
    Join Date
    May 2005
    Posts
    264

    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

  13. #13

    Thread Starter
    Hyperactive Member Olly79's Avatar
    Join Date
    May 2005
    Posts
    264

    Re: Writing text to a RichTextBox

    * Meant to say have used the following after the 'Populate second Form!

  14. #14
    Banned
    Join Date
    Nov 2005
    Posts
    2,367

    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.

  15. #15

    Thread Starter
    Hyperactive Member Olly79's Avatar
    Join Date
    May 2005
    Posts
    264

    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

  16. #16
    Banned
    Join Date
    Nov 2005
    Posts
    2,367

    Re: Writing text to a RichTextBox

    No worries, you're not being a pain.

    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.

  17. #17

    Thread Starter
    Hyperactive Member Olly79's Avatar
    Join Date
    May 2005
    Posts
    264

    Re: Writing text to a RichTextBox

    Cheers
    Attached Files Attached Files

  18. #18
    Banned
    Join Date
    Nov 2005
    Posts
    2,367

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width