Hi all,
I've been poking around and came across Matt Faus' Blog about this subject here
I see that it is written in C#, but I have my project created with VB. I already have code written, so switching isn't really an option, plus I am more familiar with VB (but by no means am I considered fluent).
Could anyone help me out with a VB translation maybe?
I used an online tool to get the code converted (but I'm not sure if it's taking me down the right path. I know that I have to replace the "var" declaration types with actual types, like Integer. Here's what it gives me:
' Number of lines we want on a page.
Dim MAX_ROWS_ON_PAGE As var = 10
' Number of lines we have placed on current page.
Dim iCurrentPageRowCount As var = 0
' Index of the current page we are adding to.
Dim iCurrentPageIndex As var = 1
' Set up access to secondary data source.
Dim domVehicles As var = XDocument.GetDOM("Vehicles")
' Source nodes.
Dim oVehicles As var = domVehicles.selectNodes("/Vehicles/Vehicle")
' Now we will get a node list for each of our groups and clear them
' of all children. We will be generating the list from scratch each
' time we switch to the Print View so that we can deal with changes
' that have occurred since the last generation of the list.
' ALL ROWS
' Get the node list.
Dim oRows As var = XDocument.DOM.selectNodes("/my:myFields/my:Document/my:Page/my:Table/my:Row")
' Save a sample node from this list for later - we will have to clone
' it to add our rows back in.
Dim oSampleRow As var = oRows.nextNode()
' Remove all the rows from all the repeating tables.
oRows.removeAll()
' ALL TABLES
Dim oTables As var = XDocument.DOM.selectNodes("/my:myFields/my:Document/my:Page/my:Table")
Dim oSampleTable As var = oTables.nextNode()
oTables.removeAll()
' ALL PAGES
Dim oPages As var = XDocument.DOM.selectNodes("/my:myFields/my:Document/my:Page")
Dim oSamplePage As var = oPages.nextNode()
oPages.removeAll()
' THE DOCUMENT
Dim oDocument As var = XDocument.DOM.selectSingleNode("/my:myFields/my:Document")
' We have only 1 document node, but we just emptied it of all
' contents, so we must add back in at least one page and one
' table node because we know we will be adding at least one row
' into this table.
' Add the first page.
oDocument.appendChild(oSamplePage.cloneNode(False))
' Add the first table.
XDocument.DOM.selectSingleNode("/my:myFields/my:Document/my:Page").appendChild(oSampleTable.cloneNode(False))
' Loop through all source nodes and add them
' to the table we are generating.
While oSrc = oVehicles.nextNode()
' We are about to put a new row on the page.
iCurrentPageRowCount += 1
' If the row we about to put on the page will not fit, create a new page.
If iCurrentPageRowCount > MAX_ROWS_ON_PAGE Then
' Reset our row count (we are about to add a row to the next page,
' so that page's row count will be 1).
iCurrentPageRowCount = 1
' We are creating a new page and working with it, so increment the index.
iCurrentPageIndex += 1
' Add the new page.
Dim oNewPage As var = oDocument.appendChild(oSamplePage.cloneNode(False))
' Add a new table to the page that we just created.
oNewPage.appendChild(oSampleTable.cloneNode(False))
End If
' Create a new row by cloning our sample row.
' This node must be cloned using "deep" mode to maintain structure of the
' DOM below it. However, we are about to overwrite all of the nodes anyway.
Dim oNewRow As var = oSampleRow.cloneNode(True)
' Set the values in the new row from the source row
' that we are reading from on this iteration.
oNewRow.selectSingleNode("my:Year").text = oSrc.selectSingleNode("@year").nodeValue
oNewRow.selectSingleNode("my:Make").text = oSrc.selectSingleNode("@make").nodeValue
oNewRow.selectSingleNode("my:Model").text = oSrc.selectSingleNode("@model").nodeValue
oNewRow.selectSingleNode("my:Description").text = oSrc.selectSingleNode("@description").nodeValue
' Add the row to the table that is on the current page.
XDocument.DOM.selectSingleNode("/my:myFields/my:Document/my:Page[" + iCurrentPageIndex + "]/my:Table").appendChild(oNewRow)
End While
' End while looping through all source nodes.
What I'm looking for is some direction on how to declare variables like oVehicles, oRows, and oSampleRow.
NOTE: My data source that the table is tied to is my Main Data Source (XML) within InfoPath