Results 1 to 3 of 3

Thread: [RESOLVED] for loop through results

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2009
    Location
    Scotland
    Posts
    417

    Resolved [RESOLVED] for loop through results

    Hi Guys,

    I can't think of a better way to do this, what i have is this function:

    vb.net Code:
    1. Function functionDealWithHiddenFields(ByVal HTML As String, ByVal numHiddenFields As Integer)
    2.  
    3.         Try
    4.  
    5.             '// The html source
    6.             Dim sText = HTML
    7.  
    8.             '// The string we are searching for
    9.             Dim sPattern As String = "(?<=<input type=""hidden"" class="").*?(?="".*?')"
    10.  
    11.             '// This is the regular expression
    12.             Dim regex As New Regex(sPattern, RegexOptions.IgnoreCase Or RegexOptions.Singleline)
    13.  
    14.             '// The matches that we return are put in the matchcollection
    15.             Dim regexMatches As MatchCollection = regex.Matches(sText)
    16.  
    17.             '// Return
    18.             'Return regexMatches(0).ToString
    19.             For x As Integer = 0 To numHiddenFields
    20.                 MessageBox.Show(regexMatches(x).ToString)
    21.             Next
    22.  
    23.         Catch ex As Exception
    24.  
    25.             'Return False
    26.  
    27.             Return False
    28.  
    29.         End Try
    30.  
    31.     End Function

    I feed in afew parameters, one being
    PHP Code:
    numHiddenFields 
    which usually contains: 4 so when i loop out the names, it loops the 4 results, 4 times, instead of just showing me the names 4 times so i can then store them

    i'm probably doing something basic lol

    any help would be great

    thanks guys

    Graham

  2. #2

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2009
    Location
    Scotland
    Posts
    417

    Re: for loop through results

    Sory guys, i'm an idiot, im feeding a for loop into a for loop.

    cheers

    Graham

  3. #3
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: [RESOLVED] for loop through results

    vb.net Code:
    1. For Each reMatch As Match In regexMatches
    2.     MessageBox.Show(reMatch.Value)
    3. Next
    Last edited by Pradeep1210; Aug 26th, 2009 at 04:05 AM.
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width