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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

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

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

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

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

762 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