View Full Version : How do I speed up this code?
11-17-2005, 12:19 PM
I am new to programming MapPoint and I would like to speed up the following code that I have written using Excel VBA (this is just an extract not the complete subroutine)
Set objRS = objDataSet.QueryAllRecords
'Loop through all the records (if any)
' Symbol 336 is first of Custom set
Do Until objRS.EOF
Set objFldStatus = objRS.Fields.Item("Status")
Set objFldType = objRS.Fields.Item("Type")
Select Case objFldStatus.Value
Select Case objFldType.Value
objRS.Pushpin.Symbol = 16 ' black dot
objRS.Pushpin.Symbol = 23 ' purple dot
objRS.Pushpin.Symbol = 17 ' red dot
objRS.Pushpin.Symbol = 22 ' green dot
objRS.Pushpin.Symbol = 21 ' cyan dot
objRS.Pushpin.Symbol = 20 ' blue dot
objRS.Pushpin.Symbol = 254 ' question mark
objRS.Pushpin.Symbol = 336 ' transparent
objRS.Pushpin.Symbol = 336 ' transparent
objRS.Pushpin.Symbol = 255 ' exclamation mark
'Move to the next record (or to EOF)
I have also tried using the if ... then ... else if construct but I did not detect much reduction in execution time when processing 10,000 records.
As I do not have VB6 nor do I have Microsoft Office XP Developer I am unable to create a DLL :(
11-17-2005, 01:40 PM
I dont think you can speed this code up. If/else does the same as a Case statement, also you do a 1 byte compare (or 2), so that is also fast because it is only CPU register comparisation.
The problem is probably also not because you loop in 10000 records (you can test this of course), but because you are redisplaying all the pushpins (changing the symbols), and that is what take time.
So what you eventually can do is process the whole data and whilst processing check which symbol you want and put the pushpin on mappoint, so then it is only 1 loop while it is displayed and the whole time will be exact the time needed for display.
I hope my explanation make sence...
11-17-2005, 02:13 PM
... So what you eventually can do is process the whole data and whilst processing check which symbol you want and put the pushpin on mappoint, so then it is only 1 loop while it is displayed and the whole time will be exact the time needed for display...
Thank you for the quick reply - much faster than MapPoint ;)
I will do some tests to see where the time is being consumed by removing various bits of the code.
In the quoted paragraph from your reply are you suggesting that I should check to see if the symbol already exists and only update it if it is different? I have tried running without the map display on and I have not noticed any significant different in execution time. MapPoint certainly uses 100% of the available CPU time.
11-17-2005, 02:24 PM
n the quoted paragraph from your reply are you suggesting that I should check to see if the symbol already exists and only update it if it is different?
No, I'm sorry but my English is not so good to express myself sometime :(
what I meant was following:
Now (as far as I can conclude from your code) you trow all positions into mappoint database. Then you check each record and eventually update symbol. This is time consuming.
I meant that you go tru your own data first in VBA, and for each record assign the right symbol and trow the symbol to mappoint.
This way all the work is done in one single loop, and you are not depending on the speed of mappoint.
Is this more clear what I mean ?
11-17-2005, 09:40 PM
Wilfried has a good overall idea. If it fits what you're doing, it will be the fastest option.
If you must use this code, there are three things you can try:
- Simplify your comparisons. Can you work with numbers for the first 2 chars?
If you use numbers, you can use a Look Up Table.
- Are some options more likely than others?
List them in order of likelihood. The most likely first. This removes many unnecessary comparisons.
Also investigate a binary search instead of a linear one.
- Use the VB6 "With...End" statement. This avoids a lot of VB's member lookup processing time.
11-18-2005, 11:55 AM
Wilfried and Richard,
Many thanks for your help. I now understand that it is best to prepare my data in Excel prior to invoking MapPoint. The easiest change for me is to prepare a Symbol field in my Excel spreadsheet and use this to set the pushpin symbol. It is a pity that Microsoft do not recognise a field name of Symbol and use this directly. This would get round the restriction of 8 different pushpins of the Multiple Symbol Map; it is not always necessary to have a legend.
Am I correct in thinking that an XLA file executes more quickly than the same code run from within the VBA Editor? It seems to for me. I say seems because the timings that I have taken vary such a lot.
Powered by vBulletin® Version 4.2.2 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.
Search Engine Friendly URLs by vBSEO