Home All Groups Group Topic Archive Search About

Working between forms

Author
13 Apr 2005 4:13 PM
Jeffrey Spoon
Hello I have two forms which have components on them. On Screen1 I have
a component which I want to update from Screen2. However, if I simply
call the component from Screen2 it can't find it. If I create a new
instance of Screen1 in Screen2 and then call the component using a
reference, this works, but I end up with 2 Screen1's and the original
screen is not updated since I am only updating the new instance of
Screen1. How do I make the component available to Screen2? I changed the
components access property to Public but this didn't seem to make any
difference. Or can I stop the initial form from loading?

I tried to add a Main module:

Module Startup
     Public scr1 As Screen1
     Public scr2 As Screen2

     Sub Main()
         scr1 = New Screen1
         scr2 = New Screen2
         scr1.Activate()
         scr1.Show()
     End Sub
End Module

But this just partially loads the form then bombs out with no errors or
anything.

Cheers




--
Jeffrey Spoon

Author
13 Apr 2005 4:56 PM
Chris
Jeffrey Spoon wrote:
Show quoteHide quote
>
>
>
> Hello I have two forms which have components on them. On Screen1 I have
> a component which I want to update from Screen2. However, if I simply
> call the component from Screen2 it can't find it. If I create a new
> instance of Screen1 in Screen2 and then call the component using a
> reference, this works, but I end up with 2 Screen1's and the original
> screen is not updated since I am only updating the new instance of
> Screen1. How do I make the component available to Screen2? I changed the
> components access property to Public but this didn't seem to make any
> difference. Or can I stop the initial form from loading?
>
> I tried to add a Main module:
>
> Module Startup
>     Public scr1 As Screen1
>     Public scr2 As Screen2
>
>     Sub Main()
>         scr1 = New Screen1
>         scr2 = New Screen2
>         scr1.Activate()
>         scr1.Show()
>     End Sub
> End Module
>
> But this just partially loads the form then bombs out with no errors or
> anything.
>
> Cheers
>
>
>
>

You need to pass Screen2 the instance of Screen1 so that S2 knows where
S1 is.

Example:

Class S2
    Dim ptrS1 as S1
    Sub New(Value as S1)
        ptrS1 = Value
    End Sub   
End Class

Sub Main()
     scr1 = New Screen1
     scr2 = New Screen2(scr1)
End Sub

Now you will be able to act on S1 in S2.

Chris
Author
13 Apr 2005 6:03 PM
Jeffrey Spoon
In message <e8Hx6mEQFHA.***@TK2MSFTNGP12.phx.gbl>, Chris <no@spam.com>
writes
Show quoteHide quote
>
>You need to pass Screen2 the instance of Screen1 so that S2 knows where
>S1 is.
>
>Example:
>
>Class S2
>       Dim ptrS1 as S1
>       Sub New(Value as S1)
>               ptrS1 = Value
>       End Sub
>End Class
>
>Sub Main()
>    scr1 = New Screen1
>    scr2 = New Screen2(scr1)
>End Sub
>
>Now you will be able to act on S1 in S2.
>
>Chris

Thanks Chris. I still can't seem to load Screen1 properly though from
Main. The window loads and vanishes. Originally when I was loading it
straight from Screen1 it worked ok, using a form load event handler.


--
Jeffrey Spoon
Author
13 Apr 2005 6:46 PM
Chris
Jeffrey Spoon wrote:
Show quoteHide quote
> In message <e8Hx6mEQFHA.***@TK2MSFTNGP12.phx.gbl>, Chris <no@spam.com>
> writes
>
>>
>> You need to pass Screen2 the instance of Screen1 so that S2 knows
>> where S1 is.
>>
>> Example:
>>
>> Class S2
>>       Dim ptrS1 as S1
>>       Sub New(Value as S1)
>>               ptrS1 = Value
>>       End Sub
>> End Class
>>
>> Sub Main()
>>    scr1 = New Screen1
>>    scr2 = New Screen2(scr1)
>> End Sub
>>
>> Now you will be able to act on S1 in S2.
>>
>> Chris
>
>
> Thanks Chris. I still can't seem to load Screen1 properly though from
> Main. The window loads and vanishes. Originally when I was loading it
> straight from Screen1 it worked ok, using a form load event handler.
>
>


This is because all your threads have exited.  You don't have any
message loops setup.  That is just a fancy way of saying you need to use
ShowDialog (a blocking call so your thread won't exit until the form is
closed) instead of Show.

Chris
Author
13 Apr 2005 7:26 PM
Jeffrey Spoon
In message <Ode9skFQFHA.1***@tk2msftngp13.phx.gbl>, Chris <no@spam.com>
writes
>>
>
>
>This is because all your threads have exited.  You don't have any
>message loops setup.  That is just a fancy way of saying you need to
>use ShowDialog (a blocking call so your thread won't exit until the
>form is closed) instead of Show.
>
>Chris

Excellent thanks. That worked, although Screen2's components are
complaining of a null reference. I would've thought that it would use
the reference in Main? Anyway I'll work on it. Cheers.


--
Jeffrey Spoon
Author
14 Apr 2005 6:53 PM
Jeffrey Spoon
In message <J+m2ehC9JXXCF***@nowhere.nnn>, Jeffrey Spoon
<JeffreySp***@hotmail.com> writes
Show quoteHide quote
>In message <Ode9skFQFHA.1***@tk2msftngp13.phx.gbl>, Chris <no@spam.com>
>writes
>>>
>>
>>
>>This is because all your threads have exited.  You don't have any
>>message loops setup.  That is just a fancy way of saying you need to
>>use ShowDialog (a blocking call so your thread won't exit until the
>>form is closed) instead of Show.
>>
>>Chris
>
>Excellent thanks. That worked, although Screen2's components are
>complaining of a null reference. I would've thought that it would use
>the reference in Main? Anyway I'll work on it. Cheers.
>
>

Finally I have it working. Of course it was something stupidly simple
(didn't reference the module properly - doh!)

Cheers Chris.



--
Jeffrey Spoon