Monday, January 21, 2013

looping logic in VB

Public Shared Function IsRouteParametersSane(ByVal dataSet As DataSet, url As
            String) As Boolean
   If InStr(url, "?") = 0 Then
      Return True
   End If
   Dim secondHalfOfUrl As String
   secondHalfOfUrl = Split(url, "?")(1)
   Dim routeParametersAndTheirVariables As New ArrayList()
   If InStr(secondHalfOfUrl, "&") = 0 Then
      routeParametersAndTheirVariables.Add(secondHalfOfUrl)
   Else
      Dim routeParametersAndTheirVariablesAsArray = Split(secondHalfOfUrl, "&")
      routeParametersAndTheirVariables = New
                  ArrayList(routeParametersAndTheirVariablesAsArray)
   End If
   Dim routeParameters As New ArrayList()
   Dim routeParameterAndValue As String
   For Each routeParameterAndValue In routeParametersAndTheirVariables
      If InStr(routeParameterAndValue, "=") = 0 Then
         routeParameters.Add(routeParameterAndValue)
      Else
         routeParameters.Add(Split(routeParameterAndValue, "=")(0))
      End If
   Next
   Dim routeParameter As String
   For Each routeParameter In routeParameters
      Dim isFailure As Boolean = True
      For Each Row As DataRow In dataSet.Tables(0).Rows
         If Row(2) = "Route Parameter" Then
            If Row(1).ToLower() = routeParameter.ToLower() Then
               isFailure = False
            End If
         End If
      Next
      If isFailure = True Then
         Return False
      End If
   Next
   Return True
End Function

No comments:

Post a Comment