Beginner: trying to set a label from a module 
Author Message
 Beginner: trying to set a label from a module

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



Tue, 07 Jun 2005 02:19:55 GMT  
 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



Tue, 07 Jun 2005 03:15:23 GMT  
 Beginner: trying to set a label from a module

Quote:

>    Form1.Label1.Caption

Try Form1.Label1.Text = "foo"

--
           Abderaware
    Fine Components For .NET
   Turn on, tune in, download.



Tue, 07 Jun 2005 03:12:44 GMT  
 Beginner: trying to set a label from a module
You can also use in place of
Dim f As New Form1
    f.Label1.Text = "abcde"
    f.show()

form1.activeform.label1.text



Quote:
> 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



> > 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



Wed, 08 Jun 2005 17:06:56 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Beginner trying to read Visual Foxpro Database with CDX index and Fpt file

2. Beginner..trying hard

3. Beginner..trying hard

4. Resetting label.caption (beginner)

5. Beginner: the SSTAB overlap the label

6. VBA beginner needs help with Module

7. DIM / Public (Module?) beginner question

8. Beginner question: Accessing conrtrols on a from from am module

9. Trying to Add 2 Label totals (Sum)

10. corrupted database - trying to extract a module

11. Incongruous out of memory error when trying to add a function or sub to a module

12. Error trying to use a Mid point function in a module

 

 
Powered by phpBB® Forum Software