Retrieving information from a Class module VB.Net

2019-09-19 11:25发布

问题:

Currently I'm trying to store a bunch of integers/Strings in a Class inserting the information isn't a problem but for some reason i can't figure out how to retrieve the information

    Public Class HardwareCards
         Public Property RackAmount() As Integer
    End class 

Inserting the information

Sub GrabAccessInfo()
            Dim Hardware As New HardwareCards
            Dim HardwareCollection As New Collection
            Hardware.RackAmount = rst("RackAmount").Value
End Sub

Retrieving the information

Sub RackSlotAccess() 
    Dim type As Type = HardwareCards.GetType()
    Dim typename As Integer = type.FullName
    If HardwareCards.Hardware.DI32 >= 1 Then 'Inserting 32 bit Digital input card(s) 
        InsertDigAddresses(HardwareCards.Hardware.DI32, 32, "I", Slot, Rack)
    End If
End sub

What do i need to do to get the infomation out of the Class Module?

回答1:

You're referencing the type when calling HardwareCards, and not an initialized object. Notice how in GrabAccessInfo you declare and initialize an instance of HardwareCards into the variable Hardware. In order to access the information you assigned to the object variable Hardware, you would need to reference it in RackSlotAccess.

Sub RackSlotAccess(hardware As HardwareCards)
    'Perform logic, evaluations on hardware. Example:
    Dim currentRackAmount = hardware.RackAmount
End Sub


标签: vb.net class