Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB 2005 > Pro Visual Basic 2005
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Pro Visual Basic 2005 For advanced Visual Basic coders working in version 2005. Beginning-level questions will be redirected to other forums, including Beginning VB 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro Visual Basic 2005 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old October 25th, 2007, 10:02 AM
Registered User
 
Join Date: Oct 2007
Location: Pearl River, NY, USA.
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default VB.net slow compared to vb6

I have created a program that updates some fields in a database when certain fields are exited. I have created the same program in vb6 and vb.net. When the vb.net program is called, it takes about 6 seconds before the cursor is available in the next field. When I call the vb6 program, which does the exact same thing, it takes about 1 sec.
The vb.net is compiled in release mode.
Is there anything I can do to speed up vb.net?
Reply With Quote
  #2 (permalink)  
Old October 25th, 2007, 03:00 PM
Friend of Wrox
 
Join Date: Nov 2004
Location: Port Orchard, WA, USA.
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

I suggest you add a logging function to your .NET program that writes messages to an external file, and have various parts of the process report what they are up to, and what time it is. That should help you find the location(s) where so much time is being spent.
Reply With Quote
  #3 (permalink)  
Old October 25th, 2007, 03:09 PM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Alternatively, you could use Trace.WriteLine() (or if you want to flip back into Debug mode, Debug.WriteLine() ) so you don't have to play around with the FileSystem and an external file.

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
.: Wrox Technical Editor :.
Wrox Books 24 x 7
================================================== =========
Reply With Quote
  #4 (permalink)  
Old October 25th, 2007, 03:18 PM
Imar's Avatar
Wrox Author
Points: 67,271, Level: 100
Points: 67,271, Level: 100 Points: 67,271, Level: 100 Points: 67,271, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 16,227
Thanks: 66
Thanked 1,414 Times in 1,394 Posts
Default

Additionally, you may want to post some code here. There are often a million ways to do the same thing in .NET, so maybe you haven't chosen the most optimized way to do things....

Imar


---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Reply With Quote
  #5 (permalink)  
Old October 25th, 2007, 03:43 PM
Registered User
 
Join Date: Oct 2007
Location: Pearl River, NY, USA.
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Okay,
Here is the code. I'm am being very vulnerable here showing my coding skills or lack thereof.

It is updating the current record in an Act6.0 database.
This is the vb.net version. The vb6 version is the same with syntax changes.

Sub Main()
        Dim objApp As Object
        Dim objViews As Object
        Dim objContact As Object

        Dim cAcceptanceDate As Integer = My.Settings.cAcceptanceDate
        Dim cCategory As Integer = My.Settings.cCategory
        Dim cDepartureDate As Integer = My.Settings.cDepartureDate
        Dim cFAPReceived As Integer = My.Settings.cFAPReceived
        Dim cFAPSent As Integer = My.Settings.cFAPSent
        Dim cInactiveDate As Integer = My.Settings.cInactiveDate
        Dim cInquiryDate As Integer = My.Settings.cInquiryDate
        Dim cHoldDate As Integer = My.Settings.cHoldDate
        Dim cPQReceived As Integer = My.Settings.cPQReceived
        Dim cPQSent As Integer = My.Settings.cPQSent
        Dim cPRStatus As Integer = My.Settings.cPRStatus
        Dim cPRStatusNumber As Integer = My.Settings.cPRStatusNumber
        Dim cPRCategory As Integer = CInt(My.Settings.cPRCategory)
        Dim cMemberType As Integer = CInt(My.Settings.cMemberType)
        'Short term dims
        Dim cSTAcceptanceDate As Integer = CInt(My.Settings.cSTAcceptanceDate)
        Dim cSTAppReceived As Integer = CInt(My.Settings.cSTAppReceived)
        Dim cSTFinishDate As Integer = CInt(My.Settings.cSTFinishDate)
        Dim cSTInactiveDate As Integer = CInt(My.Settings.cSTInactiveDate)
        Dim cSTInquiryDate As Integer = CInt(My.Settings.cSTInquiryDate)
        Dim cSTStartDate As Integer = CInt(My.Settings.cSTStartDate)
        Dim cSTCategory As Integer = CInt(My.Settings.cSTCategory)
        Dim strCategory As String = String.Empty
        Dim strPRCategory As String = String.Empty
        Dim strPRStatus As String = String.Empty
        Dim strSTCategory As String = String.Empty
        Dim intPRStatusNumber As Integer
        Dim strMemberType As String = String.Empty

        'Create a Views object.
        objApp = CreateObject("ACTOLE.APPOBJECT")
        objViews = objApp.Views
        objContact = objViews.Create(1, "CV") 'Contact View

        'Determine if FT or ST
        strPRStatus = (CStr(objContact.getfield(cPRStatus)))
        strCategory = CStr(objContact.getfield(cCategory))
        strSTCategory = CStr(objContact.getfield(cSTCategory))
GetMemberType:
        strMemberType = CStr(objContact.getfield(cMemberType))

        'Get a member type if it is blank
        'MessageBox.Show(strMemberType)


        If (InStr("STFT-FT+", Left(strMemberType, 2), CompareMethod.Text).Equals(0)) Or strMemberType.Equals(String.Empty) Then

            Dim strCheck As String = InputBox("If this person is a Short Termer " & _
                "or a Fulltermer, please enter their Status (ST, FT+ or FT-) or enter 'n' for neither").ToUpper
            If strCheck.Equals("N") Then
                intPRStatusNumber = 0
                'strCategory = String.Empty
                strPRStatus = String.Empty
                strPRCategory = String.Empty
                GoTo UpDateFields
                'Exit Sub
            Else
                If strCheck.ToUpper.Equals("ST") Then
                    strMemberType = "ST"
                Else
                    If (InStr(1, "FT-FT+", strCheck.ToUpper, CompareMethod.Text).Equals(0)) Then
                        strMemberType = InputBox("What kind of member is this contact? 'FT+' or 'FT-'").ToUpper
                    End If
                    strMemberType = strCheck.ToUpper
                End If
            End If
            objContact.setfield(cMemberType, strMemberType)
            'Update the current record
            objContact.update()
            GoTo GetMemberType
        End If

        Select Case Left(strMemberType, 2)
            Case "FT"

                Try
                    If Not objContact.getfield(cDepartureDate).Equals("") Then
                        intPRStatusNumber = 7 'departure date
                    Else
                        If Not objContact.getfield(cAcceptanceDate).Equals("") Then
                            intPRStatusNumber = 6 'Acceptance date
                        Else
                            If Not objContact.getfield(cFAPReceived).Equals("") Then
                                intPRStatusNumber = 5 'FAP Received
                            Else
                                If Not objContact.getfield(cFAPSent).Equals("") Then
                                    intPRStatusNumber = 4 'FAP Sent
                                Else
                                    If Not objContact.getfield(cPQReceived).Equals("") Then
                                        intPRStatusNumber = 3 'PQ Received
                                    Else
                                        If Not objContact.getfield(cPQSent).Equals("") Then
                                            intPRStatusNumber = 2 'PQ Sent
                                        Else
                                            If Not objContact.getfield(cInquiryDate).Equals("") Then
                                                intPRStatusNumber = 1 'Inq date
                                            End If
                                        End If
                                    End If
                                End If
                            End If
                        End If
                    End If
                    Select Case intPRStatusNumber
                        Case 1
                            strPRStatus = "Inquirer"
                            strCategory = "Inquirer"
                            'strPRCategory = "Inquirer" & " - " & strPRStatus
                        Case 2
                            strPRStatus = "PQ Sent"
                            strCategory = "Inquirer"
                            'strPRCategory = "Inquirer" & " - " & strPRStatus
                        Case 3
                            strPRStatus = "PQ Recvd"
                            strCategory = "Candidate"
                            'strPRCategory = "Candidate" & " - " & strPRStatus
                        Case 4
                            strPRStatus = "FAP Sent"
                            strCategory = "Candidate"
                            'strPRCategory = "Candidate" & " - " & strPRStatus
                        Case 5
                            strPRStatus = "FAP Recvd"
                            strCategory = "Candidate"
                            'strPRCategory = "Candidate" & " - " & strPRStatus
                        Case 6
                            strPRStatus = "Accepted"
                            strCategory = "Appointee"
                            'strPRCategory = "Appointee" & " - " & strPRStatus
                        Case 7
                            strPRStatus = "To Field"
                            strCategory = "Missionary"
                        Case Else
                            strPRStatus = String.Empty
                            strCategory = String.Empty

                            MsgBox("Select a Category from the drop down list that " & _
                                    "applies to this contact and please make sure at least the inquiry date is filled in.")
                    End Select
                    If Not objContact.getfield(cHoldDate).Equals("") Then
                        'MessageBox.Show("On Hold")
                        strPRStatus = "On Hold"
                        'strPRCategory = strCategory & " - " & strPRStatus
                    End If
                    If Not objContact.getfield(cInactiveDate).Equals("") Then
                        'MessageBox.Show("Inactive")
                        strPRStatus = "Inactive"

                        'strPRCategory = strCategory & " - " & strPRStatus
                    End If
                    strPRCategory = strCategory & " - " & strPRStatus
                    If Not objContact.getfield(cSTInquiryDate).Equals("") _
                        And objContact.getfield(cSTInactiveDate).Equals("") Then
                        MsgBox("On the Short Term tab, either enter the Inactive Date for this person " & vbCrLf & _
                         "or remove the Inquiry Date if it was entered by mistake " & vbCrLf & "or change the Member Type to ST.")
                    End If
                    GoTo updatefields

                Catch ExceptionErr As Exception
                    MessageBox.Show(ExceptionErr.Message, "Update " & strCategory & " Status")
                End Try


                'If the field changed is for a short termer...
            Case "ST"
                Try
                    If Not objContact.getfield(cSTInactiveDate).Equals("") Then
                        intPRStatusNumber = 106 ' Inactive
                    Else
                        If Not objContact.getfield(cSTFinishDate).Equals("") Then
                            intPRStatusNumber = 105 'Returned
                        Else
                            If Not objContact.getfield(cSTStartDate).Equals("") Then
                                intPRStatusNumber = 104 'On Field
                            Else
                                If Not objContact.getfield(cSTAcceptanceDate).Equals("") Then
                                    intPRStatusNumber = 103 'Accepted
                                Else
                                    If Not objContact.getfield(cSTAppReceived).Equals("") Then
                                        intPRStatusNumber = 102 'Application Received
                                    Else
                                        If Not objContact.getfield(cSTInquiryDate).Equals("") Then
                                            intPRStatusNumber = 101 'Inquiry

                                        End If
                                    End If
                                End If
                            End If
                        End If
                    End If
                    strCategory = "Short Term"
                    Select Case intPRStatusNumber
                        Case 101
                            strPRStatus = "Inquirer"
                            strSTCategory = "A:Inquiry"
                        Case 102
                            strPRStatus = "App Received"
                            strSTCategory = "D:Applying"
                        Case 103
                            strPRStatus = "Accepted"
                            strSTCategory = "B:Accepted"
                        Case 104
                            strPRStatus = "On Field"
                            strSTCategory = "A:On Field"
                        Case 105
                            strPRStatus = "Returned"
                            strSTCategory = "E:Returned"
                        Case 106
                            strPRStatus = "Inactive"
                            strSTCategory = "Inactive"
                        Case Else
                            strPRStatus = String.Empty
                            strSTCategory = String.Empty
                            MsgBox("Select a Category from the drop down list that applies to this contact.")
                    End Select
                    strPRCategory = strCategory & " - " & strPRStatus
                    If Not CStr(objContact.getfield(cInquiryDate)).Trim.Equal s(String.Empty) _
                        And CStr(objContact.getfield(cInactiveDate)).Trim.Equa ls("") Then
                        MsgBox("On the Dates tab, either enter the Inactive Date for this person " & vbCrLf & _
                         "or remove the Inquiry Date if it was entered by mistake " & vbCrLf & "or change the Member Type to FT.")
                    End If
                Catch ExceptionErr As Exception
                    MessageBox.Show(ExceptionErr.Message, "Update Short Term Status")

                End Try
        End Select

UpDateFields:
        Try
            'Update the fields
            objContact.setfield(cPRCategory, strPRCategory)
            objContact.setfield(cPRStatus, strMemberType)
            objContact.setfield(cPRStatusNumber, intPRStatusNumber)
            objContact.setfield(cCategory, strCategory)
            objContact.setfield(cSTCategory, strSTCategory)

            'Update the current record
            objContact.update()
        Catch ExceptionErr As Exception
            MessageBox.Show(ExceptionErr.Message, "Update Status Failed")
        End Try



    End Sub

Thanks for your suggestions.
Reply With Quote
  #6 (permalink)  
Old October 25th, 2007, 03:48 PM
Imar's Avatar
Wrox Author
Points: 67,271, Level: 100
Points: 67,271, Level: 100 Points: 67,271, Level: 100 Points: 67,271, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 16,227
Thanks: 66
Thanked 1,414 Times in 1,394 Posts
Default

Right, from what I can see, there isn't much in your logic that explains the slow performance.

However, you are using late binding (where you defer determining an object's type until run-time) which is bad for performance and maintainability of your application. I see you are using an external component for database updates. You create it using CreateObject which is slow in the .NET world.

Maybe there's an updated version of this piece of software available? Does it do so much you really need it? Or could you use plain (and fast) ADO.NET objects instead?

Imar
Reply With Quote
  #7 (permalink)  
Old October 25th, 2007, 04:15 PM
Registered User
 
Join Date: Oct 2007
Location: Pearl River, NY, USA.
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Imar,
Thanks for your input. I always wondered what late binding was. Working with the Act6.0 I need to use what I have done. The thing is, the vb6 version does the same thing, has the same late binding and still works 6 times faster.
We are planning an update but not until April next year. I was just wondering if I was missing something going from vb6 to vb.net in the compiling process.
So, it looks like vb.net is just different in the way it compiles and processes the instructions. I was wondering if it had to do with permissions. The .net framework checks permissions on the machine to see if it is trusted. At least my first .net program took a few hours to get it to run on the computer I first installed it on. vbscript was so easy but I really enjoy vb.net development.
John
Reply With Quote
  #8 (permalink)  
Old October 28th, 2007, 06:26 AM
Imar's Avatar
Wrox Author
Points: 67,271, Level: 100
Points: 67,271, Level: 100 Points: 67,271, Level: 100 Points: 67,271, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 16,227
Thanks: 66
Thanked 1,414 Times in 1,394 Posts
Default

(Sorry for the late reply; I overlooked your post).

Performance is influenced by a lot of factors. Late binding is one of them, but there could be more.

You could try to create a .NET wrapper around your COM DLL. To do this, right-click your project, choose Add Reference and then browse for the Act DLL. Once you have the reference in place, you can create strongly typed objects like this:

Dim objApp = New ACTOLE.APPOBJECT

Whether this works, and how the syntax looks exactly depends on the component. I am not familiar with ACTOLE.APPOBJECT so I can't recommend much, but this is what I would try.

Additionally, you could add some Debug.Write calls in your code here and there that output the current date and time in milliseconds. This gives you some rough ideas of where the performance bottleneck is.

Hope this helps a little.

Imar

---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Reply With Quote
  #9 (permalink)  
Old January 16th, 2008, 11:54 PM
Registered User
 
Join Date: Jan 2008
Location: , , Australia.
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hey, I'm not adding anything here of true value to your dilema but just a word of encouragement. I too started out with vb6 and going to .NET is really hard at first but hang in there. Once you get used to it .NET is far better and easier to use. It is also faster once you've optimised for how .Net works.

One tip that will also help should you wish to migrate to c#. You are using VB specific syntax. Eg, InStr. The .Net equivelent is variable.IndexOf(searchstring). Won't help with speed in this case but will help the way you code.

Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Consume VB6.0 WebService in ASP.NET using VB.NET pinkarc .NET Web Services 1 March 5th, 2007 07:19 AM
VB6 PrintForm method too slow bwhit VB How-To 0 May 2nd, 2006 02:51 PM
Should I go VB.NET or VB 2005 from VB6? HB Visual Studio 2005 1 December 9th, 2005 02:13 AM
VBA Word is very slow with vb.net preeti01 VB How-To 4 May 5th, 2005 05:01 AM
VB6 and VB.Net ioates VB.NET 2002/2003 Basics 1 December 9th, 2003 04:25 AM



All times are GMT -4. The time now is 01:53 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.