set and get properties on Shared Libraries - vb.net

i created a comp.dll for my project and then add the dll to my projects.sln (multiple projects), for every project on projects.sln i added comp.dll, and created 1 mdlmain.vb
Module mdlMain
Public master_FA As New master_FixAsset
Public objComp As New component.clsFunction
End Module
and 1 clsmain.vb to call main form on that project.
in comp.dll i made a property :
Private pubUserName as String
Public Property userName As String
Get
Return pubUserName
End Get
Set(value As String)
pubUserName = value
End Set
End Property
i changed the properties through my login.vbproj (inside projects.sln), but when i tried to get the value of that properties (from fixasset.vbproj) it returns nothing. Is it because i declare New component.clsFunctionin fixasset.vbproj so the compilers (?) create another new object in my .sln ? How can i fix this ?

Related

How to hide a public property without making it private or removing it

Premise
Suppose that we have a class in a dll with a simple public property "OldP". In a newer version of this dll, I want to change the name of this property in "NewP". I can't simply replace the property name, because this dll is used in a lot of program and I can't change them...
I want to hide this property and show only the newer property. How is this possible?
"Browsable" attempt
Before asking this, I searched similar questions on StackOverflow and read something about Browsable, but it doesn't work. Here is my code:
Public Class Example
Private _p As Integer
<System.Obsolete("Use NewP instead", False)>
<System.ComponentModel.Browsable(False)>
Public Property OldP() As Integer
Get
Return _p
End Get
Set(ByVal value As Integer)
_p = value
End Set
End Property
Public Property NewP() As Integer
Get
Return _p
End Get
Set(ByVal value As Integer)
_p = value
End Set
End Property
End Class
When I create a new Example object, I can still see "OldP":
Where I'm wrong?
You cannot completely prevent the old property from being used, but you can hide it from IntelliSense by adding this directive: <System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)>. The OldP property will no longer be suggested, but still be accessible normally.
Beside that, I recommend you change the OldP property so that it refers not to the _p object, but to the NewP property to make future management easier, so that you don't have to worry about the deprecated version in the future.

Can I create a global object and assign its value globally in VBA?

I've had no trouble creating a new object globally, but when I try to assign values to the object globally, a Compile Error pops up (Expected end of statement).
Just started with VBA, I feel like I'm going about this the wrong way. Couldn't find anything about this online.
I've listed the Class and Sub below.
Class
'Class name: FileManager
Option Explicit
Public FileName, Path As String
Public Printer As Integer
Module Variable declaration
Public Scripts As Worksheet
Public CDM As New FileManager
Public CDM.Printer = 1 '<--Where the error occurs

I have a public function still i am not able to call that function using the object?It says the function is not a member of the class

I am using visual studio 2010
I have created a public function in one class.when i try to call the that function using the objects.I am getting an error that the function is not a member of that class.
BusinessLayer :Status.vb
Public Class Status
Public Function CheckPUServiceLine(ByVal pintScenario As Integer) As Integer
Dim objStatusDac As New DataAccess.StatusDac
Dim intResult As Integer
intResult = objStatusDac.CheckPUServiceLine(pintScenario)
Return intResult
End Function
End Class
Vb:
Dim objStatusBiz As New Status
intResultForServiceLineCheck = objStatusBiz.CheckPUServiceLine(1)
When i try to call the function CheckPuServiceLine I am getting an error that
the function CheckPUServiceLine is not a member of Status
This looks like a Namespace issue. Status is a common enough class name, that I wouldn't be surprised if you are loading the wrong Status class.
Try to be explicit about the Status class, using the namespace for the class library.
Dim objStatusBiz As New MyNamespace.Status
You can usually find out which Namespace you are using by clicking on the Status class and pressing F12 to go to the definition for the class (or right clicking and choosing to go to definition).

Xbrl Validation

I have a generated XDocument that needs to be validated to Xbrl xsd's
I have created a custom XmlResolver to load all the xsd files from the external party.
This is the GetEntity Function from my resolver so i can get the included xsd's:
Public Overrides Function GetEntity(absoluteUri As Uri, role As String, ofObjectToReturn As Type) As Object
'If absoluteUri.ToString.Contains("www.xbrl.org") Then
' Nothing here yet
'End If
Dim nmSpace As String = _assembly.GetName.Name.ToString
Dim resource = String.Concat(nmSpace, ".", Path.GetFileName(absoluteUri.ToString()))
Dim result = _assembly.GetManifestResourceStream(resource)
Return result
End Function
However there are a lot of xsd's from the xbrl namespace and they don't get loaded.
I started downloading them to include them as a resource but there are just to many files so it doesn't seem like the best solution.
I hope anyone has some experience in validating an Xbrl file because i feel like i'm missing the point here :)
www.Arelle.org
This open source project contains a web-service that can be used to validate Xbrl files.
This what i implemented right now and it checks against all the required Xbrl rules
I'm using plain Xml-Xsd validation and this seems ok so far.
I implemented the custom resolver like this:
Public Class ResourceXmlResolver
Inherits XmlResolver
Private Shared _xmlUrlResolver As XmlUrlResolver = New XmlUrlResolver()
Private _assembly As Assembly
Public Sub New(assembly As Assembly)
_assembly = assembly
End Sub
Public Overrides Function GetEntity(absoluteUri As Uri, role As String, ofObjectToReturn As Type) As Object
If absoluteUri.ToString.Contains("www.xbrl.org") Then
Return _xmlUrlResolver.GetEntity(absoluteUri, role, ofObjectToReturn)
End If
Dim nmSpace As String = _assembly.GetName.Name.ToString
Dim resource = String.Concat(nmSpace, ".", Path.GetFileName(absoluteUri.ToString()))
Dim result = _assembly.GetManifestResourceStream(resource)
Return result
End Function
Public Overrides WriteOnly Property Credentials() As System.Net.ICredentials
Set(value As System.Net.ICredentials)
Throw New NotImplementedException()
End Set
End Property
End Class
The Xsd files provided by the third party are embedded resources.
I set the Assembly to the assembly containing my Xsd files, so when the GetEntity method is called by setting the resolver:
Dim schemas As XmlSchemaSet = New XmlSchemaSet()
schemas.XmlResolver = New ResourceXmlResolver(System.Reflection.Assembly.GetExecutingAssembly)
They are loaded correctly. I do however provide a check for the xsd's from www.xbrl.org.
In that case i'm using the standard XmlUrlResolver to get them from the web.
I also got this working by just downloading all the xbrl xsd's and also embedding them.
I hope this is enough validation for Xbrl but got this working so far :)

VB.NET Property as StringDictionary?

I'm trying to create a new property with a type of StringDictionary but when I use the property like a stringdictionary variable I am getting an error.
The goal is to NOT use a variable, I need to use a property for this. Behind the scenes I am saving the stringdictionary value to a global user-ID indexed collection. Here's the code that creates the property and attempts to get and set:
Public Property MaxLenDict As StringDictionary()
Get
Return GetFromCollection("MaxLenDict")
End Get
Set(Value As StringDictionary())
SaveToCollection("MaxLenDict", Value)
End Set
End Property
Public Sub ExampleSub()
If MaxLenDict("hello world") = "" Then MaxLenDict.Add("Hello World", "I'm Here")
End Sub
Get this error in ExampleSub "StringDictionary cannot be converted to string" in the IF statement on this code:
MaxLenDict("hello world")=""
So how do I successfully make and use a property as a stringdictionary?
Your property is of type StringDictionary() (an array!), not StringDictionary.
I’m not sure that using StringDictionary is advised in the first place, though. The class is simply a remnant from pre-generics versions of .NET. Use Dictionary(Of String, String) instead.