Solved

referencing MDI Child control from bas module

Posted on 2002-07-02
10
285 Views
Last Modified: 2010-05-18
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
Comment
Question by:JooZ
  • 4
  • 3
  • 2
  • +1
10 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 7124157
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
 

Author Comment

by:JooZ
ID: 7124181
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
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 7124190
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
Technology Partners: 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!

 

Author Comment

by:JooZ
ID: 7124219
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
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 200 total points
ID: 7124224
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
 
LVL 4

Expert Comment

by:trkcorp
ID: 7124515
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
 
LVL 4

Expert Comment

by:trkcorp
ID: 7124520
PS: Use the TAG property of the child forms give each a unique ID if there are multiple instances...
0
 
LVL 2

Expert Comment

by:nahumd
ID: 7124651
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
 

Author Comment

by:JooZ
ID: 7126144
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
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 7126156
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

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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

713 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question