从VB.Net中的Class模块集合中检索信息

时间:2015-12-11 10:08:18

标签: vb.net excel class class-method class-variables

目前我遇到问题/正在努力了解如何从类模块中提取信息。 我的理解是,如果一个类模块是一个Excel工作表,一个实例将是一行,公共属性将是我发出此问题的列,然后看到链接(Retrieving information from a Class module VB.Net)这里是我的代码

在我的班级模块旁边

Public Class tDCVillains 
    Public Property Gothem As Integer
    Public Property metropolis as Integer
End Class

将信息插入课程模块

Sub GrabAccessInfo()
  Dim DCVillains As New tDCVillains
  Dim VillainsCollection As New Collection
  DCVillains.Gothem = rst("Gothem").Value
  DCVillains.metropolis = rst("metropolis").Value
  VillainsCollection.Add(DCVillains)
  rst.MoveNext()
End Sub

从类模块中检索信息

Sub RackSlotAccess(DCVillains As tDCVillains)
    For Each tDCVillains As System.Reflection.PropertyInfo In tDCVillains ' its not liking tDCVillains  
        Dim ObjGothem = DCVillains.Gothem
        Dim Objmetropolis = DCVillains.metropolis
        If ObjGothem >= 1 Then 
              InsertGothemVillains(ObjGothem, 32, "I", Slot, Rack)
        End If
        If Objmetropolis >= 1 Then 
              InsertmetropolisVillains(Objmetropolis, 16, "I", Slot, Rack)
        End If
    Next
End Sub

对于代码不喜欢的每个陈述,但我无法弄清楚为什么?

1 个答案:

答案 0 :(得分:1)

好像你想要循环tDCVillains类型的属性。您可以使用Type.GetProperties

Sub RackSlotAccess(DCVillains As tDCVillains)
    Dim type = GetType(tDCVillains)
    For Each tDCVillains As System.Reflection.PropertyInfo In type.GetProperties()  
        Dim ObjGothem = DCVillains.Gothem
        Dim Objmetropolis = DCVillains.metropolis
        If ObjGothem >= 1 Then
            InsertGothemVillains(ObjGothem, 32, "I", Slot, Rack)
        End If
        If Objmetropolis >= 1 Then
            InsertmetropolisVillains(Objmetropolis, 16, "I", Slot, Rack)
        End If
    Next
End Sub