Connecting Tech Pros Worldwide Forums | Help | Site Map

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

RD
Guest
 
Posts: n/a
#1: Nov 21 '05
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


Scott Gunn
Guest
 
Posts: n/a
#2: Nov 21 '05

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


try this

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

"RD" <nospam@nospam.net> wrote in message
news:uQPayZt5EHA.4040@TK2MSFTNGP14.phx.gbl...[color=blue]
> 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
>
>[/color]


RD
Guest
 
Posts: n/a
#3: Nov 21 '05

re: Writing to a label.text on form from within a 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.

"Scott Gunn" <scott@thebigspider.co.uk> wrote in message
news:uINeQct5EHA.1404@TK2MSFTNGP11.phx.gbl...[color=blue]
> try this
>
> Module myModule
> sub mysub()
> form1.label1.text = "Hello World"
> end sub
> end module
>
> "RD" <nospam@nospam.net> wrote in message
> news:uQPayZt5EHA.4040@TK2MSFTNGP14.phx.gbl...[color=green]
> > 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
> >
> >[/color]
>
>[/color]


Gerald Hernandez
Guest
 
Posts: n/a
#4: Nov 21 '05

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


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" <nospam@nospam.net> wrote in message
news:uQPayZt5EHA.4040@TK2MSFTNGP14.phx.gbl...[color=blue]
> 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
>
>[/color]


Herfried K. Wagner [MVP]
Guest
 
Posts: n/a
#5: Nov 21 '05

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


"RD" <nospam@nospam.net> schrieb:[color=blue]
> 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[/color]

\\\
Public Sub SetLabelText(ByVal Label As Label)
Label.Text = ...
End Sub
///
[color=blue]
> end module[/color]

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/>
Cor Ligthert
Guest
 
Posts: n/a
#6: Nov 21 '05

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


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" <nospam@nospam.net>[color=blue]
> 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
>
>[/color]


Closed Thread