Solved

Opening a form and running a sub - can it also be dialog?

Posted on 2006-11-16
8
177 Views
Last Modified: 2010-04-23
hi there

I would like to open a form as a dialog form.  However I also need to call a sub on the opened form (I call the same form in a lot of places so the sub I am running is important, and I load child forms onto the loaded form) i.e.

dim f as form1
f.showdialog()
f.getresults(id, date)

obviously f.getresults(id, date) wouldn't be called, but I do want the characteristics of the dialog in that I don't want the user to be able to move away from the form until it is closed.

Can I have the best of both worlds somehow?
0
Comment
Question by:DavidGreenfield
[X]
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
  • 5
  • 2
8 Comments
 
LVL 10

Expert Comment

by:Kinger247
ID: 17956285
Is there no reason why you cannot do it this way ?

f.getresults(id, date)
f.showdialog()
0
 
LVL 13

Expert Comment

by:newyuppie
ID: 17956439
a proper way of doing it would be handling the dialog close event from form1 and get the values there:

dim f as form1
AddHandler f.FormClosing, AddressOf f_closing
f.ShowDialog()


    Private Sub f_closing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs)
        Dim f As Form1 = DirectCast(sender, Form1)

        somevar = f.getresults(id, date)

    End Sub
0
 
LVL 13

Expert Comment

by:newyuppie
ID: 17956443
excuse me not from form1, i meant from the form that calls the form1
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!

 

Author Comment

by:DavidGreenfield
ID: 17956522

Yes it is a little bit more compilcated that I have explained.

I have a generic "pop up" form with all the graphics in.  and I call a sub in this to load any form I want.

Sometimes the form I am loading needs to run a sub, where I tell the pop up not to load as dialog so I am able to do this.  What I really want is either to be able to switch the dialog on, or to mimick the dialog action.

so actually:

dim f as form1
popup.load(f,false) - where false means no dialog
f.getresults(id, date)
0
 
LVL 13

Accepted Solution

by:
newyuppie earned 500 total points
ID: 17956523
what i posted is the proper way if you need to retrieve values, obviously when displayed dialog has started to close, and still has the variables in memory.
if you need to run a sub when the form is loading you can pretty much hook to any event in the dialog.

dim f as form1
AddHandler f.Load, AddressOf f_load
f.ShowDialog()

etc
0
 
LVL 13

Expert Comment

by:newyuppie
ID: 17956557
maybe write your own Show sub, so inside the dialog you could have something like:
public shared sub MyShow(byval boolDialog as boolean)
  dim f as new form1
  if boolDialog then
    f.showdialog
  else
    f.show
  end if
end sub

and call from your popup
f.MyShow(true) or f.MyShow(false)
0
 

Author Comment

by:DavidGreenfield
ID: 17956982
hi newyuppie,

your method does work, I had to change my code slightly - but it is now working.

Thank you very much!
0
 
LVL 13

Expert Comment

by:newyuppie
ID: 17957010
you're welcome, thanks for the points
NY
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

726 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