HELP! VBA app slowing over time! What is wrong? 
Author Message
 HELP! VBA app slowing over time! What is wrong?

  Hi.  Please excuse this message if it is in the wrong group.  It seemed
like the groups it is in had titles that sounded like they would accept it.
  My name is Josh.  I have made a small VBA program that I added to an Excel
spreadsheet.  On the spreadsheet, there is a button that says "Add an
address".  When the program starts, it loads a text file that is a
comma-seperated list of customer names, addresses, and phone numbers, and
sticks them into an array.  When the user clicks the "Add an address"
button, the program displays a ComboBox that is filled with the customer's
names.  The user can then scroll down the ComboBox and select a customer, at
which time the combo box disappears and the customer's name and address are
inserted onto the Excel spreadsheet.
  This is a simple database application, and it used to work just fine.  The
problem is that over time, it has started to successively slow WAY down.
Should the customer list have changed much, I could see that, but it hasn't!
The list has only grown by 4 or 5 names.  When I say slow, I mean that the
ComboBox's scroll handle doesn't follow your mouse, because it acts as if it
wants to stay right where it was when you opened it.  It will follow, but it
lags about a second behind when you drag it down, and it "jerks", rather
than staying glued to your mouse pointer as you would expect a scroll bar to
do.  The code runs just fine on other computers.
  I have tried updating VB (which does exist on the machine I run the Excel
spradsheet on) to Service Pack 4, I have updated Office 2000 SB to Service
Release 2, I have run RegClean, I have uninstalled/reinstalled Excel, then
the entire Office suite, all to no avail.  What could be wrong?  I'm pulling
my hair out here.
  I've included the code below, as well as some sample lines from the
datbase.  Thanks very very much for any help you can offer me.

-Josh DeWinter
Pullman, WA

---------------------
Object descriptions:
---------------------
There is one command button, "CommandButton1"
and one ComboBox, "ComboBox1"...that's it.

The VBA project consists of 1 module, 1 workbook, and 3 sheets.  (Sheets 2
and 3 are empty).

-----------------------------------------------
The Code in "Module1" (the only module):
-----------------------------------------------
Global custArray(1 To 200, 1 To 7) As String

----------------------------------------------------------------------------
---
The code in the "ThisWorkbook" Excel workbook  (the only workbook):
----------------------------------------------------------------------------
---
Public Sub Workbook_Activate()

Sheet1.CommandButton1.Caption = "Add an Address"
Sheet1.ComboBox1.Visible = False
Sheet1.ComboBox1.Text = "CLICK THE ARROW ON THE RIGHT SIDE OF THIS BOX TO
DISPLAY THE LIST OF AVAILABLE NAMES -->"

Dim Line1 As String
Dim Line2 As String
Dim Line3 As String
Dim Line4 As String
Dim Line5 As String
Dim Line6 As String
Dim counter As Integer
counter = 1

'Inputting the data from the text file into the storage array "custArray":
Open "C:\CustomerData\CustomerData_Billing.txt" For Input As #1
    Do While Not EOF(1)
        Input #1, ID, Line1, Line2, Line3, Line4, Line5, Line6
        custArray(counter, 1) = ID
        custArray(counter, 2) = Line1
        custArray(counter, 3) = Line2
        custArray(counter, 4) = Line3
        custArray(counter, 5) = Line4
        custArray(counter, 6) = Line5
        custArray(counter, 7) = Line6

        counter = counter + 1
    Loop
Close #1

'This command assigns all the data from the first string in each array
element to the ComboBox all at once:
Sheet1.ComboBox1.List = custArray

End Sub

----------------------------------------------------------------------------
--------------------
The code in "Sheet1" (one of three sheets in the workbook, this is the only
one with anything in it):
----------------------------------------------------------------------------
--------------------

Private Sub ComboBox1_Change()
Dim getout_flag As Integer
getout_flag = 0

'We don't want to print the ComboBox on the final printout of this invoice.
Worksheets("sheet1").ComboBox1.PrintObject = False

For i = 1 To 200

        'custArray is two-dimensional.  The 1st dimension specifies the
customer.
        'The 2nd dimension is the individual pieces of a customer's
information.
        'The following If statement checks to see if what's in the ComboBox
now
        'matches one of the ID elements (element 1) in the array (which it
should,
        'since the ComboBox was filled with those ID elemenets from the
array
        'when the Workbook was opened).
        'When it finds the match, it assigns the contents of the other array
elements
        'belonging to that ID to the appropriate cells in the worksheet.
(elements 2-6).

        If ComboBox1.Text = custArray(i, 1) Then
            Worksheets("sheet1").Range("b12").Value = custArray(i, 2)
            Worksheets("sheet1").Range("b13").Value = custArray(i, 3)
            Worksheets("sheet1").Range("b14").Value = custArray(i, 4)
            Worksheets("sheet1").Range("b15").Value = custArray(i, 5)
            Worksheets("sheet1").Range("b16").Value = custArray(i, 6)
            Worksheets("sheet1").Range("b17").Value = custArray(i, 7)
            getout_flag = 1

       End If

Next i

ComboBox1.Visible = False
CommandButton1.Visible = True
End Sub

Private Sub CommandButton1_Click()
Worksheets("sheet1").CommandButton1.PrintObject = False
CommandButton1.Caption = "Change Address"
ComboBox1.Visible = True
CommandButton1.Visible = False

End Sub

--------------------------------------------------------------------------
A sample of the text database file: (comma-seperated, double-quoted list)
You'll notice some of the text fields are empty.  They are just there in
case
an address comes along that takes up many lines (max of 6).  If they are
not used, they still have to be present in the file so that the Input#
command
doesn't get confused.  If they hold nothing, they are just empty double
quotes,
such as: "", "", ""
--------------------------------------------------------------------------

"Al Black", "Alan T. Black", "c/o Black Investments", "341 W. 1st.",
"Spokane, WA  99201", "", ""
"Bill's Plumbing", "Bill's Plumbing", "3117 N. Sharp", "Spokane, WA  43223",
"", "", ""
"RazorWare", "Scott Daniels", "RazorWare, inc.", "44112 E. Sprague",
"Spokane, WA 99207", "", ""
"Teddy B.", "Theodore Baker", "Swift Data Services", "4233 N. Indiana",
"Spokane, WA   22122", "", ""

Thanks again for any help you can offer me.
-Josh



Fri, 27 Jun 2003 08:54:19 GMT  
 HELP! VBA app slowing over time! What is wrong?
Hi Josh:

The only thing I really saw in the code was a lack of a test in Private Sub
ComboBox1_Change() for getout_flag.  When you find the match, bail!, no need
to continue the search.  Obviously you thought about it, just overlooked
implementing.

Other than that I had no code suggestions.

btw, I just mail-merged each company you posted to advise them that you are
posting their names and addresses on the n/g free of charge.  I'm sure they
don't mind the advertising, but if you continue to post information - at
least charge for it! ;o)

hth
tac



Fri, 27 Jun 2003 10:45:10 GMT  
 HELP! VBA app slowing over time! What is wrong?
In VB, it is customary to close out all instances of the use of an object, thus
freeing up the memory that is going to be held by that object.  It sounds
like(at least to me) that your objects are not releasing the memory they are
using.  I can't advise you as to whether or not to close the apps within excel,
as I am not familiar with VBA coding in excel, but I can tell you that you would
have problems very similar to the problems that you are having if you created a
program in VB to do the same thing and then DIDN'T close the excel object that
you had opened.

Make sure that you are releasing all of you appropriate resources after you are
done using them.

Quote:

>   Hi.  Please excuse this message if it is in the wrong group.  It seemed
> like the groups it is in had titles that sounded like they would accept it.
>   My name is Josh.  I have made a small VBA program that I added to an Excel
> spreadsheet.  On the spreadsheet, there is a button that says "Add an
> address".  When the program starts, it loads a text file that is a
> comma-seperated list of customer names, addresses, and phone numbers, and
> sticks them into an array.  When the user clicks the "Add an address"
> button, the program displays a ComboBox that is filled with the customer's
> names.  The user can then scroll down the ComboBox and select a customer, at
> which time the combo box disappears and the customer's name and address are
> inserted onto the Excel spreadsheet.
>   This is a simple database application, and it used to work just fine.  The
> problem is that over time, it has started to successively slow WAY down.
> Should the customer list have changed much, I could see that, but it hasn't!
> The list has only grown by 4 or 5 names.  When I say slow, I mean that the
> ComboBox's scroll handle doesn't follow your mouse, because it acts as if it
> wants to stay right where it was when you opened it.  It will follow, but it
> lags about a second behind when you drag it down, and it "jerks", rather
> than staying glued to your mouse pointer as you would expect a scroll bar to
> do.  The code runs just fine on other computers.
>   I have tried updating VB (which does exist on the machine I run the Excel
> spradsheet on) to Service Pack 4, I have updated Office 2000 SB to Service
> Release 2, I have run RegClean, I have uninstalled/reinstalled Excel, then
> the entire Office suite, all to no avail.  What could be wrong?  I'm pulling
> my hair out here.
>   I've included the code below, as well as some sample lines from the
> datbase.  Thanks very very much for any help you can offer me.

> -Josh DeWinter
> Pullman, WA

> ---------------------
> Object descriptions:
> ---------------------
> There is one command button, "CommandButton1"
> and one ComboBox, "ComboBox1"...that's it.

> The VBA project consists of 1 module, 1 workbook, and 3 sheets.  (Sheets 2
> and 3 are empty).

> -----------------------------------------------
> The Code in "Module1" (the only module):
> -----------------------------------------------
> Global custArray(1 To 200, 1 To 7) As String

> ----------------------------------------------------------------------------
> ---
> The code in the "ThisWorkbook" Excel workbook  (the only workbook):
> ----------------------------------------------------------------------------
> ---
> Public Sub Workbook_Activate()

> Sheet1.CommandButton1.Caption = "Add an Address"
> Sheet1.ComboBox1.Visible = False
> Sheet1.ComboBox1.Text = "CLICK THE ARROW ON THE RIGHT SIDE OF THIS BOX TO
> DISPLAY THE LIST OF AVAILABLE NAMES -->"

> Dim Line1 As String
> Dim Line2 As String
> Dim Line3 As String
> Dim Line4 As String
> Dim Line5 As String
> Dim Line6 As String
> Dim counter As Integer
> counter = 1

> 'Inputting the data from the text file into the storage array "custArray":
> Open "C:\CustomerData\CustomerData_Billing.txt" For Input As #1
>     Do While Not EOF(1)
>         Input #1, ID, Line1, Line2, Line3, Line4, Line5, Line6
>         custArray(counter, 1) = ID
>         custArray(counter, 2) = Line1
>         custArray(counter, 3) = Line2
>         custArray(counter, 4) = Line3
>         custArray(counter, 5) = Line4
>         custArray(counter, 6) = Line5
>         custArray(counter, 7) = Line6

>         counter = counter + 1
>     Loop
> Close #1

> 'This command assigns all the data from the first string in each array
> element to the ComboBox all at once:
> Sheet1.ComboBox1.List = custArray

> End Sub

> ----------------------------------------------------------------------------
> --------------------
> The code in "Sheet1" (one of three sheets in the workbook, this is the only
> one with anything in it):
> ----------------------------------------------------------------------------
> --------------------

> Private Sub ComboBox1_Change()
> Dim getout_flag As Integer
> getout_flag = 0

> 'We don't want to print the ComboBox on the final printout of this invoice.
> Worksheets("sheet1").ComboBox1.PrintObject = False

> For i = 1 To 200

>         'custArray is two-dimensional.  The 1st dimension specifies the
> customer.
>         'The 2nd dimension is the individual pieces of a customer's
> information.
>         'The following If statement checks to see if what's in the ComboBox
> now
>         'matches one of the ID elements (element 1) in the array (which it
> should,
>         'since the ComboBox was filled with those ID elemenets from the
> array
>         'when the Workbook was opened).
>         'When it finds the match, it assigns the contents of the other array
> elements
>         'belonging to that ID to the appropriate cells in the worksheet.
> (elements 2-6).

>         If ComboBox1.Text = custArray(i, 1) Then
>             Worksheets("sheet1").Range("b12").Value = custArray(i, 2)
>             Worksheets("sheet1").Range("b13").Value = custArray(i, 3)
>             Worksheets("sheet1").Range("b14").Value = custArray(i, 4)
>             Worksheets("sheet1").Range("b15").Value = custArray(i, 5)
>             Worksheets("sheet1").Range("b16").Value = custArray(i, 6)
>             Worksheets("sheet1").Range("b17").Value = custArray(i, 7)
>             getout_flag = 1

>        End If

> Next i

> ComboBox1.Visible = False
> CommandButton1.Visible = True
> End Sub

> Private Sub CommandButton1_Click()
> Worksheets("sheet1").CommandButton1.PrintObject = False
> CommandButton1.Caption = "Change Address"
> ComboBox1.Visible = True
> CommandButton1.Visible = False

> End Sub

> --------------------------------------------------------------------------
> A sample of the text database file: (comma-seperated, double-quoted list)
> You'll notice some of the text fields are empty.  They are just there in
> case
> an address comes along that takes up many lines (max of 6).  If they are
> not used, they still have to be present in the file so that the Input#
> command
> doesn't get confused.  If they hold nothing, they are just empty double
> quotes,
> such as: "", "", ""
> --------------------------------------------------------------------------

> "Al Black", "Alan T. Black", "c/o Black Investments", "341 W. 1st.",
> "Spokane, WA  99201", "", ""
> "Bill's Plumbing", "Bill's Plumbing", "3117 N. Sharp", "Spokane, WA  43223",
> "", "", ""
> "RazorWare", "Scott Daniels", "RazorWare, inc.", "44112 E. Sprague",
> "Spokane, WA 99207", "", ""
> "Teddy B.", "Theodore Baker", "Swift Data Services", "4233 N. Indiana",
> "Spokane, WA   22122", "", ""

> Thanks again for any help you can offer me.
> -Josh

--
 ----------------------------------------------------------------------------
|   Jeff Goslin - MCSD   | "Oh Bentson, you are so mercifully free from the  |

 ----------------------------------------------------------------------------
|   how come everyone elses religion is a cult but your cult is a religion   |
 ----------------------------------------------------------------------------
|      XGenetic, the ActiveX Artificial Intelligence Genetic Algorithm       |
|           http://www.winsite.com/info/pc/win95/demo/xgen-sw.zip/           |
 ----------------------------------------------------------------------------


Fri, 27 Jun 2003 15:24:10 GMT  
 HELP! VBA app slowing over time! What is wrong?
As with a memoery problem, this is likely.  Additionally, if the poor
Swap/Page file cant grow and shrink normally, it will get rather annoyed and
WIndows will grind to a halt - until you close excel and the memeory and
space in the swap/page file is released.


Quote:
>   Hi.  Please excuse this message if it is in the wrong group.  It seemed
> like the groups it is in had titles that sounded like they would accept
it.
>   My name is Josh.  I have made a small VBA program that I added to an
Excel
> spreadsheet.  On the spreadsheet, there is a button that says "Add an
> address".  When the program starts, it loads a text file that is a
> comma-seperated list of customer names, addresses, and phone numbers, and
> sticks them into an array.  When the user clicks the "Add an address"
> button, the program displays a ComboBox that is filled with the customer's
> names.  The user can then scroll down the ComboBox and select a customer,
at
> which time the combo box disappears and the customer's name and address
are
> inserted onto the Excel spreadsheet.
>   This is a simple database application, and it used to work just fine.
The
> problem is that over time, it has started to successively slow WAY down.
> Should the customer list have changed much, I could see that, but it
hasn't!
> The list has only grown by 4 or 5 names.  When I say slow, I mean that the
> ComboBox's scroll handle doesn't follow your mouse, because it acts as if
it
> wants to stay right where it was when you opened it.  It will follow, but
it
> lags about a second behind when you drag it down, and it "jerks", rather
> than staying glued to your mouse pointer as you would expect a scroll bar
to
> do.  The code runs just fine on other computers.
>   I have tried updating VB (which does exist on the machine I run the
Excel
> spradsheet on) to Service Pack 4, I have updated Office 2000 SB to Service
> Release 2, I have run RegClean, I have uninstalled/reinstalled Excel, then
> the entire Office suite, all to no avail.  What could be wrong?  I'm
pulling
> my hair out here.
>   I've included the code below, as well as some sample lines from the
> datbase.  Thanks very very much for any help you can offer me.

> -Josh DeWinter
> Pullman, WA

> ---------------------
> Object descriptions:
> ---------------------
> There is one command button, "CommandButton1"
> and one ComboBox, "ComboBox1"...that's it.

> The VBA project consists of 1 module, 1 workbook, and 3 sheets.  (Sheets 2
> and 3 are empty).

> -----------------------------------------------
> The Code in "Module1" (the only module):
> -----------------------------------------------
> Global custArray(1 To 200, 1 To 7) As String

> --------------------------------------------------------------------------
--
> ---
> The code in the "ThisWorkbook" Excel workbook  (the only workbook):
> --------------------------------------------------------------------------
--
> ---
> Public Sub Workbook_Activate()

> Sheet1.CommandButton1.Caption = "Add an Address"
> Sheet1.ComboBox1.Visible = False
> Sheet1.ComboBox1.Text = "CLICK THE ARROW ON THE RIGHT SIDE OF THIS BOX TO
> DISPLAY THE LIST OF AVAILABLE NAMES -->"

> Dim Line1 As String
> Dim Line2 As String
> Dim Line3 As String
> Dim Line4 As String
> Dim Line5 As String
> Dim Line6 As String
> Dim counter As Integer
> counter = 1

> 'Inputting the data from the text file into the storage array "custArray":
> Open "C:\CustomerData\CustomerData_Billing.txt" For Input As #1
>     Do While Not EOF(1)
>         Input #1, ID, Line1, Line2, Line3, Line4, Line5, Line6
>         custArray(counter, 1) = ID
>         custArray(counter, 2) = Line1
>         custArray(counter, 3) = Line2
>         custArray(counter, 4) = Line3
>         custArray(counter, 5) = Line4
>         custArray(counter, 6) = Line5
>         custArray(counter, 7) = Line6

>         counter = counter + 1
>     Loop
> Close #1

> 'This command assigns all the data from the first string in each array
> element to the ComboBox all at once:
> Sheet1.ComboBox1.List = custArray

> End Sub

> --------------------------------------------------------------------------
--
> --------------------
> The code in "Sheet1" (one of three sheets in the workbook, this is the
only
> one with anything in it):
> --------------------------------------------------------------------------
--
> --------------------

> Private Sub ComboBox1_Change()
> Dim getout_flag As Integer
> getout_flag = 0

> 'We don't want to print the ComboBox on the final printout of this
invoice.
> Worksheets("sheet1").ComboBox1.PrintObject = False

> For i = 1 To 200

>         'custArray is two-dimensional.  The 1st dimension specifies the
> customer.
>         'The 2nd dimension is the individual pieces of a customer's
> information.
>         'The following If statement checks to see if what's in the
ComboBox
> now
>         'matches one of the ID elements (element 1) in the array (which it
> should,
>         'since the ComboBox was filled with those ID elemenets from the
> array
>         'when the Workbook was opened).
>         'When it finds the match, it assigns the contents of the other
array
> elements
>         'belonging to that ID to the appropriate cells in the worksheet.
> (elements 2-6).

>         If ComboBox1.Text = custArray(i, 1) Then
>             Worksheets("sheet1").Range("b12").Value = custArray(i, 2)
>             Worksheets("sheet1").Range("b13").Value = custArray(i, 3)
>             Worksheets("sheet1").Range("b14").Value = custArray(i, 4)
>             Worksheets("sheet1").Range("b15").Value = custArray(i, 5)
>             Worksheets("sheet1").Range("b16").Value = custArray(i, 6)
>             Worksheets("sheet1").Range("b17").Value = custArray(i, 7)
>             getout_flag = 1

>        End If

> Next i

> ComboBox1.Visible = False
> CommandButton1.Visible = True
> End Sub

> Private Sub CommandButton1_Click()
> Worksheets("sheet1").CommandButton1.PrintObject = False
> CommandButton1.Caption = "Change Address"
> ComboBox1.Visible = True
> CommandButton1.Visible = False

> End Sub

> --------------------------------------------------------------------------
> A sample of the text database file: (comma-seperated, double-quoted list)
> You'll notice some of the text fields are empty.  They are just there in
> case
> an address comes along that takes up many lines (max of 6).  If they are
> not used, they still have to be present in the file so that the Input#
> command
> doesn't get confused.  If they hold nothing, they are just empty double
> quotes,
> such as: "", "", ""
> --------------------------------------------------------------------------

> "Al Black", "Alan T. Black", "c/o Black Investments", "341 W. 1st.",
> "Spokane, WA  99201", "", ""
> "Bill's Plumbing", "Bill's Plumbing", "3117 N. Sharp", "Spokane, WA
43223",
> "", "", ""
> "RazorWare", "Scott Daniels", "RazorWare, inc.", "44112 E. Sprague",
> "Spokane, WA 99207", "", ""
> "Teddy B.", "Theodore Baker", "Swift Data Services", "4233 N. Indiana",
> "Spokane, WA   22122", "", ""

> Thanks again for any help you can offer me.
> -Josh



Tue, 01 Jul 2003 23:01:45 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Help with syntax. What am I doing wrong

2. Help on GPF...what am I doing wrong???

3. What am i doing wrong here????? HELP

4. What am I doin wrong..newbie needs help...

5. HELP: what am i doing wrong??

6. HELP: what am i doing wrong??

7. Help me Where I am Wrong !!!

8. HELP - What Am I Doing Wrong

9. help? where am i going wrong

10. Help: What am I doing wrong?

11. HELP: what am i doing wrong??

12. PLEASE HELP! VBA app calls in VB app

 

 
Powered by phpBB® Forum Software