title: How To Iterate Over Members of a Structure Array in VB.net Using Member Function
body: <p>I have a vb.net enumeration that looks like this:</p>
  
  <pre><code>' define enumeration for keypad states
  Enum KeyPadState
      KEYPAD_NO           ' no keypad
      KEYPAD_UC           ' upper case keypad
      KEYPAD_LC           ' lower case keypad
      KEYPAD_NU           ' numeric keypad
      KEYPAD_SY           ' symbol keypad
  End Enum
  </code></pre>
  
  <p>I then defined a structure element to be used to translate the members of the above enumeration from enumeration values to string values and back again. The declared structure looks like below. Note the member functions that I have tried to insert. The "New" one is working.</p>
  
  <pre><code>' define keypad type look up structure
  Private Structure KeyPadXlat
      Dim KeyPadEnum As KeyPadState
      Dim KeyPadStr As String
  
      ' initializer subroutine
      Public Sub New(nKeyPadEnum As KeyPadState, nKeyPadStr As String)
          KeyPadEnum = nKeyPadEnum
          KeyPadStr = nKeyPadStr
      End Sub
  
      ' translate string to enum
      Public Function ToEnum(xKeyPadStr As String) As KeyPadState
  
          For Each item As KeyPadXlat In ????
  
          Next
      End Function
  
      ' translate enum to string
      Public Function ToStr(xKeyPadEnum As KeyPadState) As String
  
      End Function
  
  End Structure
  </code></pre>
  
  <p>The actual instance of the structure array is shown below with its initializer code.</p>
  
  <pre><code>Dim KeyPadLookUp() As KeyPadXlat = { _
                                      New KeyPadXlat(KeyPadState.KEYPAD_NO, "KEYPAD_NO"), _
                                      New KeyPadXlat(KeyPadState.KEYPAD_UC, "KEYPAD_UC"), _
                                      New KeyPadXlat(KeyPadState.KEYPAD_LC, "KEYPAD_LC"), _
                                      New KeyPadXlat(KeyPadState.KEYPAD_NU, "KEYPAD_NU"), _
                                      New KeyPadXlat(KeyPadState.KEYPAD_SY, "KEYPAD_SY") _
                                      }
  </code></pre>
  
  <p>So my question is with regard to the member functions I am trying to create to translate back and forth between the enumeration value and the string value. I have copied one of them here again for reference:</p>
  
  <pre><code>    ' translate string to enum
      Public Function ToEnum(xKeyPadStr As String) As KeyPadState
  
          For Each item As KeyPadXlat In ????
  
          Next
      End Function
  </code></pre>
  
  <p>What I need help with is how to write the code for the For Each loop so that it iterates across all of the elements of the structure array when being in a member function.</p>