Solved

Help with VB6 code to VB.NET

Posted on 2011-03-11
5
289 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
5 Comments
 
LVL 23

Accepted Solution

by:
wdosanjos earned 333 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 167 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 333 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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

777 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