Question Update Label (text) on form from Module

Citabria

Member
Joined
May 1, 2010
Messages
14
Programming Experience
1-3
Hi,
I have a Main Module that loads a form. I want to update text on a Label, my code is:

Public mFormSplash As Form = New FormSplash

Sub Main
With mFormSplash
.Show()
.LoadStatus.text = "Test"
.Update()
System.Threading.Thread.Sleep(1000)
End With 'mFormSplash
...........

The code loads the form OK but does not update the Label's text (LabelStatus)
I am getting an error Error:

'LabelStatus' is not a member of 'System.Windows.Forms.Form'.

This worked ok on a previous project and I can't work out what is different.

Thanks for any assistance.
 
If mFormSplash is a FormSplash object then why declare it as type Form?
VB.NET:
Public mFormSplash As [COLOR="Red"]Form[/COLOR] = New [COLOR="Blue"]FormSplash[/COLOR]
If the object is type FormSpalsh then declare the variable as type FormSplash. Then you'll be able to access members of the FormSplash class instead of just the Form class.

That said, there's not really any point using a module to display a splash screen. VB has inbuilt splash screen functionality so there's not really a reason not to use that. Simply select FormSplash as the splash screen on the Application page of the project properties. Done.
 
Hi jmcilhinney,
Thanks for your reply,

Declaring mFormSplash as type FormSplash (Public mFormSplash As FormSplash) or (Public mFormSplash As FormSplash=New Formplash) doesn't resolve the problem, the controls on the form are still not accessible.

Also I can not use Visual Studio option to set a Splash Screen as this is not available when "Application Framewwork" option is unselected; unselecting is required to allow a Module to be the startup object (otherwise a Form has to be the Startup Object).
 
Hi again, jmchilhinney,
I did not understand your advice correctly and did not declare correctly.

I do now and have declared Public mFormSplash as New FormSplash and I can now access the controls.

If possible can you explain why declaring it as type Form and then setting it = to FormSplash is different and does not expose the controls?

thanks for your help
 
Hi
My problem has still not been resolved;
while the control 'LabelStatus' is recognised, I am getting an error
'System.NullReferenceException'
at:
.LoadStatus.Text = "Test"
 
Why exactly do you need to disable the Application Framework?

If you're getting a NullReferenceException then LoadStatus is most likely Nothing. The only other explanation I can think of is that you're handling the TextChanged event of LoadStatus and accessing a member of a null reference there. Have you viewed the call stack from the exception?
 
Hi jmcilhinney,
Thanks for your help, I was too close to the problem to see what it really was.
The Load code of the splash form was terminating with an unhandled error and without reporting or cascading back to the Main module and so the form and its controls did not exist hence the NullReferenceException.

Also re theApplication Framework, is disabled to allow the existing code to operate, originally from early VS that did not support wizardry to operate the Splash form and check for single instance etc. I should update this and run the code from a start form instead of the Main Module.

Thanks
 
Back
Top