473,382 Members | 1,431 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,382 software developers and data experts.

Can I turn off statement completion in a macro?

Greetings!

I am trying to write a set of macros to generate Property code for private
variables. With the cursor on a line that says "Private m_MyThing as
Thing", I would run the macro and

Public Property MyThing() As Thing
Get
Return m_MyThing
End Get
Set(ByVal Value As Thing)
m_MyThing = Value
End Set
End Property

would be automatically inserted into my code.

I have a macro that automatically generates a block of code that looks like
the above. The problem is that when it is inserted into my class module,
the statement completion kicks in and I get extra End Get, End Set and End
Property lines.

I would like to have my macro check the Statement Completion setting in my
IDE, remember the current setting, make sure it is off, generate the code,
insert the code, and restore the Statement Completion setting to its
original value. Is there a way to manipulate the Statement Completion
setting inside a macro?

Thanks very much!

Rob

P.S. I will be rewriting the macro to assume Statement Completion is on.
If anybody wants it, I'll be glad to supply it. If there's enough demand,
I'll just post it here.

Nov 20 '05 #1
4 1037
"Rob Richardson" <th*****@n2net.net> wrote in message
news:vv************@corp.supernews.com...
Public Property MyThing() As Thing
Get
Return m_MyThing
End Get
Set(ByVal Value As Thing)
m_MyThing = Value
End Set
End Property

I have a macro that automatically generates a block of code that looks like the above. The problem is that when it is inserted into my class module,
the statement completion kicks in and I get extra End Get, End Set and End
Property lines.


I have written this macro if you want it, but I assume you want to write it
your self. What method(s) are you using to insert text and to create new
lines?

~
Jeremy

Nov 20 '05 #2
Jeremy,

Does your macro handle the Statement Completion problem?

I'm using "sel.text = whatever_I_want_to_write". If a CrLf is encountered,
statement completion kicks in before the rest of the text is written. I got
around this by avoiding CrLfs. I write each line one at a time. After each
line, I move down, move to the start of the line, write a single CrLf to
move whatever was there out of the way, then move up a line (to the newly
blank line) and write the next line.

Rob
Nov 20 '05 #3
"Rob Richardson" <th*****@n2net.net> wrote in message
news:vv************@corp.supernews.com...
Jeremy,

Does your macro handle the Statement Completion problem?
Yes.
I'm using "sel.text = whatever_I_want_to_write".


I assume "sel" is an instance of DTE.ActiveDocument.Selection, in which case
you should use "Insert", not Text. I build my entire block of text first in
a temp variable ( called OutputBuffer ), then insert it, see below:
'// first, get away from the selected text
CurrentSelection.EndOfLine( )

'// add a few lines, for good measure
CurrentSelection.NewLine(3)

'// dump the buffer
CurrentSelection.Insert( OutputBuffer )

HTH,
Jeremy

Nov 20 '05 #4
Here is my implementation if you are interested:
(i have also attached it as a text doc)

~
Jeremy
______________________________________
Private Function GetFirstUnderscoreIndex(ByVal strString As String) As
Integer
Dim i As Integer
Dim sChr As String

For i = 1 To Len(strString)
sChr = Mid(strString, i, 1)
If sChr = "_" Then
Return i + 1
End If
Next
End Function

Sub PropertyFromVars()
Dim Scope As String = "Public"
Dim OutputBuffer As String
Dim LineTokens(), VariableTokens() As String
Dim i, SpaceIndex As Integer
Dim SelectedVariables As String = DTE.ActiveDocument.Selection.text
Dim CurrentSelection As TextSelection = DTE.ActiveDocument.Selection

Const VAR_NAME As Short = 0
Const VAR_TYPE As Short = 1

OutputBuffer = Replace(SelectedVariables, "Private ", "", , ,
vbTextCompare)
OutputBuffer = Replace(OutputBuffer, "Public ", "", , ,
vbTextCompare)
OutputBuffer = Replace(OutputBuffer, "Friend ", "", , ,
vbTextCompare)
OutputBuffer = Replace(OutputBuffer, "Protected ", "", , ,
vbTextCompare)

LineTokens = Split(OutputBuffer, vbCrLf)

OutputBuffer = ""
For i = 0 To UBound(LineTokens)
If LineTokens(i) <> "" And Mid(Trim(LineTokens(i)), 1, 1) <> "'"
Then
VariableTokens = Split(LineTokens(i), " as ", ,
vbTextCompare)

VariableTokens(VAR_TYPE) = VariableTokens(VAR_TYPE).Trim
VariableTokens(VAR_NAME) = VariableTokens(VAR_NAME).Trim

SpaceIndex = InStr(VariableTokens(VAR_TYPE), " ")
If SpaceIndex > 0 Then
VariableTokens(VAR_TYPE) = Mid(VariableTokens(VAR_TYPE),
1, SpaceIndex - 1)
End If

OutputBuffer = OutputBuffer & Scope & " Property " &
Mid(VariableTokens(VAR_NAME),
GetFirstUnderscoreIndex(VariableTokens(VAR_NAME))) .Substring(0, 1).ToUpper &
Mid(VariableTokens(VAR_NAME),
GetFirstUnderscoreIndex(VariableTokens(VAR_NAME))) .Substring(1) & "() As " &
VariableTokens(VAR_TYPE) & vbCrLf
OutputBuffer = OutputBuffer & " Get" & vbCrLf
OutputBuffer = OutputBuffer & " Return " &
VariableTokens(VAR_NAME) & vbCrLf
OutputBuffer = OutputBuffer & " End Get" & vbCrLf
OutputBuffer = OutputBuffer & " Set (ByVal Value As " &
VariableTokens(1) & ")" & vbCrLf
OutputBuffer = OutputBuffer & " " &
VariableTokens(VAR_NAME) & " = Value" & vbCrLf
OutputBuffer = OutputBuffer & " End Set" & vbCrLf
OutputBuffer = OutputBuffer & "End Property" & vbCrLf &
vbCrLf
End If
Next

CurrentSelection.EndOfLine()
CurrentSelection.NewLine(3)
CurrentSelection.Insert(OutputBuffer)
End Sub

Nov 20 '05 #5

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

Similar topics

3
by: Caleb Hattingh | last post by:
Hi Here is a script I want to be able to write (explanation appears after): *** start of script *** import MyCustomMacroLib # This does the magic I would like help for. # This is not...
67
by: Steven T. Hatton | last post by:
Some people have suggested the desire for code completion and refined edit-time error detection are an indication of incompetence on the part of the programmer who wants such features. ...
4
by: Polly | last post by:
I had a macro that ran a parameter query and created and opened an Excel file with the system date as part of the file name, but I had to change the file name by hand. So I converted the macro to...
48
by: Foobarius Frobinium | last post by:
http://thelinuxlink.net/~fingolfin/pointer-guide Tell me what you think...
1
by: Chuck | last post by:
I am writing a database program in C#. I have a situation when I type the '(' after typing a method call, VS goes into an infinite loop. I then have to exit VS. Has anyone else had any trouble...
5
by: HS Hartkamp | last post by:
Hi all, I am working with fairly large databases (> 500 Mb / < 2,000,000 rexcords), and often need to do action queries on these. I have the feeling that much of the computing power is going...
2
by: chris.fairles | last post by:
So I took a look at assert.h because I knew it uses -DNDEBUG to turn off its assert statements but it does some funky stuff that I don't quite understand. I made my own def's something like: ...
1
by: hotflash | last post by:
Hi Master CroCrew et All, I am working on a CASE statement to allow different type of searches to search for different type of projects. EVERYTHING WORKS FINE EXCEPT, if the "Any Projects" radio...
46
by: Neal Becker | last post by:
I'd like to turn off ZeroDivisionError. I'd like 0./0. to just give NaN, and when output, just print 'NaN'. I notice fpconst has the required constants. I don't want to significantly slow...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...

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.