Writing to a label.text on form from within a module

  • Thread starter Thread starter RD
  • Start date Start date
R

RD

Form1 calls a sub that is public in module1.

How do you write a value to a text property from with this sub?

Eg

Module myModule
sub mysub()
'From here how do I write to the label1.text that is on the
currently open form (form1) that called this sub
end sub
end module

Thanks for any help,
Bob
 
try this

Module myModule
sub mysub()
form1.label1.text = "Hello World"
end sub
end module
 
Thanks,
But this does not work.
form1 is not recognized in the IDE (it shows a wavy underline) and it won't
compile.
I get reference to a non-shared member requires object reference error in
task list.

Thanks for your help.
 
If the sub method really should belong in the form class, add it to the
class.

If it should be a public method, then...
Turn the sub into a function that returns the desired caption.
Instead of a Sub, use a function in the module:
Function myfunction() as String
Return "Hello World"
End Function

Calling from Form:
label1.text = myfunction()

Or

Provide an appropriate method on your form class to update the caption.
Pass in an instance to the form to the sub, and have the sub call the
method.
Form:
Public Sub SetLabelCaption(Value as String)
label1.text = Value
End Sub

Sub:
Sub MySub(FormInstance as Form1)
...
FormInstance.SetLabelCaption ("Hello World")
End sub

Calling Sub from Form:
MySub(Me)

Or, any number of other ways. Just make sure that you provide a way to
uniquely identify the particular instance of the Form1 in question, and be
aware of potential threading issues.

Gerald
 
RD said:
Form1 calls a sub that is public in module1.

How do you write a value to a text property from with this sub?

Eg

Module myModule

\\\
Public Sub SetLabelText(ByVal Label As Label)
Label.Text = ...
End Sub
///
end module

Usage:

\\\
MyModule.SetLabelText(Me.Label1)
///
 
RD,

You would not want to do that. It is against everything that is OOP.

You can do in your form
\\\
me.label.text = MyOwnClass.Hello
///
And than you have in myownclass
\\\
class MyOwnClass
Friend Shared ReadOnly Property hello() as String
Get
Return "Hello"
End Get
End Property
///

This just as idea what is in this form crasy and I hope it gives you that?

Cor
 

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

Back
Top