473,386 Members | 1,705 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Macros too slow !

Hi all,

I posted this topic in microsoft.public.dotnet.general but received no
reply. So hoping for a reply here...

I'm trying to use a macro in VS 2003 to insert a code snippet in
various sections of my code. This code will help me to test the time
taken for any particular action to be performed.

The problem is that it takes nearly 30 seconds for it to be executed,
after I press my Keyboard shortcut, and to see the results in my code
window. I'm new to using macros in the IDE, so I have no idea if the
macro is actually being compiled and then executed or what !

The macro code is as follows :
=========================
Sub TimeSpanCheck()
Dim objDoc As Document = DTE.ActiveDocument
Dim mySel As TextSelection = objDoc.Selection
mySel.Text = "Console.Write(""Time before the action :"")"
mySel.NewLine()
mySel.Text = "Dim oldTime As DateTime = DateTime.Now"
mySel.NewLine()
mySel.Text = "Console.WriteLine(""{0:HH:mm:ss.fff}"", oldTime)"

mySel.NewLine()
mySel.Text = " ' "
mySel.NewLine()
mySel.Text = " ' My actions here"
mySel.NewLine()
mySel.Text = " ' "
mySel.NewLine()
mySel.Text = "Console.Write(""Time after the action :"")"
mySel.NewLine()
mySel.Text = "Dim newTime As DateTime = DateTime.Now"
mySel.NewLine()
mySel.Text = "Console.WriteLine(""{0:HH:mm:ss.fff}"", newTime)"

mySel.NewLine()
mySel.Text = "Dim Diff As TimeSpan = newTime.Subtract(oldTime)"

mySel.NewLine()
mySel.Text = "Console.WriteLine(""Time taken for process :
{0}min:{1}secs:{2}millisecs"", Diff.Minutes, Diff.Seconds,
Diff.Milliseconds)"
mySel.NewLine()
objDoc.Save()
End Sub
=========================
Am I doing something wrong here, or is this time taken normal ? Also,
is there a way to speed it up (something like precompiling the code.)
Any comments are appreciated,
Regards,
Cerebrus.

Mar 6 '06 #1
3 1249
Hi,

You are using TextSelection.Text property to insert the text. This may
be the reason of slow execution. The better way is to use
TextSelection.Insert method. See my blog on VS macros at
http://www.vbdocman.com/blog/archives/14. This article contains very
simple macro which inserts some code at the current cursor position. In
addition it correctly handles Undo operation. It executes immediately.

FYI, you can find more responses about for VS add-ins and macros in
microsoft.public.vb.addins.
--
Peter Macej
Helixoft - http://www.vbdocman.com
VBdocman - Automatic generator of technical documentation for VB, VB
..NET and ASP .NET code
Mar 6 '06 #2
Hi Peter,

AFAIK, microsoft.public.vb.addins is for VB6 add-ins, not for VS.NET
add-ins. I used to answer questions in that newsgroup long time ago...

--

Best regards,

Carlos J. Quintero

MZ-Tools: Productivity add-ins for Visual Studio
You can code, design and document much faster:
http://www.mztools.com

"Peter Macej" <pe***@vbdocman.com> escribió en el mensaje
news:%2****************@TK2MSFTNGP10.phx.gbl...
Hi,

You are using TextSelection.Text property to insert the text. This may be
the reason of slow execution. The better way is to use
TextSelection.Insert method. See my blog on VS macros at
http://www.vbdocman.com/blog/archives/14. This article contains very
simple macro which inserts some code at the current cursor position. In
addition it correctly handles Undo operation. It executes immediately.

FYI, you can find more responses about for VS add-ins and macros in
microsoft.public.vb.addins.
--
Peter Macej
Helixoft - http://www.vbdocman.com
VBdocman - Automatic generator of technical documentation for VB, VB .NET
and ASP .NET code

Mar 6 '06 #3
Wow ! Thanks a lot, Peter.

After checking your sample, I realized that I could use all the
Framework classes here. So I used a StringBuilder to build up the Code
fragment and then used ONE insert statement only. I also learnt how to
use Undo.

Now it works, and it is instantaneous ! ;-)

Thanks again,

Regards,

Cerebrus.

Mar 6 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
by: Chris Reedy | last post by:
For everyone - Apologies for the length of this message. If you don't want to look at the long example, you can skip to the end of the message. And for the Python gurus among you, if you can...
699
by: mike420 | last post by:
I think everyone who used Python will agree that its syntax is the best thing going for it. It is very readable and easy for everyone to learn. But, Python does not a have very good macro...
16
by: mike420 | last post by:
Tayss wrote: > > app = wxPySimpleApp() > frame = MainWindow(None, -1, "A window") > frame.Show(True) > app.MainLoop() > Why do you need a macro for that? Why don't you just write
37
by: michele.simionato | last post by:
Paul Rubin wrote: > How about macros? Some pretty horrible things have been done in C > programs with the C preprocessor. But there's a movememnt afloat to > add hygienic macros to Python. Got any...
12
by: Steven T. Hatton | last post by:
I've noticed in different places where people who write #MACROS use a null do/while. For example: do { POINTER = new CONSTRUCTOR; \ if (POINTER == 0) { errno = ENOMEM; ACE_THROW_INT...
1
by: Cerebrus | last post by:
Hi all, I'm trying to use a macro in VS 2003 to insert a code snippet in various sections of my code. This code will help me to test the time taken for any particular action to be performed. ...
17
by: Alex Buell | last post by:
A previous thread about macros just reminded me to ask this. I have avoided using macros and defined some constants i.e.: const int BYTES_PER_TRACK = 10 * 256; const int TRACK0_SS_OFFSET = 0;...
33
by: Robert Seacord | last post by:
When writing C99 code is a reasonable recommendation to use inline functions instead of macros? What sort of things is it still reasonable to do using macros? For example, is it reasonable to...
5
by: sturlamolden | last post by:
Hello The Lisp crowd always brags about their magical macros. I was wondering if it is possible to emulate some of the functionality in Python using a function decorator that evals Python code...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.