Re-use snippets of code

  • Thread starter Thread starter moondaddy
  • Start date Start date
M

moondaddy

I've seen how people have snippets of code stored over by the tool box and
then can drag them into a code page. What do you call this and what's a
reference on how to do this?

Thanks.
 
Hi


It is called the ClipBoard Ring. Basically it allows you to copy and
paste or cut and paste from your code window into it. You can then drag
code snippets from it back into code windows as you need them.

Here is the Help item from VS:
To use the Clipboard ring

1.. Cut or copy some text from your code. Use CTRL+X to cut or CTRL+C to
copy. The last item you cut or copy into the Clipboard Ring is the current
item for pasting.
2.. Use CTRL+SHIFT+V to paste the Clipboard Ring's current item to the
current document.
3.. Repeatedly press CTRL+SHIFT+V to cycle through the entries in the
Clipboard Ring until you get to the one you want to permanently paste in the
document. Each time you press CTRL+SHIFT+V, the Editor replaces the last
entry you pasted from the Clipboard Ring so that you end up with only the
last one you selected. The item you stop on then becomes the current item.
4.. Move to another location or cancel the selection. You can use
CTRL+SHIFT+V to paste the current item again or cycle the Clipboard Ring to
a new item.
 
Thanks

--
(e-mail address removed)
Ged Mead said:
Hi


It is called the ClipBoard Ring. Basically it allows you to copy and
paste or cut and paste from your code window into it. You can then drag
code snippets from it back into code windows as you need them.

Here is the Help item from VS:
To use the Clipboard ring

1.. Cut or copy some text from your code. Use CTRL+X to cut or CTRL+C to
copy. The last item you cut or copy into the Clipboard Ring is the current
item for pasting.
2.. Use CTRL+SHIFT+V to paste the Clipboard Ring's current item to the
current document.
3.. Repeatedly press CTRL+SHIFT+V to cycle through the entries in the
Clipboard Ring until you get to the one you want to permanently paste in
the
document. Each time you press CTRL+SHIFT+V, the Editor replaces the last
entry you pasted from the Clipboard Ring so that you end up with only the
last one you selected. The item you stop on then becomes the current item.
4.. Move to another location or cancel the selection. You can use
CTRL+SHIFT+V to paste the current item again or cycle the Clipboard Ring
to
a new item.
 
Hi,

Here is how to add a tab to the toolbox that contains some code
snippit. Here is some code for a console app.

Imports EnvDTE

Module Module1

Sub Main()

Dim myDTE As DTE

myDTE =
CType(Microsoft.VisualBasic.Interaction.CreateObject("VisualStudio.DTE.7.1"),
DTE)

Dim objToolbox As ToolBox

Dim colTbxTabs As ToolBoxTabs

Dim objTab As ToolBoxTab

Dim colTbxItems As ToolBoxItems

Dim objTbxItem As ToolBoxItem

objToolbox = CType(myDTE.Windows.Item(Constants.vsWindowKindToolbox).Object,
ToolBox)

colTbxTabs = objToolbox.ToolBoxTabs

' look to see if tab exists

Dim bFound As Boolean = False

Dim tbtDelete As ToolBoxTab

For Each t As ToolBoxTab In colTbxTabs

If t.Name = "WMI Code" Then

tbtDelete = t

bFound = True

End If

Next



If bFound Then tbtDelete.Delete()

objTab = colTbxTabs.Add("WMI Code")

objTab.Activate()

Dim sbCode As New System.Text.StringBuilder

sbCode.Append("' Add a Reference to System.Management" & ControlChars.CrLf)

sbCode.Append("Dim moReturn As Management.ManagementObjectCollection" &
ControlChars.CrLf)

sbCode.Append("Dim moSearch As Management.ManagementObjectSearcher" &
ControlChars.CrLf)

sbCode.Append("Dim mo As Management.ManagementObject" & ControlChars.CrLf)

sbCode.Append("" & ControlChars.CrLf)

sbCode.Append("moSearch = New Management.ManagementObjectSearcher(""Select *
from Win32_LogicalDisk"")" & ControlChars.CrLf)

sbCode.Append("moReturn = moSearch.Get" & ControlChars.CrLf)

sbCode.Append("For Each mo In moReturn" & ControlChars.CrLf)

sbCode.Append(" Dim strOut As String" & ControlChars.CrLf)

sbCode.Append(" strOut = String.Format(""Drive {0} - Drive Type {1}"",
mo(""Name""), mo(""DriveType""))" & ControlChars.CrLf)

sbCode.Append(" Trace.WriteLine(strOut)" & ControlChars.CrLf)

sbCode.Append("Next" & ControlChars.CrLf)

objTab.ToolBoxItems.Add("LogicalDisk", sbCode.ToString,
vsToolBoxItemFormat.vsToolBoxItemFormatText)

sbCode = New System.Text.StringBuilder

sbCode.Append("' Add a Reference to System.Management" & ControlChars.CrLf)

sbCode.Append("Dim moReturn As Management.ManagementObjectCollection" &
ControlChars.CrLf)

sbCode.Append("Dim moSearch As Management.ManagementObjectSearcher" &
ControlChars.CrLf)

sbCode.Append("Dim mo As Management.ManagementObject" & ControlChars.CrLf)

sbCode.Append("" & ControlChars.CrLf)

sbCode.Append("moSearch = New Management.ManagementObjectSearcher(""Select *
from Win32_Group"")" & ControlChars.CrLf)

sbCode.Append("moReturn = moSearch.Get" & ControlChars.CrLf)

sbCode.Append("For Each mo In moReturn" & ControlChars.CrLf)

sbCode.Append(" Trace.WriteLine(mo(""Name""))" & ControlChars.CrLf)

sbCode.Append("Next" & ControlChars.CrLf)

objTab.ToolBoxItems.Add("Groups", sbCode.ToString,
vsToolBoxItemFormat.vsToolBoxItemFormatText)

sbCode = New System.Text.StringBuilder

sbCode.Append("' Add a Reference to System.Management" & ControlChars.CrLf)

sbCode.Append("Dim moReturn As Management.ManagementObjectCollection" &
ControlChars.CrLf)

sbCode.Append("Dim moSearch As Management.ManagementObjectSearcher" &
ControlChars.CrLf)

sbCode.Append("Dim mo As Management.ManagementObject" & ControlChars.CrLf)

sbCode.Append("" & ControlChars.CrLf)

sbCode.Append("moSearch = New Management.ManagementObjectSearcher(""Select *
from Win32_Process"")" & ControlChars.CrLf)

sbCode.Append("moReturn = moSearch.Get" & ControlChars.CrLf)

sbCode.Append("For Each mo In moReturn" & ControlChars.CrLf)

sbCode.Append(" Dim arOwner(2) As String" & ControlChars.CrLf)

sbCode.Append(" mo.InvokeMethod(""GetOwner"", arOwner)" & ControlChars.CrLf)

sbCode.Append(" Dim strOut As String" & ControlChars.CrLf)

sbCode.Append(" strOut = String.Format(""{0} Owner {1} Domain {2}"",
mo(""Name""), arOwner(0), arOwner(1))" & ControlChars.CrLf)

sbCode.Append(" Trace.WriteLine(strOut)" & ControlChars.CrLf)

sbCode.Append("Next" & ControlChars.CrLf)

objTab.ToolBoxItems.Add("ProcessOwner", sbCode.ToString,
vsToolBoxItemFormat.vsToolBoxItemFormatText)

sbCode = New System.Text.StringBuilder

sbCode.Append("' Add a Reference to System.Management" & ControlChars.CrLf)

sbCode.Append("Dim moReturn As Management.ManagementObjectCollection" &
ControlChars.CrLf)

sbCode.Append("Dim moSearch As Management.ManagementObjectSearcher" &
ControlChars.CrLf)

sbCode.Append("Dim mo As Management.ManagementObject" & ControlChars.CrLf)

sbCode.Append("" & ControlChars.CrLf)

sbCode.Append("moSearch = New Management.ManagementObjectSearcher(""Select *
from Win32_Processor"")" & ControlChars.CrLf)

sbCode.Append("moReturn = moSearch.Get" & ControlChars.CrLf)

sbCode.Append("For Each mo In moReturn" & ControlChars.CrLf)

sbCode.Append(" Dim strOut As String" & ControlChars.CrLf)

sbCode.Append(" strOut = String.Format(""{0} - ID {1}"", mo(""Name""),
mo(""ProcessorID""))" & ControlChars.CrLf)

sbCode.Append(" Trace.WriteLine(strOut)" & ControlChars.CrLf)

sbCode.Append("Next" & ControlChars.CrLf)

objTab.ToolBoxItems.Add("Processor", sbCode.ToString,
vsToolBoxItemFormat.vsToolBoxItemFormatText)

' Add a Reference to System.Management

Dim moReturn As Management.ManagementObjectCollection

Dim moSearch As Management.ManagementObjectSearcher

Dim mo As Management.ManagementObject

moSearch = New Management.ManagementObjectSearcher("Select * from
Win32_Group")

moReturn = moSearch.Get

For Each mo In moReturn

Trace.WriteLine(mo("Name"))

Next

End Sub

End Module



Ken

------------------------

I've seen how people have snippets of code stored over by the tool box and
then can drag them into a code page. What do you call this and what's a
reference on how to do this?

Thanks.
 
Hi,

The clipboard ring wont be there after you close the ide. See my
reply on how to add a tab to the toolbox with some code snippits.

Ken
----------------
Hi


It is called the ClipBoard Ring. Basically it allows you to copy and
paste or cut and paste from your code window into it. You can then drag
code snippets from it back into code windows as you need them.

Here is the Help item from VS:
To use the Clipboard ring

1.. Cut or copy some text from your code. Use CTRL+X to cut or CTRL+C to
copy. The last item you cut or copy into the Clipboard Ring is the current
item for pasting.
2.. Use CTRL+SHIFT+V to paste the Clipboard Ring's current item to the
current document.
3.. Repeatedly press CTRL+SHIFT+V to cycle through the entries in the
Clipboard Ring until you get to the one you want to permanently paste in the
document. Each time you press CTRL+SHIFT+V, the Editor replaces the last
entry you pasted from the Clipboard Ring so that you end up with only the
last one you selected. The item you stop on then becomes the current item.
4.. Move to another location or cancel the selection. You can use
CTRL+SHIFT+V to paste the current item again or cycle the Clipboard Ring to
a new item.
 
Hi,

Sorry forgot to mention you need to add a reference to envdte
for this to work. Sample works best if you build the app and run it with
vs.net closed.

Ken
---------------------
Hi,

Here is how to add a tab to the toolbox that contains some code
snippit. Here is some code for a console app.

Imports EnvDTE

Module Module1

Sub Main()

Dim myDTE As DTE

myDTE =
CType(Microsoft.VisualBasic.Interaction.CreateObject("VisualStudio.DTE.7.1"),
DTE)

Dim objToolbox As ToolBox

Dim colTbxTabs As ToolBoxTabs

Dim objTab As ToolBoxTab

Dim colTbxItems As ToolBoxItems

Dim objTbxItem As ToolBoxItem

objToolbox = CType(myDTE.Windows.Item(Constants.vsWindowKindToolbox).Object,
ToolBox)

colTbxTabs = objToolbox.ToolBoxTabs

' look to see if tab exists

Dim bFound As Boolean = False

Dim tbtDelete As ToolBoxTab

For Each t As ToolBoxTab In colTbxTabs

If t.Name = "WMI Code" Then

tbtDelete = t

bFound = True

End If

Next



If bFound Then tbtDelete.Delete()

objTab = colTbxTabs.Add("WMI Code")

objTab.Activate()

Dim sbCode As New System.Text.StringBuilder

sbCode.Append("' Add a Reference to System.Management" & ControlChars.CrLf)

sbCode.Append("Dim moReturn As Management.ManagementObjectCollection" &
ControlChars.CrLf)

sbCode.Append("Dim moSearch As Management.ManagementObjectSearcher" &
ControlChars.CrLf)

sbCode.Append("Dim mo As Management.ManagementObject" & ControlChars.CrLf)

sbCode.Append("" & ControlChars.CrLf)

sbCode.Append("moSearch = New Management.ManagementObjectSearcher(""Select *
from Win32_LogicalDisk"")" & ControlChars.CrLf)

sbCode.Append("moReturn = moSearch.Get" & ControlChars.CrLf)

sbCode.Append("For Each mo In moReturn" & ControlChars.CrLf)

sbCode.Append(" Dim strOut As String" & ControlChars.CrLf)

sbCode.Append(" strOut = String.Format(""Drive {0} - Drive Type {1}"",
mo(""Name""), mo(""DriveType""))" & ControlChars.CrLf)

sbCode.Append(" Trace.WriteLine(strOut)" & ControlChars.CrLf)

sbCode.Append("Next" & ControlChars.CrLf)

objTab.ToolBoxItems.Add("LogicalDisk", sbCode.ToString,
vsToolBoxItemFormat.vsToolBoxItemFormatText)

sbCode = New System.Text.StringBuilder

sbCode.Append("' Add a Reference to System.Management" & ControlChars.CrLf)

sbCode.Append("Dim moReturn As Management.ManagementObjectCollection" &
ControlChars.CrLf)

sbCode.Append("Dim moSearch As Management.ManagementObjectSearcher" &
ControlChars.CrLf)

sbCode.Append("Dim mo As Management.ManagementObject" & ControlChars.CrLf)

sbCode.Append("" & ControlChars.CrLf)

sbCode.Append("moSearch = New Management.ManagementObjectSearcher(""Select *
from Win32_Group"")" & ControlChars.CrLf)

sbCode.Append("moReturn = moSearch.Get" & ControlChars.CrLf)

sbCode.Append("For Each mo In moReturn" & ControlChars.CrLf)

sbCode.Append(" Trace.WriteLine(mo(""Name""))" & ControlChars.CrLf)

sbCode.Append("Next" & ControlChars.CrLf)

objTab.ToolBoxItems.Add("Groups", sbCode.ToString,
vsToolBoxItemFormat.vsToolBoxItemFormatText)

sbCode = New System.Text.StringBuilder

sbCode.Append("' Add a Reference to System.Management" & ControlChars.CrLf)

sbCode.Append("Dim moReturn As Management.ManagementObjectCollection" &
ControlChars.CrLf)

sbCode.Append("Dim moSearch As Management.ManagementObjectSearcher" &
ControlChars.CrLf)

sbCode.Append("Dim mo As Management.ManagementObject" & ControlChars.CrLf)

sbCode.Append("" & ControlChars.CrLf)

sbCode.Append("moSearch = New Management.ManagementObjectSearcher(""Select *
from Win32_Process"")" & ControlChars.CrLf)

sbCode.Append("moReturn = moSearch.Get" & ControlChars.CrLf)

sbCode.Append("For Each mo In moReturn" & ControlChars.CrLf)

sbCode.Append(" Dim arOwner(2) As String" & ControlChars.CrLf)

sbCode.Append(" mo.InvokeMethod(""GetOwner"", arOwner)" & ControlChars.CrLf)

sbCode.Append(" Dim strOut As String" & ControlChars.CrLf)

sbCode.Append(" strOut = String.Format(""{0} Owner {1} Domain {2}"",
mo(""Name""), arOwner(0), arOwner(1))" & ControlChars.CrLf)

sbCode.Append(" Trace.WriteLine(strOut)" & ControlChars.CrLf)

sbCode.Append("Next" & ControlChars.CrLf)

objTab.ToolBoxItems.Add("ProcessOwner", sbCode.ToString,
vsToolBoxItemFormat.vsToolBoxItemFormatText)

sbCode = New System.Text.StringBuilder

sbCode.Append("' Add a Reference to System.Management" & ControlChars.CrLf)

sbCode.Append("Dim moReturn As Management.ManagementObjectCollection" &
ControlChars.CrLf)

sbCode.Append("Dim moSearch As Management.ManagementObjectSearcher" &
ControlChars.CrLf)

sbCode.Append("Dim mo As Management.ManagementObject" & ControlChars.CrLf)

sbCode.Append("" & ControlChars.CrLf)

sbCode.Append("moSearch = New Management.ManagementObjectSearcher(""Select *
from Win32_Processor"")" & ControlChars.CrLf)

sbCode.Append("moReturn = moSearch.Get" & ControlChars.CrLf)

sbCode.Append("For Each mo In moReturn" & ControlChars.CrLf)

sbCode.Append(" Dim strOut As String" & ControlChars.CrLf)

sbCode.Append(" strOut = String.Format(""{0} - ID {1}"", mo(""Name""),
mo(""ProcessorID""))" & ControlChars.CrLf)

sbCode.Append(" Trace.WriteLine(strOut)" & ControlChars.CrLf)

sbCode.Append("Next" & ControlChars.CrLf)

objTab.ToolBoxItems.Add("Processor", sbCode.ToString,
vsToolBoxItemFormat.vsToolBoxItemFormatText)

' Add a Reference to System.Management

Dim moReturn As Management.ManagementObjectCollection

Dim moSearch As Management.ManagementObjectSearcher

Dim mo As Management.ManagementObject

moSearch = New Management.ManagementObjectSearcher("Select * from
Win32_Group")

moReturn = moSearch.Get

For Each mo In moReturn

Trace.WriteLine(mo("Name"))

Next

End Sub

End Module



Ken

------------------------

I've seen how people have snippets of code stored over by the tool box and
then can drag them into a code page. What do you call this and what's a
reference on how to do this?

Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top