Help: what's wrong with this code snippet?
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Help: what's wrong with this code snippet?

  1. #1
    Join Date
    Dec 2008
    Posts
    19

    Help: what's wrong with this code snippet?

    Code:
    public notinheritable class myClass
    
    Private txt As String = ""
    
    Public Delegate Sub SetInfoPercentageDelegate(ByVal Percentage As Integer)
    
    Public Sub SetInfo(ByVal Text As String)
    
    txt = Text
    
    If Me.InvokeRequired Then
    
    Dim SI As New SetInfoTextDelegate(AddressOf SetInfo)
    
    Me.Invoke(SI, New Object() {Text})
    
    Else
    
    tbStatus.Text = Text
    
    End If
    
    End Sub
    
    End class
    My problem: According to my reasoning, when an invoke is required, the if condition is satisfied and the program should execute the IF part. And since in the IF part, the Setinfo method is invoked, the program should run through the Else part on the next step. But it doesn't do so... Can anybody help me with this? Thanks.
    Last edited by HanneSThEGreaT; February 14th, 2009 at 03:32 AM. Reason: Added Code Tags!

  2. #2
    Join Date
    Jan 2006
    Location
    Chicago, IL
    Posts
    14,982

    Re: Help: what's wrong with this code snippet?

    Use CODE TAGS, please.

    I think it's your definition. You need to assign something to i.
    Code:
      Dim SI As New SetInfoTextDelegate(AddressOf SetInfo)
    Try something like this:

    Code:
      Dim SI As SetInfoTextDelegate= New SetInfoTextDelegate(AddressOf SetInfo)
    (free-hand)
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center