|
| 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
|
|
|
| |
|
| |
| | |
| |
| 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
|
|
|
| |
|
|
| |
|
| |
| 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.
|
|
|
| |
|
|
| |
|
| | |
|
|
|
|
|
|
|
BootFX
Reliable and powerful .NET application framework. |
|
|
|
|
|
|