• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 299
  • Last Modified:

referencing MDI Child control from bas module

I have an MDI child form which has a textbox. normally referenced using

frmR.txtMesgWindow.text = frmR.txtMesgWindow.text & Foo

where frmR is the variable referencing to the child form (frmMQ) in the MDI parent.

this child form picks up a message from MSMQ (should not affect anything) and passes it to a sub in a generic bas module, this sub then outputs the message to a textbox in either the originating MDI Child or to another MDI Child, depending on content.

however, using frmR.txtMesgWindow.text inside the bas module raises a variable not defined error. (frmR word is highlighted in debug mode!)

using
frmMQ.txtMesgWindow.text = frmMQ.txtMesgWindow.text & Foo causes a totally new form to appear, so thats not right, and is also not usable if i have multiple instances of frmMQ in the MDI application.

using "Public frmR as frmMQ" inside frmMain doesnt make a difference either.

thanks very much for assistance.
0
JooZ
Asked:
JooZ
  • 4
  • 3
  • 2
  • +1
1 Solution
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
You should check with is the startup form. If the child window is start up (project properties).
Then, the Main MDI form has a property saying AutoShowChildren (or similar...), which should be set to false.
Then, using Public frmR as frmMQ could make the difference, but if I understood correctly, you might have several frmMQ forms? You could then loop the forms collection to find the relevant frmMQ form.

CHeers
0
 
JooZAuthor Commented:
thanks for the prompt comment, angellll

startup sub is Sub Main in frmMain , which is necesary to start instantiating a whole bunch of other subs and as well as to load the child forms.

autoshowchildren was set to true, but i call frmXXX.show for every form in load anyway, so i'm not sure if it makes a difference?? set it to false anyway upon your recommendation.

i managed to find a short workaround by declaring
 Public frmR as frmMQ
in the bas module instead of in frmMain, but that will not work for multiple frmMQs and as well as a dynamic number of other child forms using frmGSMControl.

should i go with an array to hold references to instances of multiple forms, or is there a simple way of keeping track ?

code example or reference would be much appreciated
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
As I said, you can loop throug the forms collection, and using a common property you can determine if you found the frmMQ...

Here how I do such things:

dim f as form
dim fMQ as frmMQ
for each f in Forms
  if f.SomeProperty = SomeValue then
    set fMQ = f
  end if
next

if fMQ is nothing then
  'you found no relevant form frMQ...
  set fMQ = new frmMQ
  fMQ.<InitForm>...
end if

fMQ.<LoadData> ...

etc
CHeers
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
JooZAuthor Commented:
thanks for the help, theres still a few kinks to work out with the application and referencing, specifically: figuring out how to dim each instance of the same form with a unique property (use the caption?).

for example , say if i used frm.caption (?) as the check for f.someproperty in your example above, how would i *dynamically* dim *each* form instance without using an array and setting the frm.caption to a unique identifier? (the real problem, not so much the finding of the right form)

gahh.. i'm zombified and repeating myself. heh.

or is Forms already an array of type frmMQ?
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
Forms is an existing collection you can use as is.

I typically add 2 properties to my forms:
FormType as string
FormKey as string

I would choose FormType to be "MQ" for the frmMQ (on Form_Load), and FormKey would represent a key information (normally set in the <LoadData> sub.

CHeers
0
 
trkcorpCommented:
Here is an example:

'In Module:
Sub main()
Load MDIForm1
End Sub

Public Sub test_text(frm As Form, smsg As String)
frm.Text1 = smsg
End Sub

'In the MDIForm:
Private Sub MDIForm_Load()
Load Form1
Load Form2
Form1.Show vbModeless
Form2.Show vbModeless
End Sub

'On the child form1, 2 buttons & text1:
Private Sub Command1_Click()
Call test_text(Me, "Hello")
End Sub

Private Sub Command2_Click()
Call test_text(Form2, "Hello from form1")
End Sub

'On child form2, a text1 textbox...
0
 
trkcorpCommented:
PS: Use the TAG property of the child forms give each a unique ID if there are multiple instances...
0
 
nahumdCommented:
Anyway, when you asked the question, you knew which form you wanted to choose , which means that you already have a property or anything that uniquely distinguishes one form from the others.
0
 
JooZAuthor Commented:
excellent stuff :)
have got the problems worked out already, tho i still need to multi-thread the processes in each form. *its a fairly complex app, an SMS gateway, actually. (yes it can be done in VB) Will tinker around a bit and see if the algorithms work after i have multi-threaded the processes.

angelIII will get the points anyway for having provided me with great guidance.
 
after i have accepted an answer, is it possible for other people to post comments without having to pay points to view the question ?

does anyone have any comments on their multi-threading experiences or methodologies ?

also, if anyone is interested in the SMS gateway code, i'll be glad to share development ideas and code snippets. just drop me an email :)
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
Hi,

All those that have commented will see the q for free, others would need to pay 20points (once). users with the KnowledgePro profile will see all q for free.

VB6+multithreaded: never done that...

CHeers
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 4
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now