Solved

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

Posted on 2006-11-16
8
174 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
  • 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
 

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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 …
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

863 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

24 Experts available now in Live!

Get 1:1 Help Now