dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Calling a method in an embedded Class from the Primary Class

  1. #1
    Join Date
    Sep 2018
    Posts
    38

    Calling a method in an embedded Class from the Primary Class

    Hi Everyone. I'm using Visual Studio 2017 and have found an issue in debugging that I need help with. I've embedded a Class in my Primary Class, and have tried to call a method found in that embedded class, but VS gives me an error (a squiggly red line under the name of the method, like it can't be found).

    How do I call a method in my embedded Class from my Primary Class? Can someone explain to me why my Primary Class can't "see" the methods in the embedded Class? I'll continue to search through the related articles on this site and other threads to find an answer as well.

    The version of .Net I'm using is 4.7.03056. I'm also including a screen print of the Visual Studio app with my code.Name:  pic.jpg
Views: 166
Size:  18.9 KB Thanks!

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,002

    Re: Calling a method in an embedded Class from the Primary Class

    Welcome aboard. Please post the code using code tags - the code is too hard to read in the screenshot.

  3. #3
    Join Date
    Sep 2018
    Posts
    38

    Re: Calling a method in an embedded Class from the Primary Class

    Thanks for the tip Arjay Here's the code for the Click Event I use to call the method...

    Code:
        Private Sub BtnPsBackup_Click(sender As Object, e As EventArgs) Handles BtnPsBackup.Click
            Select Case BtnPsBackup.Text
                Case "Pause Plan"
                    BtnPsBackup.Text = "Start Plan"
                    StopWatcher(LstBxBaseBackup.SelectedItem.ToString(), LstBxTargetBackup.SelectedItem.ToString())
    
            End Select
        End Sub

    Last night I decided to take the other class definition out of my primary class and enclose it in a namespace, then imported it into my primary class instead. I still couldn't call the method I needed, though. Here's the other method I'm trying to call:


    Code:
            Public Sub StopWatcher(fswBase As String, fswTarget As String)
    
                If Me.Prompt IsNot Nothing Then
                    Me.Prompt.AppendText(String.Format("Logger Stop Time: {0}" +
                                         Environment.NewLine, DateTime.UtcNow.ToString()))
                End If
    
                plnPair(0) = fswBase
                plnPair(1) = fswTarget
    
                For Each plnPath As String In plnPair
                    Me.BeginInit()
                    Me.Path = plnPath
                    Me.EnableRaisingEvents = False
                    Me.EndInit()
                Next
    
            End Sub

  4. #4
    Join Date
    Sep 2018
    Posts
    38

    Re: Calling a method in an embedded Class from the Primary Class

    Hi, I've been looking around for answers to this issue, and I think I've found what I'm looking for. I've found that importing a namespace does not make the methods of that class immediately available to the primary class. The imported class has to be instantiated in an object to make those methods available to the primary class; for instance, I had to create an object as:

    Code:
    Dim FSWatcher As Watcher
    Watcher being the imported class. After instantiating it that way, I could call my method as:

    Code:
    FSWatcher.StopWatcher(LstBxBaseBackup.SelectedItem.ToString(), LstBxTargetBackup.SelectedItem.ToString())

    Thanks for anyone looking at this issue. This seems to have solved the issue

Tags for this Thread

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




On-Demand Webinars (sponsored)