• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1483
  • Last Modified:

vb.net list of variables or constants

vb.net list of variables or constants in a form

here is a list of const declarations in a form

    Public Const toSquareInch As Decimal = 1.0
    Public Const toSquareFeet As Decimal = 0.006944444444
    Public Const toSquareYard As Decimal = 0.000771604938

I want to retrive a list of these, i.e. do something that will  return the followin (the names not the contents)

     toSquareInch
     toSquareFeet
    toSquareYard
0
APLIT
Asked:
APLIT
1 Solution
 
Bart-De-BalCommented:
This gives the result that you need:

        For Each fi As System.Reflection.FieldInfo In CType(Me, Object).GetType().GetFields()
            MsgBox(fi.Name)
        Next
0
 
kiran_ramisettiCommented:
to get the value of constant variable values write like this :

       For Each fi As System.Reflection.FieldInfo In CType(Me, Object).GetType().GetFields()
            MsgBox(fi.GetValue(fi))
        Next
Result is: 1
                0.006944444444
                0.000771604938

or if you want get the name of the constatnt variables you can writte like this :
        For Each fi As System.Reflection.FieldInfo In CType(Me, Object).GetType().GetFields()
            MsgBox(fi.Name)
        Next

Result is : toSquareInch
                 toSquareFeet
                 toSquareYard
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now