473,471 Members | 2,613 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Problem getting information from non-shared object

3 New Member
I get an error when I declare an object NOT-shared in a subclass.
I can not make this object (glNR) shared.
Is there an other way?

Code...
Expand|Select|Wrap|Line Numbers
  1. Public Class clsRap
  2.   Private glNr As String = ""  ' not shared
  3.  
  4.   Public Class clsHd
  5.     Public Sub Hd(ByVal _D As SPZClasses.clsPDF)
  6.        dim xx = glNr  ' Here I get the error
  7.        ' I need the information set in RPT1 !!
  8.     End Sub
  9.   End Class
  10.  
  11.   Public Function RPT1(ByVal _ID As String)
  12.     Dim resultaat As Boolean = True
  13.     glNr = _ID
  14.     Return resultaat
  15.   End Function
  16. End Class  'clsRap
  17.  
  18. Public Class Rap1
  19.   Dim Doc as new clsRap
  20.   Doc.RPT1(123)
  21. End Class
The error is 'Reference to a non-shared member requires an object reference'.

Does anyone can help ?
Thanks.
Mar 9 '11 #1
5 1500
R MacDonald
24 New Member
Hello, MFSPZ,

You will need to pass a reference to the "parent class" object into the "nested class" function. See the modified version of your example below:

Expand|Select|Wrap|Line Numbers
  1. Public Class clsRap
  2.     Private glNr As String = "" ' not shared
  3.  
  4.     Public Class clsHd
  5.         Public Sub Hd(ByVal _D As Object, ByVal ParentClass As clsRap)
  6.             Dim xx As String = ParentClass.glNr ' Here I get the error
  7.             ' I need the information set in RPT1 !!
  8.         End Sub
  9.     End Class
  10.  
  11.     Public Function RPT1(ByVal _ID As String) As Boolean
  12.         Dim resultaat As Boolean = True
  13.         glNr = _ID
  14.         Return resultaat
  15.     End Function
  16. End Class 'clsRap
Mar 9 '11 #2
MFSPZ
3 New Member
Thanks.
But how can I get the parentClass? I should know this in function RPT1.
Mar 10 '11 #3
R MacDonald
24 New Member
Hello, MFSPZ,

RPT1 is a function of the parent class. See the sample below for an example of calling Hd from within RPT1. Since your sample Hd function doesn't actually do anything, I have added a Debug.PrintLine statement to it to illustrate the result. I have also appended Button1_Click code to demonstrate how the Hd function can be invoked, first from within the RPT1 method, and then directly. Please see below.

Cheers,
Randy

Hello, MFSPZ,

RPT1 is a function of the parent class. See the sample below for an example of calling Hd from within RPT1. Since your sample Hd function doesn't actually do anything, I have added a Debug.PrintLine statement to it to illustrate the result. I have also appended Button1_Click code to demonstrate how the Hd function can be invoked, first from within the RPT1 method, and then directly. Please see below.

Cheers,
Randy

Public Class clsRap
Private glNr As String = "" ' not shared

Public Class clsHd
''Public Sub Hd(ByVal _D As Object)
'' Dim xx As String = glNr ' Here I get the error
'' ' I need the information set in RPT1 !!
''End Sub
Public Sub Hd(ByVal _D As Object, ByVal ParentClass As clsRap)
Dim xx As String = ParentClass.glNr
' I need the information set in RPT1 !!
Debug.WriteLine("The value of xx is """ & xx & """.")
End Sub
End Class

Public Function RPT1(ByVal _ID As String) As Boolean
Dim resultaat As Boolean = True
glNr = _ID

' Example showing a call to the nested class function
' from inside the parent class function RPT1.
Dim NestedHdClass As New clsHd
NestedHdClass.Hd(Nothing, Me)

Return resultaat
End Function

End Class 'clsRap

Public Class Rap1
Dim Doc As New clsRap

Sub Testit()
Debug.WriteLine("Value = " & Doc.RPT1("123"))
End Sub
End Class


Public Class Form1

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

' Example showing a call to the nested class function
' from inside the parent class function RPT1.
Dim SampleParentClass As New clsRap
SampleParentClass.RPT1("Set the glNr value to be this string.")

' Example showing a call to the nested class function
' from outside of the parent class.
Dim SampleNestedClass As New clsRap.clsHd
SampleNestedClass.Hd(Nothing, SampleParentClass)

End Sub

End Class
Mar 10 '11 #4
R MacDonald
24 New Member
Hi, MFSPZ,

I'm sorry about the lack of formatting in the code in the above sample. It seems that all formatting gets stripped away when I post to the thread. Perhaps there is a way to avoid this. But I'm a newbie here and if there is a way I haven't yet learned how.

Cheers,
Randy
Mar 10 '11 #5
MFSPZ
3 New Member
Thanks Randy !
I have solved the problem.
Mar 11 '11 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Skulled2003 | last post by:
Hi, I have a question on getting information from the os to be used in one of my programs. What i need to accomplish is a list of languages that are installed or can be viewed on the system. I...
1
by: Darrel Yurychuk | last post by:
I'm having a problem getting the window.onresize to work properly. Here is a simple test case I wrote: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">...
1
by: torbs | last post by:
I have a problem when I use javascript to get the length and position of a movie I recieve from a rtsp stream. The length and position is extremely high and not the actual length and position of...
1
by: kkrizl | last post by:
I have a form that displays general information about an alarm permit location. There's a subform that shows detailed information about burglar alarms that have gone off at the location. When a...
5
by: Thelma Lubkin | last post by:
I have a form/subform with the common one-to-many relationship. The form allows user to display records and move to other records via the selector, to add,delete, and edit them, with the related...
4
by: davermcl | last post by:
Hi, I'm experiencing a problem when using the VB SendKeys method. I'm sending characters to a textbox in another application. It works fine when the Windows Input Languages on both apps are...
8
by: garyusenet | last post by:
Program is witten in C++ and runs on my windows xp computer. It is a game, but I have been struggling with this project for weeks now so would appreciate some help - although I understand what i'm...
1
by: qrosity | last post by:
Why message var is always empty? var x:XML = new XML(); x.ignoreWhite = true; var total:Number; var clave:Array = new Array(); var friends:Array = new Array(); var birthday:Array = new...
0
by: bkelly1977 | last post by:
Hi all, I am trying to create a program in VB.NET that will go through the system tables of an SQL Server 2000 database and recreate it. I am making good progress but I have a couple of...
0
by: microcool1024 | last post by:
I am having a problem getting a C callback to correctly activate in a C# program after using a dllimport. Here is the declaration of the C code in the C header: typedef BOOL (CALLBACK...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.