[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

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

Posted on 2011-09-12
2
Medium Priority
?
491 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
[X]
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
2 Comments
 
LVL 5

Accepted Solution

by:
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...
        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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

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…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

650 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