By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,982 Members | 1,738 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,982 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Nov 21 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
try this

Module myModule
sub mysub()
form1.label1.text = "Hello World"
end sub
end module

"RD" <no****@nospam.net> wrote in message
news:uQ**************@TK2MSFTNGP14.phx.gbl...
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

Nov 21 '05 #2

P: n/a
RD
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.

"Scott Gunn" <sc***@thebigspider.co.uk> wrote in message
news:uI**************@TK2MSFTNGP11.phx.gbl...
try this

Module myModule
sub mysub()
form1.label1.text = "Hello World"
end sub
end module

"RD" <no****@nospam.net> wrote in message
news:uQ**************@TK2MSFTNGP14.phx.gbl...
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


Nov 21 '05 #3

P: n/a
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" <no****@nospam.net> wrote in message
news:uQ**************@TK2MSFTNGP14.phx.gbl...
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

Nov 21 '05 #4

P: n/a
"RD" <no****@nospam.net> schrieb:
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)
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #5

P: n/a
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

"RD" <no****@nospam.net>
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

Nov 21 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.