class problem, How to get data from class

S

sympatico

i'm stuck with a class problem, i want to create a class that, say for
example gets the system time, and can be displayed in label or textbox but
can be accessed many times....

ok i'll start with a pseudo example.

VB.NET
pseudo code....

public function test(variable)
do something....anything
eg get system date,time or anything
'**********************
label1.text=result 'This works here, but not in a class?
'**********************
end function

private sub form load
timer1.interval=500
timer1.enabled=true
end sub

private sub timer1_tick()
dim x as integer
test(x)
end sub

'This works fine but i want to put this in class so, it can be accessed many
times.

class myclass
'maybe withevents of inherits timer1, not sure
public function test(variable)
do something....anything

'****problem here******

label1.text=result 'this will not work but to put in its place?

'*******************
end function
private sub timer1_tick()
dim x as integer
test(x)
end sub
end class

i cant figure out how to bring the data out of the class, for example if the
data in displayed in a label, and use it to have say tens or thousands of
labels that display this data, how do i extract it from the class.
 
C

Cor Ligthert

Sympatico,

The timers (there are 3 of those which are) are alarmclocks.

For your system time is enough,
Dim dt As DateTime = Now
MessageBox.Show(dt.ToString("hh:mm"))

In my opinion is using a class for this the wrong use of OOP.

I cannot find any reason for it, in contradiction, it makes the program less
readable and process slower, although that last is in my opinion not
important for this.

I hope this helps?

Cor
 

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