473,396 Members | 2,018 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Iterate a structure to get name and value

Hello,

just wondering if someone can help me - im using the following code to
iterate around a structure and get the name of each varaibale in the
structure. Basically i need to get the value of the item in the
structure as well as the name. Would anyone have any ideas on how to go
about this ???

Dim i As Integer
Dim myType As Type = oSAgreements.GetType 'Get the type of
the object
Dim myField As FieldInfo() = myType.GetFields() 'Get the
fields from my() 'type'
For i = 0 To myField.Length - 1
System.Diagnostics.EventLog.WriteEntry("Test Value",
myField(i).name)
Next i

Any help appreciated

Thanks

Colin Graham

Sep 28 '06 #1
2 9932
Hi Colin,
To extract the field name and the value out of the code you posted
you need to amend it as below.

Public Sub TestMe()
Dim oSAgreements As New MyObject
oSAgreements.Field1 = "Value1"
oSAgreements.Field2 = "Value2"

Dim myType As Type = oSAgreements.GetType
For Each myField As Reflection.FieldInfo In myType.GetFields
Console.WriteLine("FieldName: " & myField.Name & " = " &
myField.GetValue(oSAgreements))
Next

End Sub

I'm curious however on what you're developing that would require this
type of code.

Kind Regards,
Tony

Sep 28 '06 #2
csgraham74 wrote:
Hello,

just wondering if someone can help me - im using the following code to
iterate around a structure and get the name of each varaibale in the
structure. Basically i need to get the value of the item in the
structure as well as the name. Would anyone have any ideas on how to go
about this ???

Dim i As Integer
Dim myType As Type = oSAgreements.GetType 'Get the type of
the object
Dim myField As FieldInfo() = myType.GetFields() 'Get the
fields from my() 'type'
For i = 0 To myField.Length - 1
System.Diagnostics.EventLog.WriteEntry("Test Value",
myField(i).name)
Next i
Once you have the FieldInfo for the object, you can call it's GetValue
method. myField(i).GetValue

Sep 28 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: nc | last post by:
My iterator can find my collection when my Action class calls my jsp directly, however when my Action class calls an html file that is set up with IFrames (one of which is loading that same jsp), I...
5
by: kazack | last post by:
I am a little confused with code I am looking at. My c++ book does not go into passing a structure to a function so I pulled out a c book which does. and I do not understand the prototype verses...
3
by: Matteo Cima | last post by:
hi! i have a struct like: Public struct conf { public bool debug=false; public int opPalm=-1; public int neMess=0; public bool caPart = false; }
5
by: jaso | last post by:
Hi, If have a structure of a database record like this: struct record { char id; char title; ... }; Is there some way to find out how many member variables there is in the struct and then...
3
by: bill | last post by:
All, I have the following: ...... unsafe public struct Example { public double we;
5
by: ameshkin | last post by:
What I want to do is very simple, but I'm pretty new at PHP and its a little hard for me. I have one page, where there are a rows of checkboxes. A button selects all checkboxes, and then...
15
RMWChaos
by: RMWChaos | last post by:
As usual, an overly-long, overly-explanatory post. Better too much info than too little, right? A couple weeks ago, I asked for some assistance iterating through a JSON property list so that my...
1
by: prathna | last post by:
Hi .. I have a logic:iterate tag which will display 5 rows each row with a drop downlist and 2 textfields.now by default all the rows will be shown.how do i hide all the rows except the first...
3
Kelicula
by: Kelicula | last post by:
Hi all, I am usually a Perl programmer, I have some background in javascript and am attempting to create a Googleish selector div. Please bear with me, excuse the long introduction... Here's...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.