Hi Guys,

I am very close to finishing this function lol, what i am trying to do is a for loop which:

1) Grabs the value
2) saves the value in an .xml file for later use

Currently when i use a for loop to feed in my function i over write the hiddenFields.xml on every pass, instead of adding to it.

Calling function:

vb.net Code:
  1. For X As Integer = 0 To postingHiddenFields
  2.                 Dim hiddenFieldsReturned As String = functionDealWithHiddenFields(HTMLResponse, postingHiddenFields, X)
  3.             Next

Function:

vb.net Code:
  1. Function functionDealWithHiddenFields(ByVal HTML As String, ByVal numHiddenFields As Integer, ByVal X As Integer)
  2.  
  3.         Try
  4.  
  5.             'For i As Integer = 0 To numHiddenFields
  6.             '// The html source
  7.             Dim sText = HTML
  8.  
  9.             '// The string we are searching for
  10.             Dim sPattern As String = "(?<=<input type=""hidden"" class="").*?(?="".*?')"
  11.  
  12.             '// This is the regular expression
  13.             Dim regex As New Regex(sPattern, RegexOptions.IgnoreCase Or RegexOptions.Singleline)
  14.  
  15.             '// The matches that we return are put in the matchcollection
  16.             Dim regexMatches As MatchCollection = regex.Matches(sText)
  17.  
  18.             '// Return
  19.             'Return regexMatches(0).ToString
  20.             MessageBox.Show(regexMatches(X).ToString)
  21.  
  22.  
  23.             '// File location
  24.             Dim fileLocation As String = "Debug/hiddenFields.xml"
  25.  
  26.             '// The XmlTextWriter that will build the XML file
  27.             Dim myXmlWriter As New Xml.XmlTextWriter(fileLocation, System.Text.Encoding.UTF8)
  28.  
  29.             '// Add a few extra options to the XML
  30.             With myXmlWriter
  31.  
  32.                 .Formatting = Formatting.Indented
  33.                 .Indentation = 3
  34.  
  35.                 'Write an element (this one is the root)
  36.                 myXmlWriter.WriteStartDocument()
  37.                 myXmlWriter.WriteStartElement("hiddenFields")
  38.  
  39.                 'Write the title element.
  40.                 myXmlWriter.WriteStartElement("fieldNumber" & X)
  41.                 myXmlWriter.WriteString(regexMatches(X).ToString)
  42.                 myXmlWriter.WriteEndElement()
  43.  
  44.                 '// Close up
  45.                 myXmlWriter.Close()
  46.  
  47.             End With
  48.  
  49.         Catch ex As Exception
  50.  
  51.             'Return False
  52.  
  53.             Return False
  54.  
  55.         End Try
  56.  
  57.     End Function

So basically on every pass of the function i'm overwriting the values instead of adding to them, i'm not sure of the proper way to do this, any help would be appreciated.

thanks a lot guys

Graham