Reputation: 97
A development/testing form contains a DataGridView that is loaded with the name and value of every variable in a global module. The downside is that adding or removing a variable requires a corresponding change to the form. Is there a way to iterate through the variables defined in a module class, getting their names and values?
Upvotes: 1
Views: 289
Reputation: 97
The vb.net code that works (amended):
Try
With dgvGlobalVariables.Rows
For Each oMember As MemberInfo In GetType(modGlobal).GetRuntimeFields
Dim oField As FieldInfo = CType(oMember, FieldInfo)
Try
Dim sValue As String = oField.GetValue(oField).ToString
.Add(oField.Name, sValue)
Catch ex As Exception
.Add(oField.Name)
End Try
Next
End With
Catch ex As Exception
With System.Reflection.MethodBase.GetCurrentMethod()
P_WriteErrorToLog(ex.ToString, .ReflectedType.Name & "." & .Name)
End With
End Try
Upvotes: 1