Solved

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

Posted on 2011-09-12
2
475 Views
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
  _Plan2.Rows.Add(PlanTable.Rows(a))
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
      T2.Rows.Add(T1.Rows(a))
    Next
  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).
0
Comment
Question by:Cluskitt
2 Comments
 
LVL 5

Accepted Solution

by:
Rainverse earned 500 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...
        myClonedTableRow.Cells.Add(newCell)
    Next
    myClonedTableRow.Cells.Add(newCell)
    myClonedTable.Rows.Insert(1, myClonedTableRow)
Next

Open in new window


-MJC
0
 
LVL 11

Expert Comment

by:SAMIR BHOGAYTA
ID: 36524533
Hello,

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:

Function
Sub

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

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
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 discusses moving either the default database or any database to a new volume.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

760 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now