Is there any way to prevent the addition of an extra line below a multi-line snippet in VB.NET?
(hit tab key to expand snippet...)
I've double checked that the snippet itself does not have an extra line at the end. Also, this seems to be VB-specific.
Just close the ]] after the end of your snipped. The ¿end¿ part sets the caret at this position after inserting the snipped.
<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets
xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
</SnippetTypes>
<Title>tryt</Title>
<Author>[USERNAME]</Author>
<Description>
</Description>
<HelpUrl>
</HelpUrl>
<Shortcut>tryt</Shortcut>
</Header>
<Snippet>
<Code Language="vb" Delimiter="¿"><![CDATA[Try
¿end¿
Catch ex As Exception
Throw New Exception(ex) 'or do some other stuff
End Try]]></Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>
Related
Get error:
Cannot implicitly convert type 'string' to 'int'
on this code:
<TotalInvoiceCost>
<xsl:value-of select="sum(//*[local-name()='InvoiceTotal'])" />
</TotalInvoiceCost>
Then tried this:
<TotalInvoiceCost>
<xsl:value-of select="sum(number(//*[local-name()='InvoiceTotal']))" />
</TotalInvoiceCost>
but get this error:
Argument 1 of function 'sum()' cannot be converted to a node-set.
Cut Down Sample Data with Structure (all values are numeric):
<TAR210 xmlns="demo">
<DummyHeaderGroup xmlns=""/>
<Invoice xmlns="">
<Level1>
<InvoiceTotal>1075</InvoiceTotal>
</Level1>
<Level1>
<InvoiceTotal>595</InvoiceTotal>
</Level1>
</Invoice>
</TAR210>
In http://www.xpathtester.com/xpath, this works fine:
sum(//*[local-name()="InvoiceTotal"])
Example of XSLT in context:
<?xml version="1.0" encoding="utf-16"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:var="http://schemas.microsoft.com/BizTalk/2003/var"
exclude-result-prefixes="msxsl var userCSharp" version="1.0"
xmlns:ns0="demo"
xmlns:userCSharp="http://schemas.microsoft.com/BizTalk/2003/userCSharp">
<xsl:output omit-xml-declaration="yes" method="xml" version="1.0" />
<xsl:template match="/">
<ns0:TAR210>
<DummyHeaderGroup>
<Level0>
<TotalInvoiceCost>
<xsl:value-of select="sum(//*[local-name()='InvoiceTotal'])" />
</TotalInvoiceCost>
</Level0>
</DummyHeaderGroup>
</ns0:TAR210>
</xsl:template>
</xsl:stylesheet>
Well, the real world program is typically more complex than what we post on the web when we have a problem; I tried to simplify. The error had nothing to do with the code I posted.
To me, it seems like the biggest issue is that the error from the "Test Map" in Visual Studio doesn't give any hint to the line number with the error.
<Level0>
<BatchNumberLeaveBlank></BatchNumberLeaveBlank>
<InvoiceSendDateCCYYMM>
<!-- Get current CCYYMM -->
<!-- Current-DateTime doesn't exist in XSLT 1.0, had to use C#
<xsl:value-of select="concat(substring(current-dateTime(),1,4),substring(current-dateTime(),6,2))"/>
-->
<xsl:value-of select="userCSharp:GetDateCCYYMM()"/>
</InvoiceSendDateCCYYMM>
<DefaultValueN>N</DefaultValueN>
<TotalInvoiceCost>...
Then I had the C# code below:
<msxsl:script language="C#" implements-prefix="userCSharp">
<![CDATA[ int lineCount = 0;
public int GetDateCCYYMM()
{
return DateTime.Now.ToString("yyyyMMdd");
}
]]>
</msxsl:script>
Obviously, the "public int" should have been "public string" above.
The only way I know how to tackle these problems is the "divide and conquer" method.
I made a copy of the XSLT, named it same with _Debug.xslt, changed the BizTalk map to use it instead, and started ripping out lines of code left and right until the error goes away. Even removing the call to the c# didn't remove the error, so it must have been running a .NET compile or syntax check on the code.
Assuming I want to create a code snippet for ToString(), I have created the following snippet:
<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets
xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>To String VB</Title>
<Author>John Doe</Author>
<Description>Shortcut for ToString()</Description>
<Shortcut>ts</Shortcut>
</Header>
<Snippet>
<Code Language="VB">
<![CDATA[toString()]]>
</Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>
When I write the code myObject.ts and then press tab to invoke the code snippet, visual studio does this:
myObject.
toString()
instead of this:
myObject.toString()
How can I keep the snippet completion on the same line that I invoked it from? I came across a page that mentioned using $end$ to mark the position the cursor should go when the snippet is inserted, but that has done nothing for me besides including the $end$ in the snippet.
I am trying to add a new tab to an actionscript TabBar control at runtime. When I use addChild() to add a tab to the tab bar I get an exception at runtime:
Error: addChild() is not available in this class. Instead, use addElement() or modify the skin, if you have one.
However, when I tried using addElement() instead I get an error at compile time:
1061: Call to a possibly undefined method addElement through a reference with static type spark.components:TabBar.
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
width="100%"
height="100%">
<fx:Script>
<![CDATA[
import mx.events.FlexEvent;
private var _lastAddedNumber:int = 1;
protected function btnAddNewTab_clickHandler(event:MouseEvent):void
{
tabby.dataProvider.addItem('New '+_lastAddedNumber);
_lastAddedNumber++;
}
]]>
</fx:Script>
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<mx:Button id="btnSave"
click="btnAddNewTab_clickHandler(event)"
label="Add New Tab"/>
<mx:Form top="50">
<mx:FormItem label="tabWidth:">
<s:HSlider id="slider"
minimum="40"
maximum="120"
value="100"/>
</mx:FormItem>
</mx:Form>
<s:TabBar id="tabby"
horizontalCenter="0"
verticalCenter="0">
<s:layout>
<s:HorizontalLayout gap="-1"
columnWidth="{slider.value}"
variableColumnWidth="false"/>
</s:layout>
<s:dataProvider>
<s:ArrayList source="[red,orange,yellow,green,blue]"/>
</s:dataProvider>
</s:TabBar></s:Application>
may this will help you!!!
Below is my SQL snippet that is used to surround existing SQL. After highlighting some SQL and inserting this snippet, I want ALL the selected text to be indented by a tab or several spaces. My snippet currently will indent just the first line of highlighted code.
How can I make is indent all the selected text?
Here is my SQL snippet.
<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>Insert a comment header for SQL</Title>
<Shortcut>header</Shortcut>
<Description>SQL Snippet will add comment area for header to break up code</Description>
<Author>Mike Adams</Author>
<SnippetTypes>
<SnippetType>SurroundsWith</SnippetType>
<SnippetType>Expansion</SnippetType>
</SnippetTypes>
</Header>
<Snippet>
<Declarations>
<Literal Editable="true">
<ID>headerText</ID>
<ToolTip>Header Text</ToolTip>
<Default></Default>
<Function></Function>
</Literal>
</Declarations>
<Code Language="sql">
<![CDATA[
-- $headerText$
---------------------------------------------------------
$selected$
$end$
]]>
</Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>
In Visual Studio 2010, for VB.NET, the "Property" + Tab + Tab inserts a full property implementation. Is there another snippet for inserting an autoproperty?
Just put this in a file called C:\Users\\Documents\Visual Studio 2010\Code Snippets\Visual Basic\My Code Snippets\DefaultProperty.snippet and restart VS... or put it in that file but not in that dir, then in VS click Tools, Code Snippets Manager, and Select Visual Basic as the language... the click on the Import button. Select your new file, and then choose the top folder "My Snippets". Now in the IDE just type PropDefAuto and tab tab. Feel free to modify the file.
<?xml version="1.0" encoding="UTF-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>Define a Auto-Implemented Default Property</Title>
<Author>Some Guy On SO</Author>
<Description>Defines an Auto-Implemented default property or index property.</Description>
<Keywords>
<Keyword>PropAuto</Keyword>
</Keywords>
<Shortcut>PropDefAuto</Shortcut>
</Header>
<Snippet>
<Imports>
<Import>
<Namespace>System</Namespace>
</Import>
</Imports>
<Declarations>
<Literal>
<ID>propertyName</ID>
<Type>
</Type>
<ToolTip>Rename to descriptive name for the property.</ToolTip>
<Default>PropertyName</Default>
</Literal>
<Literal>
<ID>indexType</ID>
<Type>
</Type>
<ToolTip>Replace with the type of the index</ToolTip>
<Default>Integer</Default>
</Literal>
<Literal>
<ID>propertyType</ID>
<Type>
</Type>
<ToolTip>Replace with the type returned by the property.</ToolTip>
<Default>String</Default>
</Literal>
<Literal>
<ID>IndexIsValid</ID>
<Type>Boolean</Type>
<ToolTip>Replace with an expression to test if index is valid.</ToolTip>
<Default>True</Default>
</Literal>
</Declarations>
<Code Language="VB" Kind="method decl"><![CDATA[Public Property $propertyName$ As $PropertyType$
]]></Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>
The closest you can currently get in VB is typing out
Property Name as string
You can find more information in this blog post by The Gu