Results 1 to 8 of 8

Thread: richtexbox array

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2012
    Posts
    4

    richtexbox array

    hi, greet to everybody
    i have a problem with vb6.

    I have 2 forms visualized at the same time.
    in form1 I have an array of richtextbox1;
    in form2 I have an array of richtextbox2;
    when I fill richtextbox1, index (0), the same text is inserted in richtextbox2, example index(1) in form2.

    this is also worth for the other richtextbox1.
    in form2, there are richtextbox2 that I must directly fill, (they don't have the correspondent in form1).
    in form1 I have inserted this code:
    Code:
    Private Sub Form_Activate()    
    RichTextBox1(0).SetFocus    
    End Sub
    
    Private Sub RichTextBox1_GotFocus(Index As Integer)    
    RichTextBox1(Index).SelStart = 0    
    RichTextBox1(Index).SelLength = Len(RichTextBox1(Index).Text)    
    RichTextBox1(Index).SetFocus    
    End Sub   
    
    Private Sub RichTextBox1_Change(Index As Integer)    
    On Error GoTo Errhandler    
      
    Select Case Index    
    Case 0    
      
    Form2.RichTextBox2(6).Text = _    
    Form1.RichTextBox1(0).Text    
      
    Case 1    
      
    a = CStr(Form1.RichTextBox1(1).Text)    
    Form2.RichTextBox2(7).Text = CStr(a)    
      
    Case 2    
      
    a = CStr(Form1.RichTextBox1(1).Text)    
    b = CStr(Form1.RichTextBox1(2).Text)    
    Form2.RichTextBox2(7).Text = CStr(a) + "," + " " + "n°" + " " + (b)    
      
    Case 3    
    a = CStr(Form1.RichTextBox1(3).Text)    
    Form2.RichTextBox2(8).Text = CStr(a)    
      
    Case 4    
    Form2.RichTextBox2(9).Text = _    
    Form1.RichTextBox1(4).Text    
      
    Case 5    
      
    a = CStr(Form1.RichTextBox1(4).Text)    
    b = CStr(Form1.RichTextBox1(5).Text)    
    Form2.RichTextBox2(9).Text = CStr(a) + "," + " " + "n°" + " " + (b)    
      
    and so on....    
    End Select    
      
    Errhandler:    
    Exit Sub    
    End Sub
    this code works but if I write in the richtextbox1s of form1 the text it passes in richtextbox2 of form2;
    if I write in the richtextbox2s and then return in form1 and click in a whatever richtextbox1 the vb stops him and the screen is flashing.
    how do I modify the code?

    thanks

    best regards

  2. #2
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    Re: richtexbox array

    No idea what you are trying to describe. more detail on the problem please.

  3. #3

    Thread Starter
    New Member
    Join Date
    Nov 2012
    Posts
    4

    Re: richtexbox array

    hi, good evening
    I am trying to do this:
    the richtextbox1(0) in the form 1 receives the focus:
    then i fill the richtextbox 1, index (0) in the form 1;
    automatically the same text appears in the richtextbox 2, index (0) in the form 2;

    text of richtextbox 2, index (0) in the form 2 = text of richtextbox 1, index (0) in the form 1

    after the richtextbox1(1) in the form 1 receives the focus:
    then i fill the richtextbox 1, index (1) in the form 1;
    automatically the same text appears in the richtextbox 2, index (1) in the form 2;

    text of richtextbox 2, index (1) in the form 2 = text of richtextbox 1, index (1) in the form 1

    and so on for the other richtextbox in the form 1.
    i need also to to this:
    in some cases I must add the string, or text, of 2 richtextbox in the form 1;
    the result must appear in the richtexbox of form 2:

    text of richtextbox 2, index (2) in the form 2 = text of richtextbox 1, index (3) in the form 1
    + text of richtextbox 1, index (4) in the form 1.

    in the form 2 i have other richtextbox, not array, and i fill those too.
    when I have finished filling the richtextboxes, it is possible that I come back to form 1 for change something;
    this last event creates the problem that I have with the code that I have written you
    I hope to have been clear with the explanation
    thanks, bye

  4. #4
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,143

    Re: richtexbox array

    That long, confusing explanation, is NOT what your code says.
    First, your code says that form2.richtextbox(6).text will equal form1.richtextbox(0).text
    (Case 0
    Form2.RichTextBox2(6).Text = _
    Form1.RichTextBox1(0).Text )
    Yet you SAY you want RTB2(0) to equal RTB1(0)
    (then i fill the richtextbox 1, index (0) in the form 1;
    automatically the same text appears in the richtextbox 2, index (0) in the form 2
    SO...let's first get THAT part down....which do you want, index 6 or index 0 of RTB2 to equal index 0 of RTB1? ONce you answer that, we'll continue to analyze what you want.

    PS....if you want what you SAY., then your code would be (for Case 0)...form2.richtextbox(0).text =form1.richtextbox(0).text.

  5. #5

    Thread Starter
    New Member
    Join Date
    Nov 2012
    Posts
    4

    Re: richtexbox array

    I am sorry not to have explained well.
    my code says the truth, since in form 2 i have a richtextbox's array, while the explanation of the post was an example about what I would want to get.
    maybe i can change the index
    I try to help me with an image:

    Name:  form.gif
Views: 97
Size:  24.5 KB

    this image is correct.
    then i fill form 1, and the result is:

    Form2.RichTextBox2(0).Text = Form1.RichTextBox1(0).Text

    Form2.RichTextBox2(1).Text = Form1.RichTextBox1(1).Text + Form1.RichTextBox1(2).Text

    Form2.RichTextBox2(2).Text = Form1.RichTextBox1(3).Text

    Form2.RichTextBox2(3).Text = Form1.RichTextBox1(4).Text + Form1.RichTextBox1(5).Text

    I hope to have clarified what I intend to do.

    thanks, bye

  6. #6
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    Re: richtexbox array

    You said
    this code works but if I write in the richtextbox1s of form1 the text it passes in richtextbox2 of form2;
    if I write in the richtextbox2s and then return in form1 and click in a whatever richtextbox1 the vb stops him and the screen is flashing.
    how do I modify the code?
    Is the code you posted from form1 or from form2? If it is form2 code then do you also have code in the form1 activate event and/or in the rtb lost focus/got focus events?

  7. #7

    Thread Starter
    New Member
    Join Date
    Nov 2012
    Posts
    4

    Re: richtexbox array

    hi, good morning
    the code that I have sent is in form 1.
    in form 2 therisn't code.
    perhaps DataMiser has understood what is the problem;
    in form 1 infact I don't have written the event lostfocus.
    but now I ask you what I must write in the event lost focus?
    can you make me an example please?
    I have looked for examples in the web but I don't write a code that works
    thanks, bye

  8. #8
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,143

    Re: richtexbox array

    Might I suggest a slightly different approach...to keep the code a bit simpler.
    On Form2, use an array of RichTextBox1's instead of RichTextBox2's.
    And on Form1, use a combination of RichTextBox1's and RichTextBox2's (see the attached/included image)

    And in your code, do this:

    Code:
    Private Sub RTB1_Change(Index As Integer)   
         Form2.RTB1(Index).Text = Form1.RTB1(Index).Text
    End Sub
    
    Private Sub RTB2_LostFocus(Index As Integer)
    Select Case Index
        Case 0 
             Form2.RTB1(1).Text = Form2.RTB1(1).Text + "  " + Form1.RTB2(0).Text
        Case 1     
             Form2.RTB1(3).Text = Form2.RTB1(3).Text + "  " + Form1.RTB2(1).Text
        Case 2     
             Form2.RTB1(5).Text = Form2.RTB1(5).Text + "  " + Form1.RTB2(2).Text
    Rem  and so forth.....
    End Select
    End Sub
    Attachment 93615

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