CodeJunky
asked on
Explaining Class instances of variables
Hi All,
I would like if someone could explain to me how to use a class to store variable info, and be able to use that info in different forms.
Procedure1:
DIM rsv as new clRUN_SUBSCRIPTION_VARS
Procedure_2(rsv_t as clRUN_SUBSCRIPTION_VARS)
Procedure2:
I passed in rsv instance into procedure2 and assigned the values from a database query
Then pack in Procedure1 I process the data and send the rsv instance to various procedures and functions.
This all works fine. My problem is passing this RSV class instance to another form for processing.
I've managed to do it by setting the Class variables as Shared; but don't think that is what I want as it could be confused with other calls to the class to create a different instance of the class.
Hope I'm explain this correctly.
thanks,
John.
I would like if someone could explain to me how to use a class to store variable info, and be able to use that info in different forms.
Public Class clRUN_SUBSCRIPTION_VARS
'Data
Public ITEM_KEY As Int32
Public sItem_NAME As String
Public sITEM_NAME_DESC As String
Public Sub New()
ITEM_KEY = Nothing
sItem_NAME = Nothing
sITEM_NAME_DESC = Nothing
End Sub
Procedure1:
DIM rsv as new clRUN_SUBSCRIPTION_VARS
Procedure_2(rsv_t as clRUN_SUBSCRIPTION_VARS)
Procedure2:
I passed in rsv instance into procedure2 and assigned the values from a database query
Then pack in Procedure1 I process the data and send the rsv instance to various procedures and functions.
This all works fine. My problem is passing this RSV class instance to another form for processing.
I've managed to do it by setting the Class variables as Shared; but don't think that is what I want as it could be confused with other calls to the class to create a different instance of the class.
Hope I'm explain this correctly.
thanks,
John.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
If I don't declare the class variable as Public Shared then the class variables assigned values do not exists in the second form.
in the load event of the 2nd form I have
ReportTypeName$ = RSV_T.sITEM_NAME_DESC
error:
System.NullReferenceExcept ion
HResult=0x80004003
Message=Object reference not set to an instance of an object.
in the load event of the 2nd form I have
ReportTypeName$ = RSV_T.sITEM_NAME_DESC
error:
System.NullReferenceExcept
HResult=0x80004003
Message=Object reference not set to an instance of an object.
ASKER
I also put in the 2nd form...
Sub New(RSV_T As clRUN_SUBSCRIPTION_VARS)
' This call is required by the designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
End Sub
>>If I don't declare the class variable as Public Shared then the class variables assigned values do not exists in the second form.
Do what I suggest and pass it as a parameter.
Do what I suggest and pass it as a parameter.
ASKER
I have tried that very thing...
Dim RSV As New clRUN_SUBSCRIPTION_VARS
RSV.MODE = RM
RSV.SCHED_ID = SCHEDULE_ID_RAN
Dim RPT_VIEWER As New frmSSRS_VIEWER(RSV)
RPT_VIEWER.Show()
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I got it working..
I had to create a variable in Form2 and then assign that variable the parameter in Sub New.
Thanks very much for your help.
I had to create a variable in Form2 and then assign that variable the parameter in Sub New.
Thanks very much for your help.
That is what you have to do if you require the information elsewhere.
ps.
Your DoSomething (from my example) could also call the .Show() of the form after taking whatever data it requires from the parameter. However forcing the call to New does mean you can only create the second form with the information it requires.
ps.
Your DoSomething (from my example) could also call the .Show() of the form after taking whatever data it requires from the parameter. However forcing the call to New does mean you can only create the second form with the information it requires.
ASKER
Ok, thanks. I set a new var class to the existing class(with data), without using a New()
pseudo code
class frm2
public sub DoSomething(param as clRUN_SUBSCRIPTION_VARS) as X
end class
and in form1
dim f as new frm2
dim p as new clRUN_SUBSCRIPTION_VARS
'fill in values into p
f.DoSomething(p)
Note classes are passed by reference automatically