Errors in Upgrade

I am new to and trying to upgrade a program previously written in VB6. The problem is that in the VB6 version I was passing the form as an object which is obviously not compatible with My question is, what would be the best way of correcting this error?

An example of the code used in VB6 is as follows:

frm.txtPDate.Text = DataRcdSet.Fields("PDATE").Value

With the object "frm" being whatever form is active, containing the textbox "txtPDate".

Thanks for the Help,

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Éric MoreauSenior .Net ConsultantCommented:
I would say that a good design won't let classes affect controls directly. Functions should return values that are set to controls from within the form itself so there is no need to pass a reference to a form or a control. What if you want to use your method with a WebForm?

But as a workaround, why don't you pass your TextBox instead?
for starters, trying to upgrade a VB6 application to .NET is ALMOST ALWAYS an invitation to disaster.  The upgrade wizard work 'sort of', in cases where the VB 6 app is very simple - generally of the order of Hello World.

My experience has been that the basic concepts of VB 6 and .NET are different enough to ensure that the upgrade will typically lead to far more work than would be the case if you re-engineered the app using 'proper' .NET techniques.

I am a professional developer, have used VB 6 since 1994, and .NET since 2001 (started with the first BETA release).  I  have found the the two tools are different enough in basic architecture, that the only real simialrities are in the name, and the most basic syntax.  But any attempts to apply the design concepts from VB 6 to the development of a VB.NET app is usually not going to be successful.

At the present, I am doing development in both environments (VB 6/VBA and .NET) and the above commentary comes from personal experience.

Bob LearnedCommented:
I would agree with Arthur's assessment.  

The problem that you are having is the paradigm shift in the form class.  Forms are not globally referenced in a project in VB.NET, so you need an instance of that form:

Dim f As frm = New frm
f.txtPDate.Text = DataRcdSet.Fields("PDATE").Value

Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

bbarnetteAuthor Commented:
That worked, by passing an object of the Class with a few other minor changes, but I have another question concerning ADO. The code I previously used in the VB6 project seems to work here but is extremely slow (10-12 seconds) in retrieving a customer list that is approximately 1700 items. Do you see any problems with the code listed below, or have any idea why the dramatic difference in speed?

  Sub GetCustList(ByRef frm As Object)
        'Retrieves all customer numbers from ARCUST database, and adds customer numbers
        'to listbox for selection by user
        Dim strSQL As String
        Dim sAddedItem As String
        Dim sCustNo As String

        'SQL to get only a list of customers
        strSQL = "Select CUSTNO from ARCUST" & sLocation & " Order by CUSTNO"

        'use "ForwardOnly" to open it as fast as possible
        CustRcdSet.Open(strSQL, cn, ADODB.CursorTypeEnum.adOpenForwardOnly, ADODB.LockTypeEnum.adLockOptimistic)

        '        CustRcdSet.MoveFirst()
        While Not CustRcdSet.EOF
            sCustNo = CustRcdSet.Fields("CUSTNO").Value
            'do not dupicate the customer number in the listbox
            If sAddedItem <> sCustNo Then
                sAddedItem = CustRcdSet.Fields("CUSTNO").Value
            End If


        End While

    End Sub

Thanks again for the Help,

Bob LearnedCommented:
A couple of points:

(1) Don't use ADO classic, use ADO.NET.  A ListBox bound to a DataSet should be faster than 10-12 seconds.

(2) If you must, then use a read-only, instead of LockOptimistic.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Éric MoreauSenior .Net ConsultantCommented:
You should also use a DISTINCT clause :

     strSQL = "Select DISTINCT CUSTNO from ARCUST" & sLocation & " Order by CUSTNO"
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.