
Beginner: trying to set a label from a module
This is very different under VB.NET for there are no hidden (Form) variables
involved. You must create the reference yourself. The simplest way to
accomplish this, given your scenario, would be to pass the form as an
argument to the SetLabel() method. For example,
Public Sub SetLabel (Byval myForm as Form1)
myForm.Label1.Text = "abcde"
End Sub
Or, you might create a new instance altogether:
Public Sub SetLabel()
Dim f As New Form1
f.Label1.Text = "abcde"
f.show()
End Sub
These are not the best techniques -- the SetLabel routine could be written
in a more reusable, robust way -- but I don't want to confuse things here
and have stayed close to your code. This should give you a better idea of
how things work and how to proceed. By the way, you'll notice that VB.NET
controls no longer support a 'Caption' property; it's 'Text' now. Remember,
Windows Forms and VB6 Forms are NOT the same -- nor can they be handled
quite the same way.
Hope this helps,
Randall Hale
Quote:
> Hello everybody,
> I have just began to use VB.NET. I had added a module named "Module1" into
> the VB.NET project and then I had a statement in the module that would
> update a label "Form1". But it does not compile. I know that the
programming
> principle of VB.NET is completely different from that of VB6, but how can
I
> access a label in a form from a module? This might be a real dumb question
> but please enlighten me.
> I was trying this:
> /////////////////////////
> /////////////////////////
> Module Module1
> Public Sub SetLabel()
> Form1.Label1.Caption
> End Sub
> End Module
> //////////////////////////
> Thanking you all,
> Anonymous