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:
For X As Integer = 0 To postingHiddenFields Dim hiddenFieldsReturned As String = functionDealWithHiddenFields(HTMLResponse, postingHiddenFields, X) Next
Function:
vb.net Code:
Function functionDealWithHiddenFields(ByVal HTML As String, ByVal numHiddenFields As Integer, ByVal X As Integer) Try 'For i As Integer = 0 To numHiddenFields '// The html source Dim sText = HTML '// The string we are searching for Dim sPattern As String = "(?<=<input type=""hidden"" class="").*?(?="".*?')" '// This is the regular expression Dim regex As New Regex(sPattern, RegexOptions.IgnoreCase Or RegexOptions.Singleline) '// The matches that we return are put in the matchcollection Dim regexMatches As MatchCollection = regex.Matches(sText) '// Return 'Return regexMatches(0).ToString MessageBox.Show(regexMatches(X).ToString) '// File location Dim fileLocation As String = "Debug/hiddenFields.xml" '// The XmlTextWriter that will build the XML file Dim myXmlWriter As New Xml.XmlTextWriter(fileLocation, System.Text.Encoding.UTF8) '// Add a few extra options to the XML With myXmlWriter .Formatting = Formatting.Indented .Indentation = 3 'Write an element (this one is the root) myXmlWriter.WriteStartDocument() myXmlWriter.WriteStartElement("hiddenFields") 'Write the title element. myXmlWriter.WriteStartElement("fieldNumber" & X) myXmlWriter.WriteString(regexMatches(X).ToString) myXmlWriter.WriteEndElement() '// Close up myXmlWriter.Close() End With Catch ex As Exception 'Return False Return False End Try 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




Reply With Quote