Solved

referencing MDI Child control from bas module

Posted on 2002-07-02
10
279 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 142

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 142

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
 

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 142

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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
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 142

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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…

760 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now