Solved

Help with VB6 code to VB.NET

Posted on 2011-03-11
5
294 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 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

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

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…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…
Suggested Courses
Course of the Month6 days, 11 hours left to enroll

623 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