Working between forms

J

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
 
C

Chris

Jeffrey said:
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
 
J

Jeffrey Spoon

Chris <[email protected]> said:
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.
 
C

Chris

Jeffrey said:
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
 
J

Jeffrey Spoon

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[/QUOTE]

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top