Duplicating asp:Table object with VB (ByVal, not ByRef)

Posted on 2011-09-12
Medium Priority
Last Modified: 2012-06-22
I have an asp:Table object (PlanTable) which is set dynamically. And I have a Table shared variable (_Plan2). What I want is to duplicate one into another. I've tried many things:

1) _Plan2 = PlanTable (seems to work, but doesn't load anything).
2) For a = PlanTable.Rows.Count - 1 To 0 Step -1
Next  (doesn't work. Adds the rows, but removes from the other table)
3)   Protected Sub DuplicateTables(ByVal T1 As Table, ByRef T2 As Table)
    For a = T1.Rows.Count - 1 To 0 Step -1
  End Sub (doesn't work either. I thought by sending one of the tables with ByVal argument, it wouldn't be changed, but it is)

I don't know how I should do this correctly. I've thought about cycling through the cells as well, creating a new TableCell variable and copying the attributes one by one, but not only is that kinda extensive (there are quite a few number of cells I have to copy), some cells actually have controls inside them. Some may have Labels, some Buttons and some Textboxes and MaskedEditValidators. To use a loop for the cells, I would have to check for controls and create copies of them, even without knowing which type they are.

Anyway, anyone have a good suggestion for this? My biggest problem is leaving the source table intact (especially because, later in the code, they switch places). Seeing as I already have the Sub created, we might use the above coded DuplicateTables(ByVal T1 As Table, ByRef T2 As Table).
Question by:Cluskitt

Accepted Solution

Rainverse earned 2000 total points
ID: 36524276
I think for this type of object, you'll have to clone that manually.  

Dim myClonedTable As HtmlTable
Dim myClonedTableRow As HtmlTableRow
Dim newCell As HtmlTableCell

For Each row As HtmlTableRow In myExistingTable
    myClonedTableRow = New HtmlTableRow()

    For Each cell As HtmlTableCell In row
        newCell = New HtmlTableCell
        newCell.ID = cell.ID
        newCell.Width = cell.Width
        ' yadda yadda yadda...
    myClonedTable.Rows.Insert(1, myClonedTableRow)

Open in new window

LVL 11

Expert Comment

ID: 36524533

When you're upgrading a VB6 app to VB.NET manually, a difference in the way the languages pass argument can cause a nasty bug. Here's what to watch for.

There are two ways to pass arguments to a procedure in Visual Basic: ByVal and ByRef. This refers to whether a copy of the argument is passed to the procedure (ByVal - the value is passed) or whether the actual argument itself is passed (ByRef - a reference to the argument is passed). The default for VB6 is ByRef.

There are also two types of procedures in Visual Basic:


The difference is that a Function returns the a value assigned to the function name and a Sub doesn't. So if you want to return a value to the calling routine, there are two ways to do it. In VB6, the code that returns a value could look like this for a Sub:
Code to return a value from a Sub procedure in VB6

Public Sub CallingSub()
   CallingArg = "ABCDEF"
   CalledSub CallingArg
   MsgBox (CallingArg)
End Sub

Public Sub CalledSub(CalledArg)
   CalledArg = "987654"
End Sub

Code to return a value from a Function procedure in VB6:

Public Sub CallingSub()
   CallingArg = "ABCDEF"
   CalledFunc CallingArg
   MsgBox (CallingArg)
End Sub

Public Function CalledFunc(CalledArg)
   CalledArg = "987654"
   CalledFunc = "Any Return Value"
End Function
The result of both the Sub and the Function code above is a window that displays the value "987654" returned as a result of changing the value of the argument.

Note that in this coce, the main difference is that the function has just one more statement to assign a return value to the function name. In VB6, the difference was sometimes considered meaningless and programmers often used subroutines rather than functions out of habit or just to save a statement.

A few other "shortcuts" in VB6 should be pointed out.

No variables are declared.
All variables in VB6 are of type "Variant" - similar to "Object" in VB.NET.
No scoping or typing is done in the argument list.
Everything uses the default settings.
The procedure call doesn't use any parentheses or a Call keyword.

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses
Course of the Month16 days, 5 hours left to enroll

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question