[RESOLVED] VB code running very slowly....any ideas?
When I start my application it downloads a bunch of data and slots it into listboxes and combo boxes. The main form has five tabs: head of, distributor, site, team, and parent company. Each of those five tabs has two listboxes and the data is pre-loaded into every one of those before the form is even displayed.
The problem I'm having is when the user changes from one tab to another. The code used to run very quickly, but I changed the way I connect to the database (at the request of the DBAs) and now create a new ADO connection when I need to access the DB and destroy it as soon as I'm done.
Switching between tabs does not need an ADO connection since the data is pre-loaded, but ever since I made this change that action has been very slow. Switching from one tab to another now takes 1-2 seconds which I think is too long. I can't figure out why it would take so long just looking at the code that's there. I put in breakpoints earlier and tested it; that is all that's being executed when the user goes from tab to tab. I'm scratching my head here.
This is the code that is executed when the user goes from one tab to another:
VB Code:
Public Sub ClearGlobals()
' Clears app variables
appActiveTab = ""
appPrimInfoValue = ""
appReportSelected = ""
appAddInfoValue = ""
appAddInfoType = ""
End Sub
VB Code:
Public Sub SetActiveTab()
appActiveTab = GetActiveTabName()
End Sub
VB Code:
Public Sub ResetLists()
' Sets selections to false, i.e. if a value is selected on one
' tab, switching from one tab to another causes it to be de-selected
With CriteriaSelection
.lstHeadOf.Text = ""
.lstHeadOfReport.Text = ""
.lstDist.Text = ""
.lstDistReport.Text = ""
.lstSite.Text = ""
.lstSiteReport.Text = ""
.lstTeamReport.Text = ""
.lstParentCompany.Text = ""
.lstPCompReport.Text = ""
.SubFilter.Text = ""
.SubFilterContents.Text = ""
End With
End Sub
Code for GetActiveTabName():
VB Code:
Public Function GetActiveTabName() As String
Select Case GetActiveTabNumber()
Case Is = 0
GetActiveTabName = "HeadOf"
Case Is = 1
GetActiveTabName = "Distributor"
Case Is = 2
GetActiveTabName = "Site"
Case Is = 3
GetActiveTabName = "Team"
Case Is = 4
GetActiveTabName = "Parent"
Case Else
GetActiveTabName = ""
End Select
End Function
Re: VB code running very slowly....any ideas?
How was data transferred to the listboxes/comboboxes? Are you using data bound listboxes/comboboxes?
Re: VB code running very slowly....any ideas?
Quote:
Originally Posted by leinad31
How was data transferred to the listboxes/comboboxes? Are you using data bound listboxes/comboboxes?
They're loaded through code; they're not data bound.
Re: VB code running very slowly....any ideas?
When you run it with breakpoints, does it run normally or is there anything running slow in it? I mean like putting the breakpoint as soon as the tab is clicked, then keep pressing F8 until you get to a point where its a bit slow.
Re: VB code running very slowly....any ideas?
"The problem I'm having is when the user changes from one tab to another. The code used to run very quickly, but I changed the way I connect to the database (at the request of the DBAs) and now create a new ADO connection when I need to access the DB and destroy it as soon as I'm done."
If that was the only change then check if connection or ADO related code is being run during tab switch (relevant events of contained controls included such as _Change() if being "reset", not just tab events)
Re: VB code running very slowly....any ideas?
Quote:
Originally Posted by Andrew G
When you run it with breakpoints, does it run normally or is there anything running slow in it? I mean like putting the breakpoint as soon as the tab is clicked, then keep pressing F8 until you get to a point where its a bit slow.
I didn't do that because I didn't know how. :blush:
Now that I've done it I know exactly what the problem is but not how to fix it.
The problem is that when the user goes from tab to tab the variables that held his selections (what report, what site, etc.) are cleared but they still appear to be selected on the tabs. How do I clear those selections in the listbox without using listbox.text?
Re: VB code running very slowly....any ideas?
Re: VB code running very slowly....any ideas?
Quote:
Originally Posted by leinad31
listbox.listindex = -1
HAHAHAHAHA funny you should say that, I googled around and that's precisely what I was about to try.
Re: VB code running very slowly....any ideas?
Quote:
Originally Posted by leinad31
listbox.listindex = -1
That worked...it exposed a bug in my code but it solved the first problem, thanks!