Solved Problem Getting info from class

Posted on 2014-01-19
Last Modified: 2014-01-19
Hi. I am trying use the following code in a standard module to get the information
from the class further on but it doesn't work. Is it something about "Friend Function"?

   Public Function oGet()
        NsgBox GetProcessorId()
    End Function

Imports System
Imports System.Management
Imports System.Windows.Forms

Public Class clsComputerInfo

    Friend Function GetProcessorId() As String
        Dim strProcessorId As String = String.Empty
        Dim query As New SelectQuery("Win32_processor")
        Dim search As New ManagementObjectSearcher(query)
        Dim info As ManagementObject

        For Each info In search.Get()
            strProcessorId = info("processorId").ToString()
        Return strProcessorId

    End Function

    Friend Function GetMACAddress() As String

        Dim mc As ManagementClass = New ManagementClass("Win32_NetworkAdapterConfiguration")
        Dim moc As ManagementObjectCollection = mc.GetInstances()
        Dim MACAddress As String = String.Empty
        For Each mo As ManagementObject In moc

            If (MACAddress.Equals(String.Empty)) Then
                If CBool(mo("IPEnabled")) Then MACAddress = mo("MacAddress").ToString()

            End If
            MACAddress = MACAddress.Replace(":", String.Empty)

        Return MACAddress
    End Function

    Friend Function GetVolumeSerial(Optional ByVal strDriveLetter As String = "C") As String

        Dim disk As ManagementObject = New ManagementObject(String.Format("win32_logicaldisk.deviceid=""{0}:""", strDriveLetter))
        Return disk("VolumeSerialNumber").ToString()
    End Function

    Friend Function GetMotherBoardID() As String

        Dim strMotherBoardID As String = String.Empty
        Dim query As New SelectQuery("Win32_BaseBoard")
        Dim search As New ManagementObjectSearcher(query)
        Dim info As ManagementObject
        For Each info In search.Get()

            strMotherBoardID = info("SerialNumber").ToString()

        Return strMotherBoardID

    End Function

End Class
Question by:Murray Brown
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 40
ID: 39792403
It can be the Friend.

A Friend method can be called only inside of the project in which it is defined. This means inside the project you can use it as a Public, but outside of the project if is treated as a Private and cannot be called.

So, if your module is in application and your Friend method is in a dll, you cannot call it. If both are in the same application or both are in the same dll, then your module should be able to call the Friend functions.

What do you mean exactly by "but it doesn't work"? Is it that you cannot call it, that you do not get the expected result or that you get an exception?
LVL 27

Expert Comment

ID: 39792415
NsgBox GetProcessorId()???

Most likely MsgBox.

Author Comment

by:Murray Brown
ID: 39792426
Ha ha..just a typo. Had tried other techniques
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now


Author Comment

by:Murray Brown
ID: 39792431
Hi James
If I put the following code in a standard module in the same project as the class
I get the error: "Reference to a non-shared member requires an object reference"
  Public Function oGet() As String
        oGet = clsComputerInfo.GetProcessorId
    End Function
LVL 12

Expert Comment

ID: 39792447
put all your functions inside the module
LVL 40

Accepted Solution

Jacques Bourgeois (James Burger) earned 500 total points
ID: 39792448
This code is a class.

Except for very special cases, you do not put a class in a module. A class usually stands alone in its own file.

And normally, you need to create an object to use it:

Dim yourObject As New clsComputerInfo()
oget = yourObject.GetProcessorID

Or maybe easier, paste the code into your module, but remove the Public Class clsComputerInfo and the End Class lines. This way, the methods will become part of your module and you will be able to call them directly as you usually do.

Note that the 3 Imports lines at the top should not be included in the module, but should be put before the module, as they are located before the Class in the original code.

Author Closing Comment

by:Murray Brown
ID: 39792464
Thanks James. I very rarely use classes. Should have know this. Appreciate the help

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question