Printing a View with Table Headers and Not splitting Row info - InfoPath Dev

InfoPath Dev

Use our Google Custom Search for best site search results.

Printing a View with Table Headers and Not splitting Row info

Last post 08-28-2008 02:35 PM by Hilary Stoupa. 1 replies.
Page 1 of 1 (2 items)
Sort Posts: Previous Next
  • 08-28-2008 01:21 PM

    • Patrick
    • Top 500 Contributor
    • Joined on 11-03-2007
    • Texas
    • Posts 51

    Printing a View with Table Headers and Not splitting Row info

    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.

    Dim oTables As var = XDocument.DOM.selectNodes("/my:myFields/my:Document/my:Page/my:Table")
    Dim oSampleTable As var = oTables.nextNode()

    Dim oPages As var = XDocument.DOM.selectNodes("/my:myFields/my:Document/my:Page")
    Dim oSamplePage As var = oPages.nextNode()

    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.

    ' Add the first table.

    ' 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.
        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 

  • 08-28-2008 02:35 PM In reply to

    Re: Printing a View with Table Headers and Not splitting Row info

    Hey, Patrick:

    Just to clarify, that code sample in the blog post you are referencing is actually jscript.

    Are you using vbscript? Check your programming language under form options, if you don't mind, and let me know....

    The scripting languages usually don't declare a type for a variable. So in jscript, we see "var thing = 'sometext'" and the compiler says "Oh, the value of thing is text! Thing must be a string!" and busily goes to work. Same with vbscript. In managed code, we tell the compiler what to expect and it scolds us if we are wrong. So, for example, we write "int thing = 'sometext'" and our code won't compile and the compiler says "Thing is an int. I can't put a string in there. Don't be silly."

    However, with jscript, we can do things like "var thing = XDocument.DOM.selectSingleNode('xpathToThing");" and the compiler is generally compliant and fetches us our thing. Vbscript likes to be set. So we would say "Dim thing    Set thing = etc....". Here is a good post with a bit more information on vbscript syntax. Hope this helps, let me know if you get stuck or if you are using managed code instead of script!

    Hilary Stoupa

Page 1 of 1 (2 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.