write to a Form label from a class object?

S

Steve

Hello,

If I instantiate a class object from a form I would like
to be able to write to a label on the calling form
something like

"hello from class object"

from within a subroutine inside the class object. Is this
possible?

I tried the following in the class object

Public Class MyClass
Dim frm As New Form1

Sub RunProcess()
....
frm.lbl1.Text = "hello from class object"
Do While ...
.... takes about 5 minutes to run loop
Loop
....
End sub
End Class

If it is possible to write to a label on the calling form
from within the subroutine in my class object, may I ask
what the syntax looks like?

Thanks,
Steve
 
C

Cor Ligthert

Steve,

Do you mean this?

\\\
Private Sub Form1_Load(ByVal sender _
As Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim myfiller As New filler
myfiller.sayhello(Me.Label1)
End Sub
///end form
\\\begin class
Public Class filler
Public Sub sayhello(ByVal meControl As Control)
meControl.Text = "hello from class object"
End Sub
End Class
///

Cor
 
S

Steve

Yes. Thank you. But what I really want to do is to
display a counter on Form1 from my custom class. The
class object will be retrieving data from a source. Say I
have 1000 records to retrieve. I would like to write the
count of each record to Label1 on Form1, ie: 1, 2, 3, ...
1000. I imagine this should be doable with your example.
Would your example be satisfactory for something like
this? Or is there a way that would be more correct?

I tried this in VB6 with no problem. But in my vb.net app
I have Option Strict on. I am guessing there is late
binding going on in the VB6 app. In the vb6 class I say

Class1
Dim frm As Form
Sub SayHello()
Set frm = Form1
frm.Label1 = "Hello"
End Sub

This is what I was trying to do in the vb.net app with no
luck. Any suggestions greatly appreciated. And thanks
again for your reply.

Steve
 

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