.Net class library and windows application projects

FarligOpptreden

Executive Member
Joined
Mar 5, 2007
Messages
5,396
Pass the Label through to the doLoop function, instead of the Form.

Code:
Imports Test

Public Class frmGUI

    Private Sub btnGo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGo.Click
        testStuff.doLoop("value", Me.Label1)
    End Sub

End Class

Code:
Public Class doStuff

  Public Function doLoop(ByVal db As String, ByRef lbl as Label)
  
    For i = 0 To 10  
      [B]lbl.Text = i[/B]
    Next i
    
    Return Nothing
  End Function

End Class
 
Last edited:

Fuma

Executive Member
Joined
Jul 9, 2007
Messages
5,111
Pass the Label through to the doLoop function, instead of the Form.

Code:
Imports Test

Public Class frmGUI

    Private Sub btnGo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGo.Click
        testStuff.doLoop("value", Me.Label1)
    End Sub

End Class

Code:
Public Class doStuff

  Public Function doLoop(ByVal db As String, ByRef lbl as Label)
  
    For i = 0 To 10  
      [B]lbl.Text = i[/B]
    Next i
    
    Return Nothing
  End Function

End Class
Pm me your account number. I'll deposit some blood money tomorrow.
Tx guys.

I need to read more books on programming coz I'm one of those who code their way out.
 

FarligOpptreden

Executive Member
Joined
Mar 5, 2007
Messages
5,396
No blood money necessary, but maybe you can get rid of this terrible nasal congestion I'm experiencing, together with partial deafness due to my ears' inability to pop right now...

Oh, and the problem isn't the coding, per se, it's more in the logic. I guess having a sound understanding of how things work "under the hood" also helps... :D
 

dequadin

Expert Member
Joined
May 9, 2008
Messages
1,434
Glad to see this is sorted :)

For sake of completeness here's my event based solution:

The Class:
Code:
Public Class Class1
    Public Event LoopUpdated(ByVal message As String)

    Public Sub DoIt()
        For i As Integer = 0 To 10
            RaiseEvent LoopUpdated("I'm busy with record" & i.ToString)
        Next
    End Sub
End Class

The Form:
Code:
Imports ClassLibrary1

Public Class Form1
    Private Delegate Sub UpdateLabelHandler(ByVal message As String)
    Private WithEvents theClass As New Class1

    Private Sub UpdateLable(ByVal message As String) Handles theClass.LoopUpdated
        If Me.Label1.InvokeRequired Then
            Me.Label1.Invoke(New UpdateLabelHandler(AddressOf Me.UpdateLable), message)
        Else
            Me.Label1.Text = message
        End If
    End Sub


    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        theClass.DoIt()
    End Sub
End Class
 

Raithlin

Executive Member
Joined
Jan 4, 2005
Messages
5,049
Wonder what the initial problem was with referencing. Namespaces, perhaps?
 
Top