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

VB.Net macros - how to fetch string in clipboard into a string variable

Hi all,

I'm finally sick and tired of manually generating get/set properties for
each private variable in a class so I'm trying to create a macro to do it.

I'm stuck because I can't figure out how to get a string that is in the
clipboard into a variable in the macro. I tried this:

Dim x as string = DTE.ActiveDocument.Selection.Paste() thinking it would
"paste" the clipboard into the string variable X, but it just pasted the
string into the document.

Can somebody give me a code example that transfers the string in the
clipboard into a variable in the macro?

Thanks,
John
Nov 21 '05 #1
4 4196

JohnR wrote:
Hi all,

I'm finally sick and tired of manually generating get/set properties for each private variable in a class so I'm trying to create a macro to do it.
I'm stuck because I can't figure out how to get a string that is in the clipboard into a variable in the macro. I tried this:

Dim x as string = DTE.ActiveDocument.Selection.Paste() thinking it would "paste" the clipboard into the string variable X, but it just pasted the string into the document.

Can somebody give me a code example that transfers the string in the
clipboard into a variable in the macro?

Thanks,
John


this defeats the purpose of having private member variables -- the idea
is to perform some sort of testing in the "set". if this is not
necessary, then make the variable public and be done with it...

Nov 21 '05 #2
Look up 'Clipboard' & 'Text'. You will then find an example in the built in
MSDN Documentation

Crouchie1998
BA (HONS) MCP MCSE
Nov 21 '05 #3
I'm sorry, I must not have made my question clear.

When I'm actually writing the code in the IDE and I type "private _myvar as
string" I want to have a macro automatically generate
the Property get-set code. This question has nothing at all to do about
actually running the program. One way of doing this involves
copying the "private _myvar as string" line into the clipboard,
repositioning the cursor to where you want the property code to be, and
then running the macro that will copy the string in the clipboard into a
string variable and then process it... That is the genesis of my question
of "how do you get a string from the clipboard into a string variable in a
macro?"

John

"stand__sure" <st*********@hotmail.com> wrote in message
news:11*********************@g43g2000cwa.googlegro ups.com...

JohnR wrote:
Hi all,

I'm finally sick and tired of manually generating get/set

properties for
each private variable in a class so I'm trying to create a macro to

do it.

I'm stuck because I can't figure out how to get a string that is in

the
clipboard into a variable in the macro. I tried this:

Dim x as string = DTE.ActiveDocument.Selection.Paste() thinking it

would
"paste" the clipboard into the string variable X, but it just pasted

the
string into the document.

Can somebody give me a code example that transfers the string in the
clipboard into a variable in the macro?

Thanks,
John


this defeats the purpose of having private member variables -- the idea
is to perform some sort of testing in the "set". if this is not
necessary, then make the variable public and be done with it...

Nov 21 '05 #4
Here is a couple of macros that I use. To use them, you would declare
your private variables like this: Private m_SomeName As Integer. It
will take the name of the property excluding the m_ from the front. If
you don't use m_ you will have to change the InsertProperty method to
handle whatever convention you use. The ReservedWords array is for
property names that are reserved words. I only show a few in this
post, but you can add any reserved word to this array and the macro
will put it in square brackets as needed.

Friend ReservedWords() As String = {"ASSEMBLY", "CLASS", "FORM"}

Public Sub PropertyFromVar()
Dim ts As TextSelection = CType(DTE.ActiveWindow.Selection,
TextSelection)
Dim m_PropertyList(ts.TextRanges.Count - 2) As String
Dim m_Index As Integer
Dim start As EditPoint = ts.TopPoint.CreateEditPoint()
Dim endpt As TextPoint = ts.BottomPoint
Dim sb As New StringBuilder

'Make these upper case
Try
Do While (start.LessThan(endpt))
m_PropertyList(m_Index) =
start.GetText(start.LineLength).Trim.Replace("New" , "").Replace("()",
"")
start.LineDown()
start.StartOfLine()
m_Index += 1
Loop
Catch ex As System.Exception
Debug.WriteLine(ex)
End Try

Dim cnt As Integer = m_Index

For m_Index = 0 To m_PropertyList.GetUpperBound(0)
sb.Append(InsertProperty(m_PropertyList(m_Index)))
Next
ts.MoveToPoint(ts.ActivePoint.CodeElement(vsCMElem ent.vsCMElementClass).GetEndPoint(vsCMPart.vsCMPar tWhole))
ts.LineUp()
ts.EndOfLine()
ts.NewLine()
ts.NewLine()

ts.Insert(sb.ToString)

DTE.ExecuteCommand("Edit.FormatDocument")

End Sub

Nov 21 '05 #5

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

Similar topics

9
by: Agent Mulder | last post by:
My funky new compiler does not understand string, but it does understand String, so that this program gives the expected result: #include<iostream> #include<string> int main() { String...
0
by: Hessam | last post by:
Hello, I am designing a .net custom control in VS.net 7.1 and my control exposes an array of strings which are supposed to be the items to show. To do this have declared a private string variable...
4
by: J. Oliver | last post by:
I am attempting to copy a portion of a string into another string. Say I have "abcdef" in string 'a' and want to copy only "bcd" into a new string 'b'. The following function came to mind: ...
6
by: Raed Sawalha | last post by:
i have the following case a MyClass class has method with 2 arguments as void SetProp(string varname,string varvalue); in MyClass i have following members string...
6
by: Frank King | last post by:
Hi, I am looking for a hash function to map string to string in VB. Could somebody give me some informtion? Thank you very much. fk
7
by: Bruce One | last post by:
What is the difference between String and string in C#? What can u do with string that you cant do with String, vice versa?
1
by: jrgoncal | last post by:
Hi, basically what i want to do is use a string as a variable, so instead of doing this: $ar = new array("Dog","Cat","Bear","Dear","Postal Worker"); $var_1 = $ar; $var_2 = $ar; $var_3 = $ar;...
5
by: rohdej | last post by:
Hello - I have been all over the web and found a few posts that are somewhat related to what I'm trying to do, but none that provided me a concise answer. I want to prompt the user to input the...
7
by: =?Utf-8?B?R3JlZw==?= | last post by:
I've noticed two different "String" variable declarations to choose from. One uses an upper case "S" and the other uses a lower case "s". The upper case appears in a light green color, while the...
6
by: vijayarl | last post by:
Hi Everyone, i need to add a string in between the filename.so that new file will have the required filename. what am doing is reading the files from the directory & extract only the filename...
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: 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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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.