-1

Currently I'm having an issue/Struggling to understand how to pull the information out of a Class Module. How I understand it is if a Class Module was an Excel sheet an instance would be a row and the public property would be the columns I have issued this problem before see link (Retrieving information from a Class module VB.Net) here is where i am with the code

In side my Class Module

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

Inserting the Information into the Class Module

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

Retrieving information out of the Class Module

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

its the for each statement the code doesn't like but i cant figure out why?

Community
  • 1
  • 1
Alex Gale
  • 55
  • 1
  • 7

1 Answers1

1

It seems as if you want to loop the properties of the type tDCVillains. You can use 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
Tim Schmelter
  • 450,073
  • 74
  • 686
  • 939
  • the VB.Net Script doesn't like GetProperties – Alex Gale Dec 11 '15 at 10:30
  • 1
    @AlexGale: you have used `GetType(tDCVillains).Getproperties()`? Is it VB.NET or VB-Script? – Tim Schmelter Dec 11 '15 at 10:35
  • the VB.Net Script doesn't like GetProperties() the Help in VB.Net Says: `Function Type.Getproperty(Name as string, blindingAttr as reflection.BindingFlags, binder as reflection.Binder, ReturnTyoe as type(), modifier As Reflection.ParameterModifier()) as Reflection.PropertyInfo(+6 overloads) – Alex Gale Dec 11 '15 at 10:39
  • No I have wrote it as you put it above – Alex Gale Dec 11 '15 at 10:41
  • 1
    @AlexGale: if i test the code i don't get any compiler errors apart from the missing `InsertmetropolisVillains` method. What version of .NET are you using? [`Type.Getproperties`](https://msdn.microsoft.com/en-us/library/aky14axb(v=vs.110).aspx) works since .NET 2.0 – Tim Schmelter Dec 11 '15 at 10:45
  • I'm using Visual Studio Express 2015 version 4.6, the compiling error i get says; Severity Code Description Project File Line Error BC30516 Overload resolution failed because no accessible 'GetProperty' accepts this number of arguments. Telemetry Import L:\SI\Exportall\Telemetry Import\Telemetry Import\Telemetry Import\ExportIO.vb 112 – Alex Gale Dec 11 '15 at 10:52
  • 1
    @AlexGale: i haven't used `GetProperty` but `GetProperties`. You want to loop all properties, you don't need a single property, do you? – Tim Schmelter Dec 11 '15 at 10:54