Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9013119
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T03:10:49+00:00 2026-06-16T03:10:49+00:00

For some time I have been wondering if it is possible to enumerate, or

  • 0

For some time I have been wondering if it is possible to enumerate, or set and index for the properties of an object or structure.

I currently have a set of custom graph generator classes for different reports, but they all accept the same structure as a parameter.

The structures’ properties’ values get set from a SQL reader that reads columns as they are set up in a table in the database. Now ideally want to loop though these column values sequentially and write them to the properties of the structure.

My Structure is as follows:

Public Structure MyStructure
    Dim GraphName As String
    Dim GraphValue As Integer
    Dim Red As Integer
    Dim Green As Integer
    Dim Blue As Integer
End Structure

Now I want to be able to loop through these properties and assign values to each. E.g.:

 Dim Struct as MyStructure
 For i as integer = 0 to 4
      Struct.i = "A value retrieved from database"
 Next i

The main idea is that i want to avoid using a case statement:

 Dim Struct as MyStruct
 For i as integer = 0 to 4
      Select Case i
          Case 0
          Struct.GraphName  = "A value retrieved from database"
          Case 1
          Struct.GraphValue = "A value retrieved from database"
          'Etc.
      End Select
 Next i

Any insight on this will be much appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T03:10:50+00:00Added an answer on June 16, 2026 at 3:10 am

    To “dynamically” access the fields, you would use reflection:

    Private Structure foo
        Public i As Integer
        Public s As String
    End Structure
    
    Private Sub bar()
    
        Dim f As foo
        Dim fields = GetType(foo).GetFields(BindingFlags.Public Or BindingFlags.Instance)
        For Each fi As FieldInfo In fields
            fi.SetValue(f, GetValueFromDBForName(fi.Name))
        Next
    
    End Sub
    

    Be aware that Reflection is NOT fast. “FasterFlect” (via NuGet) or other “fast” replacements might be an alternative. OR you consider to use an ORM (object relational mapping) “out-of-the-box”

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been using PHP for quite some time now and was wondering what
I have been using a reset CSS set of styles for quite some time
I have been wondering for some time how does Google translate(or maybe a hypothetical
For some time i have been making more or less little games. One level
I have been spending some time on this. My problem involves bringing back domain
I have been using TortoiseSVN for some time and I really like it. I
I have been looking for some time for this and I can't seem to
I have been using Perl for some time, but today I came across this
I have been learning python for some time now. While starting this learning python
I have been using InstallJammer for some time, but it's development is now discontinued.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.