Multimobile Development: Building Applications for any Smartphone
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...
 
Really good experience at the Apple Store
MonoDroid – looking *awesome*
 
    
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...
 
First volume of Multimobile Development nearly ready to go to press
A mention on Developing for the iPhone and Android: The pros and cons
 
    
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...
 
First chapters of Multimobile Development book now available on Apress Alpha program
iPad
 
 
System.Console
System.Reflection.BindingFlags
System.Reflection.FieldInfo




Ad
BootFX
Reliable and powerful .NET application framework.
iOS, Android and Windows Phone Development Training and Consultancy
Hosted by RackSRV Communications
 
Multimobile Development: Building Applications for any Smartphone
Copyright © AMX Software Ltd 2008-2010. Portions copyright © Matthew Baxter-Reynolds 2001-2010. All rights reserved.
Contact Us - Terms of Use - Privacy Policy - 4.0.30129.1734