Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

Solved Problem Getting info from class

Posted on 2014-01-19
Medium Priority
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


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 13

Expert Comment

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

Accepted Solution

Jacques Bourgeois (James Burger) earned 2000 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA:…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

715 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