How to update label.txt from a module????

H

Hexman

In my program I have several labels that I want to update with
information that is being processed in a calculation module. I have
code similar to the following in my module. As it goes through its
process, I would like to show an update to the counts that are being
generated to show progress.

Code in a module........
cntClasses = cntClasses + 1
cntTrials = cntTrials + 3

Form1.lblCntClasses.Text = Format(cntClasses, "###,###")
Form1.lblCntTrials.Text = Format(cntTrials, "###,###")

End Code.......

I get errors on the "Form1.lbl......" statements which says "Reference
to a non-shared member requires an object reference.".

How do I rectify this? Do I have to refresh Form1 again?

Code examples or suggestions?

Sorry for the newbie questions.

Hexman
 
G

Guest

Hexman said:
In my program I have several labels that I want to update with
information that is being processed in a calculation module. I have
code similar to the following in my module. As it goes through its
process, I would like to show an update to the counts that are being
generated to show progress.

Code in a module........
cntClasses = cntClasses + 1
cntTrials = cntTrials + 3

Form1.lblCntClasses.Text = Format(cntClasses, "###,###")
Form1.lblCntTrials.Text = Format(cntTrials, "###,###")

End Code.......

I get errors on the "Form1.lbl......" statements which says "Reference
to a non-shared member requires an object reference.".

How do I rectify this? Do I have to refresh Form1 again?

Code examples or suggestions?

Sorry for the newbie questions.

Hexman

you either have to pass a reference to the form and make a property to
edit it, or pass the label into the module.

chris
 
H

Hexman

you either have to pass a reference to the form and make a property to
edit it, or pass the label into the module.

chris

Currently I have 6 labels that I want updated on the form, with more
to come. Any preference to either of the methods you mentioned? Any
code snippet of either?

Thanks,

Hexman
 
G

Guest

Hexman said:
Currently I have 6 labels that I want updated on the form, with more
to come. Any preference to either of the methods you mentioned? Any
code snippet of either?

Thanks,

Hexman

Why is this code in a module? Why not have the code in the form? Both
of those are preffered ways. To pass the form into a function just do
it like any other call:

Public sub XYZ(F as FormClass)
f.label1text = "String"
end sub

public Class FormClass
public sub CallModule
XYZ(Me)
end sub
end class
 
C

Cor Ligthert [MVP]

Hexman,

Why not use OOP

You have your labels normally on a form and when the user clicks a button
you start to update your labels

In a very very very simplified sample.

\\\\
dim myobject as new myOwnClass(100)
mylabel1 = myobject.mytext1
mylabel2 = myobject.mytext2
///
\\\
Public class MyOwnClass
Public myText1 as String
Public myText2 as Sring
Public sub New (byval PassedToMe as integer)
myText1 = (passedtome*1).ToString
myText2 = (passedtome* 5).ToString
end Sub
///

I hope this gives an idea.

Cor
 
H

Hexman

Why is this code in a module? Why not have the code in the form? Both
of those are preffered ways. To pass the form into a function just do
it like any other call:

Public sub XYZ(F as FormClass)
f.label1text = "String"
end sub

public Class FormClass
public sub CallModule
XYZ(Me)
end sub
end class

I have the code in a module because it is a data access module and is
called from several different forms.

Thanks for the example.

Hexman.
 
H

Hexman

Hexman,

Why not use OOP

You have your labels normally on a form and when the user clicks a button
you start to update your labels

In a very very very simplified sample.

\\\\
dim myobject as new myOwnClass(100)
mylabel1 = myobject.mytext1
mylabel2 = myobject.mytext2
///
\\\
Public class MyOwnClass
Public myText1 as String
Public myText2 as Sring
Public sub New (byval PassedToMe as integer)
myText1 = (passedtome*1).ToString
myText2 = (passedtome* 5).ToString
end Sub
///

I hope this gives an idea.

Cor
Thanks for the example. I'll try it.

Thanks,

Hexman
 
A

Armin Zingler

Hexman said:
I have the code in a module because it is a data access module and
is called from several different forms.


I agree with Chris. You should better either derive the Forms from a base
Form containing the common controls and put the code there, or put the
controls in a Usercontrol and place it on all your Forms.


Armin
 

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

Top