Keeping the reference to a form

Hi experts,
I've got an *.exe project that calls a dll. The first task is, from the exe, tell the dll (through its  class) to show up a form (which in turn belongs to this dll). That's alright. But the thing is that when, from the exe, try to open a second form (without first closing the first form), this first form is still seen. How can I hide the first one with code?. I know it sounds easy enough, but take into account that when I click on the exe in order to show the second form, it goes through the class code and I lose the reference to the first one, so a "MyFirstForm.hide" wouldn't work because the dll now doesn't know who MyFirstForm is. A bit of code would clarify the problem ...

In my *.exe:

set Mydll as new DLL1.CLass1

Mydll.ShowForms(1) '1 would mean, show form 1, the 2nd call later on would be (2)

In my Class1:

Private WithEvents NewfrmMyFirstForm As MyFirstForm 'It has to be this way (WithEvents), both forms
Private WithEvents NewfrmMySecondForm As MySecondForm

public sub ShowForms(FormNumber as integer)
   select case FormNumber
       case 1
           Set NewfrmMyFirstForm = New MyFirstForm
           NewfrmMyFirstForm.show
       case 2
           Set NewfrmMySecondForm = New MySecondForm
           NewfrmMySecondForm.show
           NewfrmMyFirstForm.hide  
           'After the second call from the exe, the old reference of NewfrmMyFirstForm is lost, so there is nothing to hide!!
   end select
end sub

Any ideas on how I can keep the old reference and hide the first form so?, any other way to do it?
Cheers
Toni
AntoniLAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

AlexFMCommented:
Private WithEvents NewfrmMyFirstForm As MyFirstForm
Private WithEvents NewfrmMySecondForm As MySecondForm

public sub ShowForms(FormNumber as integer)
  select case FormNumber
      case 1
          if NewfrmMyFirstForm is Nothing then
              Set NewfrmMyFirstForm = New MyFirstForm
          end if

          NewfrmMyFirstForm.show

          if not NewfrmMySecondForm is Nothing then
              NewfrmMySecondForm.Hide
          end if

      case 2
          if NewfrmMySecondForm is Nothing then
              Set NewfrmMySecondForm = New MySecondForm
          end if

          NewfrmMySecondForm.show

          if not NewfrmMyFirstForm is Nothing then
              NewfrmMyFirstForm.hide  
          end if
  end select
end sub
0
AntoniLAuthor Commented:
Hi AlexFM,
I've been trying the "is nothing" as well and couldn't. I tried your code and the last bit (the one I'm looking for), ie:

if not NewfrmMyFirstForm is Nothing then
    NewfrmMyFirstForm.hide  
end if

is not correct because I never get into the "if", during my second call NewfrmMyFirstForm is nothing so it doesn't really work.

Any other ideas?
Ta
Toni
0
AntoniLAuthor Commented:
Actually, if I used NewfrmMyFirstForm.hide, without the conditional "if", it'd have the same effect: the second call wouldn't know who NewfrmMyFirstForm is, so there would be nothing to hide

A bit desperate now

Toni
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

bob_onlineCommented:
3 things:

1)  is form 2 being displayed modally -- if it is, the form1 hide doesn't execute until form 2 is closed.  Hide form1 before showing form2 will fix it.

However, I think it is more likely that one of these is what you need to do (your references are going out of scope).

2)  Where are you declaring the variable MyFirstForm?  At a minimum, it needs to be a module level global so that it persists as long as the class that creates it does.  Make sure the class is not terminating between showing form 1 and form 2.

3)  Where are you declaring MyDll.  If you are redeclaring it within a procedure, you are creating a second instance of it which knows nothing of form1.  It also needs to be a module level, or prehaps global, variable that you create an instance of ONCE.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
AlexFMCommented:
Do you use the same instance of Class1 in subsequent calls from exe?
0
CimperialiCommented:
make a try this way:
in your class:
'----------------------------
dim frmX as form
for each frmX in Forms
   frmX.hide
   'or unload if you need
   'unload frmX
next
'and only now:
set frmX = new theoneyouwant
frmx.show
'---------------------------
0
AntoniLAuthor Commented:
Hi guys,
thanks for all your responses, but after checking out my code I realised I was using different instances of the same dll, so, as bob_online said (3rd point), it's impossible to keep track of my forms from one call to another. I reckon bob_online is the winner, so my points are yours. Thanks to you all experts!!

Toni
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.