3 Replies - 935 Views - Last Post: 01 December 2012 - 01:10 PM Rate Topic: -----

#1 syllin  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 22-November 12

array of richtextbox

Posted 22 November 2012 - 10:44 AM

hi, i am a newbies in this form and the vb.
i work with vb6.
i have problem in my project.
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:
Option Explicit 

Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long 
Const GWL_EXSTYLE = (-20) 
Const WS_EX_TRANSPARENT = &H20& 
Dim Index As Integer 
Dim a As String 
Dim b As String 

Private Sub Form_Activate() 
RichTextBox1(0).SetFocus 
End Sub 

Private Sub Form_Load() 
Form1.Left = Form_Main.Left + 700 
Form1.Top = Form_Main.Top + 1700 
Form2.Show 

Dim Control As Control 
Dim result As Long 
For Each Control In Form1.Controls 
If TypeOf Control Is RichTextBox Then 
result = SetWindowLong(Control.hWnd, GWL_EXSTYLE, WS_EX_TRANSPARENT) 

End If 
Next Control 

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 only one time;
I try to explain:
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 like a butterfly.
I have also tried with "if... elseif..." but I have the same problem.
I don't understand the problem.
how do I modify the code?

thanks in advance
best regards

Is This A Good Question/Topic? 0
  • +

Replies To: array of richtextbox

#2 BobRodes  Icon User is offline

  • Your Friendly Local Curmudgeon
  • member icon

Reputation: 574
  • View blog
  • Posts: 2,989
  • Joined: 19-May 09

Re: array of richtextbox

Posted 22 November 2012 - 11:56 AM

I have the feeling that you are finding a complicated way to do something simple. Let's see what we can find. First, why are you using WS_EX_TRANSPARENT exactly?
Was This Post Helpful? 0
  • +
  • -

#3 syllin  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 22-November 12

Re: array of richtextbox

Posted 22 November 2012 - 12:37 PM

hi, BobRodes
thanks for your answer.
I use that code because the richtextboxes are over an image, and I have read that code makes the richtextboxes transparent.
the richtextboxes are over the fields of a document that I must fill many time.
maybe is this the problem? i try to cancel that code.
thanks
bye
Was This Post Helpful? 0
  • +
  • -

#4 BobRodes  Icon User is offline

  • Your Friendly Local Curmudgeon
  • member icon

Reputation: 574
  • View blog
  • Posts: 2,989
  • Joined: 19-May 09

Re: array of richtextbox

Posted 01 December 2012 - 01:10 PM

Oh, this is where your problem is:
Private Sub RichTextBox1_GotFocus(Index As Integer)
[...]
RichTextBox1(Index).SetFocus
End Sub

Every time you call SetFocus you fire the GotFocus event, see? Endless loop.

p. s. You're using the right technique to make your RichText control transparent.

This post has been edited by BobRodes: 01 December 2012 - 01:12 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1