• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 748
  • Last Modified:

Reference to a non-shared member requires an object reference

Good Evening

Experts:

I have a bit of a problem here.  Working with VB.net as an AddOn in SAP Business One.  
The problem is related to the .Net so no worries about needing SAP knowledge. I have a Class that calls another Class if the User executes a button click on the calling form.  When leaving the called form I want to refresh the calling form but I am getting an error which I really don't understand.  To refresh I have a subroutine in the calling form called FillBOMTab.  
Public Class ItemTypeMaint
        Public Sub FillBOMTab(ByVal ItNum As String)
        .....
         Dim ItemTypeROUTINGForm As New LBSI_ItemTypeROUTING(ItemNum, SelectedRoutingRowCode, Mode)
         .....
End Class

From the called form I attempt to reference FillBOMTab be qualifying it with the Project and called form reference --> Enhance.ItemTypeMaint.FillBOMTab(RoutingItemNumPassed). However, I am getting the following error:

Reference to a non-shared member requires an object reference.  How do I do that?

Not sure if this is enough info to explain my problem.  So, feel free to ask questions.

Thanks for the help,
jimbo99999
0
Jimbo99999
Asked:
Jimbo99999
  • 2
1 Solution
 
Arthur_WoodCommented:
In order to use the class that you have created, you must create an INSTANCE of that class, and then you can call the sub using that instance.

If you what to use the class as you have described, then you should change the definition of the class like this:

Public Class ItemTypeMaint
        Shared Sub FillBOMTab(ByVal ItNum As String)
        .....
         Dim ItemTypeROUTINGForm As New LBSI_ItemTypeROUTING(ItemNum, SelectedRoutingRowCode, Mode)
         .....
End Class

This creates the Sub as SHARED - meaning that it is a method of the class, not of an instance of the class.  

You then access this Sub procedure like this:

     ItemTypeMaint.FillBOMTab(RoutingItemNumPassed)


AW
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
"I have a Class that calls another Class if the User executes a button click on the calling form.  When leaving the called form I want to refresh the calling form but I am getting an error..."

The easiest way to do this is to show the "called" form MODALLY using ShowDialog() instead of Show().  This prevents the user from using the "caller" until the "callee" is closed.  The code in the "callee" is HALTED until the "called" form is closed:

Public Class ItemTypeMaint

        Public Sub Button1_Click(...) Handles Button1.Click
            Dim frm As New YourCalledFormHere
            ' initialize "frm" somehow...

            frm.ShowDialog() '  <-- code STOPS here in "ItemTypeMaint" until "frm" is closed
           
            ' now refresh this form by calling FillBOMTab()...I assume you need to pass it some value from "frm"?
            FillBOMTab(frm.SomeRetrievedValue)
        End Sub

End Class
0
 
Jimbo99999Author Commented:
Arthur Wood:
Thanks for the help.  It is working now.  I apologize for the tardiness in awarding points...

Have a good day,
jimbo99999
0
 
Arthur_WoodCommented:
Gald to be of assistance.

AW
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now