Hi,
time ago I asked here the same Question.
Same help, but after few tries nothing to do.
Till now I used other methods to reach my goals, but today (2009.04.18)
I decide to find THE solution of the Case.
So let me show you my attempt:
-1- Defining the Class
Imports System.Reflection
Public Class Form1
Public Class Person
Public Name As String
Public Surname As String
Public Age As Short
Public Gender As String
Sub New()
Name = String.Empty
Surname = String.Empty
Age = 0
Gender = "'Undefined'"
End Sub
Sub New(ByVal sName As String, ByVal sSurname As String, Optional ByVal iAge As Short = 0, Optional ByVal sGender As String = "Undefined")
Name = sName
Surname = sSurname
Age = iAge
Gender = sGender
End Sub
Function Info() As String
Dim sInfo As String = String.Empty
Dim Tp As Type = Me.GetType
For Each FI As FieldInfo In Tp.GetFields()
If sInfo = String.Empty Then
sInfo = FI.Name & ": " & FI.GetValue(Me)
Else
sInfo &= vbNewLine & FI.Name & ": " & FI.GetValue(Me)
End If
Next FI
Return sInfo
End Function
End Class
-2- Asking the result
Sub GetInfo()
Dim P As New Person("Alfred", "Wilson")
MsgBox(P.Info)
End Sub
-3- The Class Function 'Info' returns a string containing all the Fields of the class, with associated values, like I need:
Name: Alfred
Surname: Wilson
Age: 0
Gender: 'Undefined'
Hope it helps you!
Let me know if something is not so clear.
/r
ps
I have not tryed this with 'My.Resources' ... but with little code changes ...