Errors in Upgrade

Posted on 2004-11-29
Last Modified: 2010-04-23
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,

Question by:bbarnette
    LVL 69

    Expert Comment

    by:Éric Moreau
    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?
    LVL 44

    Expert Comment

    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.

    LVL 96

    Expert Comment

    by:Bob Learned
    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


    Author Comment

    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,

    LVL 96

    Accepted Solution

    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.

    LVL 69

    Expert Comment

    by:Éric Moreau
    You should also use a DISTINCT clause :

         strSQL = "Select DISTINCT CUSTNO from ARCUST" & sLocation & " Order by CUSTNO"

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    Join & Write a Comment

    If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
    Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    734 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

    Need Help in Real-Time?

    Connect with top rated Experts

    24 Experts available now in Live!

    Get 1:1 Help Now