Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > Pro VB 6
|
Pro VB 6 For advanced Visual Basic coders working in version 6 (not .NET). Beginning-level questions will be redirected to other forums, including Beginning VB 6.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro VB 6 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 20th, 2006, 07:52 PM
Registered User
 
Join Date: Apr 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Why does Excel VBA code run faster than VB?

I've written a macro in Excel VBA. When I translated the program into VB6 I noticed a significant reduction in the processing speed. The only difference in the code is that VB6 references the application object in excel. How could this slow down the program speed? The processing time went from 3 seconds to more than one minute. How do I get around this problem if I absolutely want to create an executable file in VB6 that controls Excel? (Same computer was used for both versions)

:) mambojedi
 
Old April 21st, 2006, 03:11 PM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

When you run the code within Excel, the VBA functionality is a part if the process/thread of Excel. No "communication with" is required.

When using automation, a lot of requests, responses, laoding of resources, etc., must take place. Automation is slick, but it is always going to be slower.

What is it that you are trying to do? Perhaps there is a way to coordinate resources to speed things up.
 
Old April 21st, 2006, 05:02 PM
Registered User
 
Join Date: Apr 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Brian,
thank you for the info. Which resources would I have to coordinate to speed things up? I thought that the speed problem may have had something to do with "early" or "late" binding. I've read that early binding was better (That's what I'm using) but it didn't produce a significant increase in speed. The program basically imports a tab delimited file, then sorts and copies the data into two columns on a separate worksheet. I've noticed a speed increase if you activate or reference a cell's value directly rather than by selecting the sheet and then the selecting the cell. Makes sense since excel doesn't have to waste time doing such things which could take up memory. The Application.ScreenUpdating feature was turned off and excel is hidden while the program is run from my VB-6 form. That helps speed it up but again, not as fast as VBA. Finally, the main reason I wanted to create an EXE using VB-6 was because I wanted to make it easy to distribute the program and because the new security features in office cause problems when trying to create a rich text box which I absolutely want to use in this program. Note that the rich text box problem is actually caused by Internet explorer and the fix to get around it is to edit the registry, but that only solves the problem on a per day basis since it resets a day or two later on its own. Therefore using VB-6 is less of a hassle when dealing with rich text boxes since it doesn't have the same limitations imposed by office's security features.

mambojedi :)
 
Old April 24th, 2006, 02:48 PM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

When you will be reading from a database again and again, you can speed things up by reading an entire table into an array, then using that array.
If you need to grab bits & pieces from a text file, rather than passing a reference to the file around, you can read the whole thing into a string to reduce the overhead of opening the file repeatedly.

Accordingly, perhaps Excel provides a way to get all the values into VB as an array (like a database’s getrows() function). If so, mniipulating that array in VB will be a much bigger programming task, but a lot faster.

Your richtext box issue sounds like your network administrators are tweaking the registry every now and again, then pushing that new registry "version" onto peoples' machines when they log in. If that's the case, see if you can get them to officially endorse your registry change, so that it would be part of every registry change package (if indeed that is what is happening).

I don’t follow where a RTBx would fit into the process you described?





Similar Threads
Thread Thread Starter Forum Replies Last Post
Run a MS DOS Batch file from Excel VBA Louh Excel VBA 1 March 4th, 2008 10:02 PM
Code works in Excel VBA but not Access VBA fossx Access VBA 2 May 21st, 2007 08:00 AM
Run .bat file from Excel VBA Harold Hawken Excel VBA 2 June 23rd, 2005 03:03 PM
Excel sometimes loses VBA code James Diamond Excel VBA 0 May 25th, 2004 03:43 AM
Run VBA Excel File On Internet Explorer DHDang Excel VBA 0 November 12th, 2003 03:39 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.