Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

referencing MDI Child control from bas module

Posted on 2002-07-02
10
284 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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

766 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