Topaz Filer: if you use e-mail for business, we can save you money and decrease your risk.
Iterating through the constants in a structure
Messages   Related Types
This message was discovered on microsoft.public.dotnet.languages.vb.
Responses highlighted in red are from those people who are likely to be able to contribute good, authoratitive information to this discussion. They include Microsoft employees, MVP's and others who IMHO contribute well to these kinds of discussions.

Bob Day
Using VS 2003, VB.NET, MSDE

Is there a way to itterate through the items in a structure? Consider the
structure below, which holds the name of wave files. I would like to
itterate through them to confirm the wave files actually exist on the hard
disk. I don't see any collection or way to do it.

I would like something like this (or anything that would work):

dim Constant as Structure_Prompts_Constant

For each Constant in Structure_Prompts_Constant_Collection
' code to confirm file exists
next
------------------------------------------------------
Friend Structure Prompts

Public Const PlayPINAccessDenied1of2 As String =
"Play_PIN_Access_Denied_1of2.wav"

Public Const PlayPINAccessDenied2aof2 As String =
"Play_PIN_Access_Denied_2aof2.wav"

Public Const PlayPINAccessDenied2bof2 As String =
"Play_PIN_Access_Denied_2bof2.wav"

End Structure

Thanks!

Bob Day

Reply to this message...
Vote that this is a GOOD answer...
 
Auto-following on Twitter
Ubuntu and XP on one “desktop”
 
    
Armin Zingler
"Bob Day" <Click here to reveal e-mail address> schrieb
[Original message clipped]

http://msdn.microsoft.com/library/en-us/cpguide/html/cpcondiscoveringtypeinformationatruntime.asp

--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Reply to this message...
Vote that this is a GOOD answer...
 
Outlook interop - stopping user properties appearing on Outlook message print
Seriously, why is “cut and paste” majorly newsworthy???
 
    
Urs Eichmann
Bob Day wrote:

[Original message clipped]

How about something like

Friend Structure Prompts
    Public WaveFiles() as String=New String()
{"Play_PIN_Access_Denied_1of2.wav", "Play_PIN_Access_Denied_2aof2.wav",
"Play_PIN_Access_Denied_2bof2.wav"}
End Structure

then you can iterate through WaveFiles and don't need to use slow and
ugly Reflection code.

Regards,
Urs

Reply to this message...
Vote that this is a GOOD answer...
 
 
    
Peter Huang (VIP)
Hi Bob,

Thanks for posting in the community.

First of all, I would like to confirm my understanding of your issue.
From your description, I understand that you wants to iterate through the
fields of a structure.
Have I fully understood you? If there is anything I misunderstood, please
feel free to let me know.

I agree with Armin's suggestion, reflection will be a good choice.
Here is some code.

Dim ob As Prompts
Dim fdinfo() As FieldInfo = ob.GetType().GetFields()
For Each o As FieldInfo In fdinfo
Console.WriteLine(ob.GetType().InvokeMember(o.Name,
BindingFlags.GetField, Nothing, ob, New Object() {}))
Next

Also why you do not declare the structure as string array as Urs's
suggestion.

If you have any concern on this issue,please post here.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Reply to this message...
Vote that this is a GOOD answer...
 
 
    
Bob Day
Thanks!

Bob Day

"Bob Day" <Click here to reveal e-mail address> wrote in message
news:Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
Vote that this is a GOOD answer...
 
Email Archiving and Email Filing - what’s the difference?
Web-based task/todo list management
 
 
System.Console
System.Reflection.BindingFlags
System.Reflection.FieldInfo




Ad
BootFX
Reliable and powerful .NET application framework.
Recession Busting Bespoke Software
Get through the recession by investing in bespoke software to decrease costs and create commercial opportunities.
Other DN247 Network Sites
.NET 247
SQL Server Wins
Old Skool Developer
 
Copyright © AMX Software Ltd 2008-2009. Portions copyright © Matthew Baxter-Reynolds 2001-2009. All rights reserved.
Contact Us - Terms of Use - Privacy Policy - .NET 247 is a member of the DN247 Network - 4.0.30129.1734