Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Help with VB6 code to VB.NET

Posted on 2011-03-11
5
Medium Priority
?
296 Views
Last Modified: 2012-05-11
In VB6 I could use a collection that had properties to create a collection of the same type of thing.  Now, I'm trying to use List(of T).  There must be an easier way in VB.NET.  Any suggestions?

Here's the VB6 code, where col is the collection:
Dim col as ReportLines
Me.Row = Me.Row + 1
col.Add Me.Row, mCol1, mTotal1
col.Add Me.Row, mCol2, mTotal2

In VB.Net:
Dim ListR as New List(Of ReportLine)
Dim obj as New ReportLine
Me.Row += 1
obj.Add(Me.Row, mCol1, mTotal1)
ListR.Add(obj)
obj = New ReportLine
obj.Add(Me.Row, mCol2, mTotal2)
ListR.Add(obj)
0
Comment
Question by:Agent909
[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
5 Comments
 
LVL 23

Accepted Solution

by:
wdosanjos earned 1332 total points
ID: 35111315
If you add a constructor to ReportLine that takes the three variables, you can rewrite the VB.NET code as follows:

Dim ListR as New List(Of ReportLine)
Dim obj as New ReportLine
Me.Row += 1
ListR.Add(New ReportLine(Me.Row, mCol1, mTotal1))
ListR.Add(New ReportLine(Me.Row, mCol2, mTotal2))
0
 
LVL 29

Assisted Solution

by:Paul Jackson
Paul Jackson earned 668 total points
ID: 35111332
Dim ListR as New List(Of ReportLine)
Me.Row+= 1
ListR.Add(new ReportLine(Me.Row, mCol1,mTotal1))
ListR.Add(new ReportLine(Me.Row, mCol2,mTotal2))
0
 
LVL 23

Assisted Solution

by:wdosanjos
wdosanjos earned 1332 total points
ID: 35111346
The ReportLine constructor could be something like:

Public Class ReportLine
    Public Sub New()
    End Sub

    Public Sub New(row As Integer, col As Integer, total As Integer)
        Me.Add(row, col, total)
    End Sub

    ...
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 35111409
Let me start by saying I agree with wdosanjos' suggestion. However...

If you *really* wanted to mimic the exact behavior of your VB6 code, you could add an extension method that would let you mimic what you are doing in VB6. Create a new method that looks like this (change parameter types accordingly):

Imports System.Runtime.CompilerServices

...

<Extension()> _
Public Sub Add(ByRef source As List(Of ReportLine), ByVal row As Integer, ByVal col As Integer, ByVal total As Integer)
    source.Add(New ReportLine(row, col, total))
End Sub

Open in new window



Then you can mimic what you did in VB6:

ListR.Add(Me.Row, mCol1, mTotal1)

Open in new window

0
 
LVL 1

Author Closing Comment

by:Agent909
ID: 35111416
Thanks to all of you for the great answers!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

721 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