<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>WinSoft.se &#187; Visual Basic 10</title>
	<atom:link href="http://www.winsoft.se/category/dotnet/visualbasic10/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.winsoft.se</link>
	<description>Development with focus on Visual Basic .NET</description>
	<lastBuildDate>Thu, 26 Jan 2012 19:28:40 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Stealing keys</title>
		<link>http://www.winsoft.se/2011/08/stealing-keys/</link>
		<comments>http://www.winsoft.se/2011/08/stealing-keys/#comments</comments>
		<pubDate>Thu, 25 Aug 2011 18:37:36 +0000</pubDate>
		<dc:creator>Anders Hesselbom</dc:creator>
				<category><![CDATA[Visual Basic 10]]></category>

		<guid isPermaLink="false">http://www.winsoft.se/?p=1760</guid>
		<description><![CDATA[Events and everything you might need to develop a user control, will tell you about mouse and keyboard activity so that you can respond the user correctly. If you want to be able to catch arrow keys or tab, you must overload this function: Protected Overrides Function ProcessCmdKey(ByRef msg As System.Windows.Forms.Message, ByVal keyData As System.Windows.Forms.Keys) [...]]]></description>
			<content:encoded><![CDATA[<p>Events and everything you might need to develop a user control, will tell you about mouse and keyboard activity so that you can respond the user correctly. If you want to be able to catch arrow keys or tab, you must overload this function:</p>
<pre>Protected Overrides Function ProcessCmdKey(ByRef msg
   As System.Windows.Forms.Message, ByVal keyData
   As System.Windows.Forms.Keys) As Boolean</pre>
<p>This method gets called no matter what key is pressed. Also, if you act on the key, and don&#8217;t want the original functionality, make the function return True. If you want the framework to act on the key press, make the function return False.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.winsoft.se/2011/08/stealing-keys/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Extension methods in Visual Basic</title>
		<link>http://www.winsoft.se/2011/06/extension-methods-in-visual-basic/</link>
		<comments>http://www.winsoft.se/2011/06/extension-methods-in-visual-basic/#comments</comments>
		<pubDate>Thu, 02 Jun 2011 15:56:24 +0000</pubDate>
		<dc:creator>Anders Hesselbom</dc:creator>
				<category><![CDATA[Visual Basic 10]]></category>

		<guid isPermaLink="false">http://www.winsoft.se/?p=1686</guid>
		<description><![CDATA[Extension methods is a well known concept in C#. The idea is that you can add methods to a type without inheritance, as described here. Visual Basic doesn&#8217;t have any linguistic support for extension methods, but it can be done thanks to a method attribute. There are some rules for doing this. You must declare [...]]]></description>
			<content:encoded><![CDATA[<p>Extension methods is a well known concept in C#. The idea is that you can add methods to a type without inheritance, as described <a href="http://msdn.microsoft.com/en-us/library/bb383977.aspx" target="_blank">here</a>.</p>
<p>Visual Basic doesn&#8217;t have any linguistic support for extension methods, but it can be done thanks to a method attribute. There are some rules for doing this. You must declare your sub or function in a <strong>standard module</strong>, not a class. You must have at least one parameter, and that parameter is the type you are extending. Any other parameters will be parameters in your function. Finally, your sub or function must have the <strong>System.Runtime.CompilerServices.Extension</strong> attribute.</p>
<p>So if you want to add a function that takes no parameters to the <strong>Integer</strong> type, you will have to define a function that takes one parameter, an <strong>Integer</strong>. If you want to add a function that takes one parameter, you will have to define a function that takes two parameter, the first must be an <strong>Integer</strong> and the second (who will serve as the first parameter in your function) can be of any type you like.</p>
<pre>Public Function DoubleValue(ByVal I As Integer) As Integer
   Return I * 2
End Function</pre>
<p>Remember, the code must be written in a standard module.</p>
<p>The last thing that you have to do, is to add the attribute.</p>
<pre>&lt;System.Runtime.CompilerServices.Extension()&gt;
Public Function DoubleValue(ByVal I As Integer) As Integer
   Return I * 2
End Function</pre>
<p>(The above code is VBx syntax. For older Visual Basic versions, add a blank followed by an underscore to the attribute line.)</p>
<p>Now you can call the <strong>DoubleValue</strong> function from any <strong>Integer</strong>, in this case <strong>5</strong>:</p>
<pre>Console.WriteLine(5.DoubleValue())</pre>
<p>The output will of course be <strong>10</strong>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.winsoft.se/2011/06/extension-methods-in-visual-basic/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Visual Basic: Importing namespaces</title>
		<link>http://www.winsoft.se/2011/05/visual-basic-importing-namespaces/</link>
		<comments>http://www.winsoft.se/2011/05/visual-basic-importing-namespaces/#comments</comments>
		<pubDate>Sat, 07 May 2011 09:18:32 +0000</pubDate>
		<dc:creator>Anders Hesselbom</dc:creator>
				<category><![CDATA[Visual Basic 10]]></category>

		<guid isPermaLink="false">http://www.winsoft.se/?p=1669</guid>
		<description><![CDATA[In C# you can use the using directive to import the classes in a given namespace to your current scope. If you want to use the classes in System.Data.SqlClient, you could refer to them using their full path, like so: var r = new System.Data.SqlClient.SqlDataAdapter(); You can add namespaces to your scope by adding a [...]]]></description>
			<content:encoded><![CDATA[<p>In C# you can use the <strong>using</strong> directive to import the classes in a given namespace to your current scope. If you want to use the classes in <strong>System.Data.SqlClient</strong>, you could refer to them using their full path, like so:</p>
<pre>var r = new System.Data.SqlClient.SqlDataAdapter();</pre>
<p>You can add namespaces to your scope by adding a using directive in the beginning of your source file. If you add this directive:</p>
<pre>using System.Data.SqlClient;</pre>
<p>You could then access the <strong>SqlDataAdapter</strong> class in your code, without typing the full path, like so:</p>
<pre>var r = new SqlDataAdapter();</pre>
<p>Visual Basic does not have the using directive, but it has a more powerful directive called <strong>Imports</strong>. <strong>Imports</strong> can import both classes and other namespaces. The code that creates a <strong>SqlDataAdapter</strong> in Visual Basic looks like this:</p>
<pre>Dim R As New System.Data.SqlClient.SqlDataAdapter()</pre>
<p>If you use the <strong>Imports</strong> directive to import <strong>System.Data</strong> in the beginning of your file, like so:</p>
<pre>Imports System.Data</pre>
<p>You can access both the namespaces (like <strong>SqlClient</strong>) and the classes in <strong>System.Data</strong> without providing the full path.</p>
<pre>Dim R As New SqlClient.SqlDataAdapter()</pre>
<p>If course, you can go on and import the <strong>SqlClient</strong> namespace to access the <strong>SqlDataAdapter</strong> class without specifying it&#8217;s full path, just as you can do in C#. So, the <strong>using</strong> directive in C# can import classes, but the <strong>Imports</strong> directive in VB imports both classes and namespaces.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.winsoft.se/2011/05/visual-basic-importing-namespaces/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A multithreaded sockets server, just a few lines of code</title>
		<link>http://www.winsoft.se/2011/04/a-multithreaded-sockets-server-just-a-few-lines-of-code/</link>
		<comments>http://www.winsoft.se/2011/04/a-multithreaded-sockets-server-just-a-few-lines-of-code/#comments</comments>
		<pubDate>Sun, 24 Apr 2011 16:22:08 +0000</pubDate>
		<dc:creator>Anders Hesselbom</dc:creator>
				<category><![CDATA[Visual Basic 10]]></category>
		<category><![CDATA[Sockets]]></category>

		<guid isPermaLink="false">http://www.winsoft.se/?p=1664</guid>
		<description><![CDATA[This small piece of Visual Basic code (VBx) shows how you can do a multithreaded sockets server in just a few lines of code. I write all of this code in a console application. The main module will only hold an implementation of the Main function. Like so: Module Module1 Sub Main() Dim L As [...]]]></description>
			<content:encoded><![CDATA[<p>This small piece of Visual Basic code (VBx) shows how you can do a multithreaded sockets server in just a few lines of code. I write all of this code in a console application. The main module will only hold an implementation of the <strong>Main</strong> function. Like so:</p>
<p><!-- code formatted by http://manoli.net/csharpformat/ --></p>
<pre class="csharpcode">
<span class="kwrd">Module</span> Module1

    <span class="kwrd">Sub</span> Main()
      <span class="kwrd">Dim</span> L <span class="kwrd">As</span> <span class="kwrd">New</span> System.Net.Sockets.TcpListener(
         <span class="kwrd">New</span> System.Net.IPAddress({192, 168, 1, 100}), 80)
      L.Start()
      <span class="kwrd">Dim</span> ThreadCounter = 0
      <span class="kwrd">Do</span>
         ThreadCounter += 1
         <span class="kwrd">Dim</span> C = L.AcceptTcpClient()
         <span class="kwrd">Dim</span> S <span class="kwrd">As</span> <span class="kwrd">New</span> NetSession(C, ThreadCounter)
         <span class="kwrd">Dim</span> T <span class="kwrd">As</span> <span class="kwrd">New</span> Threading.Thread(<span class="kwrd">AddressOf</span> S.SessionLoop)
         Console.WriteLine(<span class="str">"Starting thread "</span> &amp; ThreadCounter.ToString() &amp; <span class="str">"."</span>)
         T.Start()
      <span class="kwrd">Loop</span>
    <span class="kwrd">End</span> <span class="kwrd">Sub</span>

<span class="kwrd">End</span> Module</pre>
<p>Note that I have hard coded my local IP address, and passed it as an argument to the <strong>TcpListener</strong> constructor, but there are easy ways collect this information using the .NET Framework. The variable C is a <strong>System.Net.Sockets.TcpClient</strong>, because that is what the <strong>AcceptTcpClient</strong> function returns. The <strong>ThreadCounter</strong> is just so that different connections will get a unique session identifier.</p>
<p>The rest of the code takes place in the <strong>NetSession</strong> class.</p>
<p><!-- code formatted by http://manoli.net/csharpformat/ --></p>
<pre class="csharpcode">
<span class="kwrd">Public</span> <span class="kwrd">Class</span> NetSession

   <span class="kwrd">Private</span> mC <span class="kwrd">As</span> System.Net.Sockets.TcpClient
   <span class="kwrd">Private</span> mS <span class="kwrd">As</span> System.Net.Sockets.NetworkStream
   <span class="kwrd">Private</span> mThreadCounter <span class="kwrd">As</span> <span class="kwrd">Integer</span>
   <span class="kwrd">Private</span> mIndex <span class="kwrd">As</span> <span class="kwrd">String</span>

   <span class="kwrd">Public</span> <span class="kwrd">Sub</span> <span class="kwrd">New</span>(<span class="kwrd">ByVal</span> C <span class="kwrd">As</span> System.Net.Sockets.TcpClient,
         <span class="kwrd">ByVal</span> ThreadCounter <span class="kwrd">As</span> <span class="kwrd">Integer</span>)
      <span class="kwrd">Me</span>.mC = C
      <span class="kwrd">Me</span>.mThreadCounter = ThreadCounter
      <span class="kwrd">Me</span>.mIndex = <span class="str">""</span>
   <span class="kwrd">End</span> <span class="kwrd">Sub</span>

   <span class="kwrd">Public</span> <span class="kwrd">Sub</span> SessionLoop()
      <span class="kwrd">Me</span>.mS = <span class="kwrd">Me</span>.mC.GetStream()
      <span class="kwrd">Me</span>.mC.LingerState.Enabled = <span class="kwrd">False</span>
      <span class="kwrd">Me</span>.WriteLine(<span class="str">"Connected."</span>)
      <span class="kwrd">While</span> <span class="kwrd">Me</span>.mC.Connected
         <span class="kwrd">If</span> <span class="kwrd">Me</span>.mS.DataAvailable <span class="kwrd">Then</span>
            <span class="kwrd">Dim</span> GotData <span class="kwrd">As</span> <span class="kwrd">New</span> System.Text.StringBuilder()
            <span class="kwrd">While</span> <span class="kwrd">Me</span>.mS.DataAvailable
               <span class="kwrd">Dim</span> bytes(<span class="kwrd">Me</span>.mC.ReceiveBufferSize - 1) <span class="kwrd">As</span> <span class="kwrd">Byte</span>
               <span class="kwrd">Dim</span> Len = <span class="kwrd">Me</span>.mS.Read(bytes, 0, <span class="kwrd">Me</span>.mC.ReceiveBufferSize)
               <span class="kwrd">If</span> Len &gt; 0 <span class="kwrd">Then</span>
                  GotData.Append(System.Text.Encoding.UTF8.GetString(bytes, 0, Len))
               <span class="kwrd">End</span> <span class="kwrd">If</span>
            <span class="kwrd">End</span> <span class="kwrd">While</span>
            <span class="kwrd">Dim</span> D = GotData.ToString().Trim()
            <span class="kwrd">If</span> <span class="kwrd">Not</span> D = <span class="str">""</span> <span class="kwrd">Then</span>
               <span class="kwrd">If</span> <span class="kwrd">Not</span> <span class="kwrd">Me</span>.Handle(D) <span class="kwrd">Then</span>
                  <span class="kwrd">Exit</span> <span class="kwrd">While</span>
               <span class="kwrd">End</span> <span class="kwrd">If</span>
            <span class="kwrd">End</span> <span class="kwrd">If</span>
         <span class="kwrd">End</span> <span class="kwrd">If</span>
      <span class="kwrd">End</span> <span class="kwrd">While</span>
      <span class="kwrd">Me</span>.mS.Close()
      <span class="kwrd">Me</span>.mS.Dispose()
      <span class="kwrd">Me</span>.mC.Close()
      Console.WriteLine(<span class="str">"Thread "</span> &amp; <span class="kwrd">Me</span>.mThreadCounter.ToString() &amp; <span class="str">" is closing."</span>)
   <span class="kwrd">End</span> <span class="kwrd">Sub</span>

   <span class="kwrd">Private</span> <span class="kwrd">Sub</span> WriteLine(<span class="kwrd">ByVal</span> T <span class="kwrd">As</span> <span class="kwrd">String</span>)
      <span class="kwrd">Dim</span> Bytes() <span class="kwrd">As</span> <span class="kwrd">Byte</span> = System.Text.Encoding.UTF8.GetBytes(T &amp; ControlChars.CrLf)
      <span class="kwrd">Me</span>.mS.Write(Bytes, 0, Bytes.Count)
   <span class="kwrd">End</span> <span class="kwrd">Sub</span>

   <span class="kwrd">Private</span> <span class="kwrd">Function</span> Handle(<span class="kwrd">ByVal</span> D <span class="kwrd">As</span> <span class="kwrd">String</span>) <span class="kwrd">As</span> <span class="kwrd">Boolean</span>
      Console.WriteLine(<span class="str">"Thread "</span> &amp; <span class="kwrd">Me</span>.mThreadCounter.ToString() &amp; <span class="str">": "</span> &amp; D)
      <span class="kwrd">If</span> D.ToLower() = <span class="str">"quit"</span> <span class="kwrd">Then</span>
         <span class="kwrd">Me</span>.WriteLine(<span class="str">"Bye."</span>)
         <span class="kwrd">Return</span> <span class="kwrd">False</span>
      <span class="kwrd">Else</span>

         <span class="rem">'Do parsing here! Return True no matter what.</span>
         <span class="kwrd">Me</span>.WriteLine(<span class="str">"Thanks!"</span>)

         <span class="kwrd">Return</span> <span class="kwrd">True</span>
      <span class="kwrd">End</span> <span class="kwrd">If</span>
   <span class="kwrd">End</span> <span class="kwrd">Function</span>

<span class="kwrd">End</span> Class</pre>
<p>The constructor accepts the TCP client (representing the connected application) and the ThreadCounter variable. The <strong>SessionLoop</strong> function is the main loop for each thread.</p>
<p>The <strong>WriteLine</strong> function sends responses to the connected client application and the Handle function is the place where you implement your parsing (or invokes some existing parser). Note that the <strong>Handle</strong> function must return <strong>True</strong>, even if your parsing fails. Failed parsing should render in an error message to the client application, but the function should still return <strong>True</strong>. The returning of the value <strong>False</strong>, is a signal that the client disconnects.</p>
<p>When you run this code, you will get a warning from your Windows Firewall (I run a Swedish Windows 7 installation). Accept that this program can use your local network.</p>
<p><img alt="" src="http://imghost.winsoft.se/upload/530781303660102warning.jpg" class="aligncenter" width="406" height="290" /></p>
<p>To make this program actually do something, start a sockets client, like PuTTY. Configure it like so:</p>
<p>Host IP: [Your local IP]<br />
Port: 80<br />
Encoding: UTF-8</p>
<p>Note that we use UTF-8 encoding to convert between byte arrays and strings in the source code, so the TCP client must also use UTF-8.</p>
<p><img alt="" src="http://imghost.winsoft.se/upload/653421303661718clients.jpg" class="aligncenter" width="381" height="286" /></p>
<p>Since our server is multithreaded and have multiple connection awareness, you can connect more than one sockets client to your application.</p>
<p>Send <strong>Quit</strong> from your client application to quit.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.winsoft.se/2011/04/a-multithreaded-sockets-server-just-a-few-lines-of-code/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Environment variables</title>
		<link>http://www.winsoft.se/2011/02/environment-variables/</link>
		<comments>http://www.winsoft.se/2011/02/environment-variables/#comments</comments>
		<pubDate>Sun, 13 Feb 2011 21:52:28 +0000</pubDate>
		<dc:creator>Anders Hesselbom</dc:creator>
				<category><![CDATA[Visual Basic 10]]></category>

		<guid isPermaLink="false">http://www.winsoft.se/?p=1584</guid>
		<description><![CDATA[Assuming that you are running Windows 7, the environment variables can be manually accessed if you right click on Computer, and select Properties. From there, you click Advanced system settings and on the Advanced tab, you click the Environment variables button. You can check your current variables, edit them and add new variables. I am [...]]]></description>
			<content:encoded><![CDATA[<p>Assuming that you are running Windows 7, the environment variables can be manually accessed if you right click on Computer, and select Properties. From there, you click Advanced system settings and on the Advanced tab, you click the Environment variables button. You can check your current variables, edit them and add new variables.</p>
<p>I am running a Swedish installation of Windows 7.</p>
<p><img alt="" src="http://imghost.winsoft.se/upload/770221297633932variables.jpg" class="aligncenter" width="394" height="436" /></p>
<p>To read them from Visual Basic, you just use the <strong>GetEnvironmentVariables</strong> function to retrieve the collection of registered variables. This example is written in VBx (Visual Basic 10):</p>
<pre>Console.WriteLine(
   Environment.GetEnvironmentVariables().
      Item("PROCESSOR_REVISION").ToString())</pre>
<p>Remember, when you write code to manipulate this collection, adding or changing values, you would normally want your code to run as a custom step in an MSI file, and not in a regular EXE.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.winsoft.se/2011/02/environment-variables/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Getting started with Silverlight in an existing web application</title>
		<link>http://www.winsoft.se/2010/09/getting-started-with-silverlight-in-an-existing-web-application/</link>
		<comments>http://www.winsoft.se/2010/09/getting-started-with-silverlight-in-an-existing-web-application/#comments</comments>
		<pubDate>Sat, 25 Sep 2010 11:28:48 +0000</pubDate>
		<dc:creator>Anders Hesselbom</dc:creator>
				<category><![CDATA[Visual Basic 10]]></category>
		<category><![CDATA[Visual Studio 10]]></category>
		<category><![CDATA[Silverlight]]></category>

		<guid isPermaLink="false">http://www.winsoft.se/?p=1393</guid>
		<description><![CDATA[To get things started, I will show how to enhance a web application with a Silverlight object, and how to pass parameters to that object. To be able to follow, make sure that you have the Silverlight runtime installed. Also, you must have an existing ASP.NET Web Application loaded in Visual Studio 2010. If you&#8217;re [...]]]></description>
			<content:encoded><![CDATA[<p>To get things started, I will show how to enhance a web application with a Silverlight object, and how to pass parameters to that object. To be able to follow, make sure that you have the Silverlight runtime installed. Also, you must have an existing ASP.NET Web Application loaded in Visual Studio 2010. If you&#8217;re using Visual Studio 2008, there is an Silverlight addon available for download from Microsoft.</p>
<p><strong>Adding a Silverlight object and passing data to it</strong><br />
I want to have a Silverlight object on a sub page, so I add a new ASPX page to my web application called sl.aspx. Also, I create a link to sl.aspx from my default page. I want my Silverlight object to accept a QueryString argument, so I pass one in my link:</p>
<pre>&lt;a href="sl.aspx?param=hello"&gt;Click here!&lt;/a&gt;</pre>
<p>1. Add a new Silverlight project to your solution. I use the name MySL for mine. Default, a test page is added. I unchecked the option to make the test page my start page.</p>
<p>2. The test page is a good help to copy the HTML code that is required to show the object from. The two JavaScript blocks goes in the head section and the OBJECT tag goes where you want your Silverlight object. Grab the DIV tag that contains the OBJECT tag and the IFRAME tag.</p>
<p>Now you&#8217;re done with adding the object. If you test your application, and click on your link, your (empty) Silverlight object.</p>
<p>3. I want to show the QueryString parameter in a textbox, so I add one to my Silverlight object (TextBox1). This is the code to grab the QueryString parameter and putting it in the textbox:</p>
<pre>Private Sub MainPage_Loaded(ByVal sender As Object, _
ByVal e As System.Windows.RoutedEventArgs) Handles Me.Loaded
   TextBox1.Text = _
   System.Windows.Browser.HtmlPage.Document.QueryString("param")
End Sub</pre>
<p>The result of course, is the word &#8220;hello&#8221; in the textbox.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.winsoft.se/2010/09/getting-started-with-silverlight-in-an-existing-web-application/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Big integers in .NET 4.0</title>
		<link>http://www.winsoft.se/2010/01/big-integers-in-net-4-0/</link>
		<comments>http://www.winsoft.se/2010/01/big-integers-in-net-4-0/#comments</comments>
		<pubDate>Wed, 06 Jan 2010 17:29:29 +0000</pubDate>
		<dc:creator>Anders Hesselbom</dc:creator>
				<category><![CDATA[Visual Basic 10]]></category>

		<guid isPermaLink="false">http://www.winsoft.se/?p=856</guid>
		<description><![CDATA[The BigInteger structure becomes available if you add a reference to the System.Numerics namespace. BigInteger represents a positive or negative integer of any size.  This is great for doing arithmetic calculations with very large numbers, and is one of the problems you had to solve on your own in previous versions of .NET Framework. After [...]]]></description>
			<content:encoded><![CDATA[<p>The <strong>BigInteger</strong> structure becomes available if you add a reference to the <strong>System.Numerics</strong> namespace. <strong>BigInteger</strong> represents a positive or negative integer of any size.  This is great for doing arithmetic calculations with very large numbers, and is one of the problems you had to solve on your own in previous versions of .NET Framework.</p>
<p>After the reference is added, you can create a <strong>BigInteger</strong> using the <strong>New</strong> keyword, and an initial value can be passed to the constructor, like so:</p>
<pre>Dim X As New System.Numerics.BigInteger(Long.MaxValue)
Console.WriteLine(X.ToString())</pre>
<p>To do arithmetic operations, create the <strong>BigInteger</strong>s you need for the operation, and then call the <em>static (shared)</em> functions of the <strong>BigInteger</strong> structure to do the calculations. In this case, I call the static function <strong>Multiply</strong>.</p>
<pre>Dim X As New System.Numerics.BigInteger(Long.MaxValue)
Dim Y As New System.Numerics.BigInteger(Long.MaxValue)
Dim Z As System.Numerics.BigInteger = _
     System.Numerics.BigInteger.Multiply(X, Y)
Console.WriteLine(Z.ToString())</pre>
<p>Just by adding a few of these lines to the above code, will give you one insanely large number.</p>
<pre>Z = System.Numerics.BigInteger.Multiply(Z, Z)
Z = System.Numerics.BigInteger.Multiply(Z, Z)
Z = System.Numerics.BigInteger.Multiply(Z, Z)
Z = System.Numerics.BigInteger.Multiply(Z, Z)</pre>
<p>One way to serialize this number in SQL Server could be to store the underlying bytes of the number that the <strong>BigInteger</strong> instance represents. The <strong>BigInteger</strong> structure has a member function that returns these bytes as a byte array called <strong>GetByteArray</strong>. An existing byte array can be passed to the constructor of the <strong>BigInteger</strong> to reconstruct the number.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.winsoft.se/2010/01/big-integers-in-net-4-0/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hardware accelerated graphics through XNA: Getting started</title>
		<link>http://www.winsoft.se/2010/01/hardware-accelerated-graphics-through-xna-getting-started/</link>
		<comments>http://www.winsoft.se/2010/01/hardware-accelerated-graphics-through-xna-getting-started/#comments</comments>
		<pubDate>Sat, 02 Jan 2010 23:45:26 +0000</pubDate>
		<dc:creator>Anders Hesselbom</dc:creator>
				<category><![CDATA[Visual Basic 10]]></category>
		<category><![CDATA[Visual Studio 10]]></category>
		<category><![CDATA[Game development]]></category>

		<guid isPermaLink="false">http://www.winsoft.se/?p=832</guid>
		<description><![CDATA[There are some features of the XNA Framework that is unavailable from Visual Basic, but this should not stop you from writing descent games in Visual Basic. On my machine, I have installed XNA Game Studio 3.1 (a game developing environment from Microsoft) and I also have a beta of Visual Studio 2010 that I [...]]]></description>
			<content:encoded><![CDATA[<p>There are some features of the XNA Framework that is unavailable from Visual Basic, but this should not stop you from writing descent games in Visual Basic. On my machine, I have installed <a href="http://www.microsoft.com/downloads/details.aspx?displaylang=en&#038;FamilyID=80782277-d584-42d2-8024-893fcd9d3e82" target="_blank">XNA Game Studio 3.1</a> (a game developing environment from Microsoft) and I also have a beta of Visual Studio 2010 that I am going to use. This example will just contain the code necessary to get something on the screen, a sprite floating across.</p>
<p>From VS2010, I am using a regular console application and the target platform for the project is .NET Framework 3.5.</p>
<p>Now I must add two references: <strong>Microsoft.Xna.Framework</strong> and <strong>Microsoft.Xna.Framework.Game</strong>. I use version 3.1, the version that got installed when I installed XNA Game Studio 3.1.</p>
<p>The next step is to create the game class. I call my class <strong>TestGame</strong>. <strong>TestGame</strong> should inherit from the <strong>Microsoft.Xna.Framework.Game</strong> class. In here I create a <strong>Main</strong> method to get the program started, and I select that method to be the starting point for the program in the Project Settings window. This is the code so far:</p>
<pre class="csharpcode">
<span class="kwrd">Public</span> <span class="kwrd">Class</span> TestGame
    <span class="kwrd">Inherits</span> Microsoft.Xna.Framework.Game

    <span class="kwrd">Public</span> <span class="kwrd">Shared</span> <span class="kwrd">Sub</span> Main()

    <span class="kwrd">End</span> <span class="kwrd">Sub</span>

<span class="kwrd">End</span> Class</pre>
<p>In the <strong>Main</strong> method, I create my game (the <strong>TestGame</strong> class) and from the constructor, a graphics device manager for the game. I use the graphics device manager to set my preferred resolution (800&#215;600) and to switch to fullscreen mode. Note that I want to keep the reference to the graphics device manager as a member of my game class.</p>
<pre class="csharpcode">
<span class="kwrd">Public</span> <span class="kwrd">Class</span> TestGame
    <span class="kwrd">Inherits</span> Microsoft.Xna.Framework.Game

    <span class="kwrd">Private</span> Gfx <span class="kwrd">As</span> Microsoft.Xna.Framework.GraphicsDeviceManager

    <span class="kwrd">Public</span> <span class="kwrd">Shared</span> <span class="kwrd">Sub</span> Main()
        <span class="kwrd">Dim</span> Game <span class="kwrd">As</span> <span class="kwrd">New</span> TestGame()
        Game.Run()
    <span class="kwrd">End</span> <span class="kwrd">Sub</span>

    <span class="kwrd">Public</span> <span class="kwrd">Sub</span> <span class="kwrd">New</span>()
        <span class="kwrd">Me</span>.Gfx = <span class="kwrd">New</span> Microsoft.Xna.Framework.GraphicsDeviceManager(<span class="kwrd">Me</span>)
        <span class="kwrd">Me</span>.Gfx.PreferredBackBufferWidth = 800
        <span class="kwrd">Me</span>.Gfx.PreferredBackBufferHeight = 600
        <span class="kwrd">If</span> <span class="kwrd">Not</span> <span class="kwrd">Me</span>.Gfx.IsFullScreen <span class="kwrd">Then</span>
            <span class="kwrd">Me</span>.Gfx.ToggleFullScreen()
        <span class="kwrd">End</span> <span class="kwrd">If</span>
    <span class="kwrd">End</span> <span class="kwrd">Sub</span>

<span class="kwrd">End</span> Class</pre>
<p>The next thing to do is some overrides from the base class. These methods will be overloaded:</p>
<pre class="csharpcode">
<span class="kwrd">Protected</span> <span class="kwrd">Overrides</span> <span class="kwrd">Sub</span> Initialize()
    <span class="kwrd">MyBase</span>.Initialize()
<span class="kwrd">End</span> <span class="kwrd">Sub</span>

<span class="kwrd">Protected</span> <span class="kwrd">Overrides</span> <span class="kwrd">Sub</span> LoadContent()
    <span class="kwrd">MyBase</span>.LoadContent()
<span class="kwrd">End</span> <span class="kwrd">Sub</span>

<span class="kwrd">Protected</span> <span class="kwrd">Overrides</span> <span class="kwrd">Sub</span> UnloadContent()
    <span class="kwrd">MyBase</span>.UnloadContent()
<span class="kwrd">End</span> <span class="kwrd">Sub</span>

<span class="kwrd">Protected</span> <span class="kwrd">Overrides</span> <span class="kwrd">Sub</span> Update(<span class="kwrd">ByVal</span> gameTime <span class="kwrd">As</span> Microsoft.Xna.Framework.GameTime)
    <span class="kwrd">MyBase</span>.Update(gameTime)
<span class="kwrd">End</span> <span class="kwrd">Sub</span>

<span class="kwrd">Protected</span> <span class="kwrd">Overrides</span> <span class="kwrd">Sub</span> Draw(<span class="kwrd">ByVal</span> gameTime <span class="kwrd">As</span> Microsoft.Xna.Framework.GameTime)
    <span class="kwrd">MyBase</span>.Draw(gameTime)
<span class="kwrd">End</span> Sub</pre>
<p>Just to make something happen on the screen, I am adding these members:</p>
<pre class="csharpcode">
<span class="kwrd">Private</span> Sb <span class="kwrd">As</span> Microsoft.Xna.Framework.Graphics.SpriteBatch
<span class="kwrd">Private</span> SpriteTexture <span class="kwrd">As</span> Microsoft.Xna.Framework.Graphics.Texture2D
<span class="kwrd">Private</span> SpriteX <span class="kwrd">As</span> <span class="kwrd">Integer</span> = 0
<span class="kwrd">Private</span> SpriteY <span class="kwrd">As</span> <span class="kwrd">Integer</span> = 0</pre>
<p>The <strong>SpriteBatch</strong> will manage my sprites and the <strong>Texture2D</strong> is the sprite graphics. In the LoadContent function, I will load a sprite from my hard drive.</p>
<pre class="csharpcode">
<span class="kwrd">Protected</span> <span class="kwrd">Overrides</span> <span class="kwrd">Sub</span> LoadContent()
    <span class="kwrd">Me</span>.Sb = <span class="kwrd">New</span> Microsoft.Xna.Framework.Graphics.SpriteBatch(<span class="kwrd">Me</span>.Gfx.GraphicsDevice)
    <span class="kwrd">Me</span>.SpriteTexture = Microsoft.Xna.Framework.Graphics.Texture2D.FromFile(<span class="kwrd">Me</span>.Gfx.GraphicsDevice, _
         <span class="str">"mysprite.png"</span>)
    <span class="kwrd">MyBase</span>.LoadContent()
<span class="kwrd">End</span> Sub</pre>
<p>The <strong>Update</strong> function is for changing the game scenery.</p>
<pre class="csharpcode">
<span class="kwrd">Protected</span> <span class="kwrd">Overrides</span> <span class="kwrd">Sub</span> Update(<span class="kwrd">ByVal</span> gameTime <span class="kwrd">As</span> Microsoft.Xna.Framework.GameTime)
    SpriteX += 1
    SpriteY += 1
    <span class="kwrd">MyBase</span>.Update(gameTime)
<span class="kwrd">End</span> Sub</pre>
<p>And the <strong>Draw</strong> function is for screen rendering.</p>
<pre class="csharpcode">
<span class="kwrd">Protected</span> <span class="kwrd">Overrides</span> <span class="kwrd">Sub</span> Draw(<span class="kwrd">ByVal</span> gameTime <span class="kwrd">As</span> Microsoft.Xna.Framework.GameTime)
    <span class="kwrd">Me</span>.Gfx.GraphicsDevice.Clear(Microsoft.Xna.Framework.Graphics.Color.Black)
    <span class="kwrd">Me</span>.Sb.Begin(Microsoft.Xna.Framework.Graphics.SpriteBlendMode.AlphaBlend)
    <span class="kwrd">Me</span>.Sb.Draw(<span class="kwrd">Me</span>.SpriteTexture, <span class="kwrd">New</span> Microsoft.Xna.Framework.Rectangle(<span class="kwrd">Me</span>.SpriteX, <span class="kwrd">Me</span>.SpriteY, 32, 32), _
         Microsoft.Xna.Framework.Graphics.Color.Red)
    <span class="kwrd">Me</span>.Sb.<span class="kwrd">End</span>()
    <span class="kwrd">MyBase</span>.Draw(gameTime)
<span class="kwrd">End</span> Sub</pre>
<p>This is the complete code that produces a sprite that floats over the screen in Visual Basic using XNA:</p>
<pre class="csharpcode">
<span class="kwrd">Public</span> <span class="kwrd">Class</span> TestGame
    <span class="kwrd">Inherits</span> Microsoft.Xna.Framework.Game

    <span class="kwrd">Private</span> Gfx <span class="kwrd">As</span> Microsoft.Xna.Framework.GraphicsDeviceManager

    <span class="kwrd">Private</span> Sb <span class="kwrd">As</span> Microsoft.Xna.Framework.Graphics.SpriteBatch
    <span class="kwrd">Private</span> SpriteTexture <span class="kwrd">As</span> Microsoft.Xna.Framework.Graphics.Texture2D
    <span class="kwrd">Private</span> SpriteX <span class="kwrd">As</span> <span class="kwrd">Integer</span> = 0
    <span class="kwrd">Private</span> SpriteY <span class="kwrd">As</span> <span class="kwrd">Integer</span> = 0

    <span class="kwrd">Public</span> <span class="kwrd">Shared</span> <span class="kwrd">Sub</span> Main()
        <span class="kwrd">Dim</span> Game <span class="kwrd">As</span> <span class="kwrd">New</span> TestGame()
        Game.Run()
    <span class="kwrd">End</span> <span class="kwrd">Sub</span>

    <span class="kwrd">Public</span> <span class="kwrd">Sub</span> <span class="kwrd">New</span>()
        <span class="kwrd">Me</span>.Gfx = <span class="kwrd">New</span> Microsoft.Xna.Framework.GraphicsDeviceManager(<span class="kwrd">Me</span>)
        <span class="kwrd">Me</span>.Gfx.PreferredBackBufferWidth = 800
        <span class="kwrd">Me</span>.Gfx.PreferredBackBufferHeight = 600
        <span class="kwrd">If</span> <span class="kwrd">Not</span> <span class="kwrd">Me</span>.Gfx.IsFullScreen <span class="kwrd">Then</span>
            <span class="kwrd">Me</span>.Gfx.ToggleFullScreen()
        <span class="kwrd">End</span> <span class="kwrd">If</span>
    <span class="kwrd">End</span> <span class="kwrd">Sub</span>

    <span class="kwrd">Protected</span> <span class="kwrd">Overrides</span> <span class="kwrd">Sub</span> Initialize()
        <span class="kwrd">MyBase</span>.Initialize()
    <span class="kwrd">End</span> <span class="kwrd">Sub</span>

    <span class="kwrd">Protected</span> <span class="kwrd">Overrides</span> <span class="kwrd">Sub</span> LoadContent()
        <span class="kwrd">Me</span>.Sb = <span class="kwrd">New</span> Microsoft.Xna.Framework.Graphics.SpriteBatch(<span class="kwrd">Me</span>.Gfx.GraphicsDevice)
        <span class="kwrd">Me</span>.SpriteTexture = Microsoft.Xna.Framework.Graphics.Texture2D.FromFile(<span class="kwrd">Me</span>.Gfx.GraphicsDevice, _
              <span class="str">"mysprite.png"</span>)
        <span class="kwrd">MyBase</span>.LoadContent()
    <span class="kwrd">End</span> <span class="kwrd">Sub</span>

    <span class="kwrd">Protected</span> <span class="kwrd">Overrides</span> <span class="kwrd">Sub</span> UnloadContent()
        <span class="kwrd">MyBase</span>.UnloadContent()
    <span class="kwrd">End</span> <span class="kwrd">Sub</span>

    <span class="kwrd">Protected</span> <span class="kwrd">Overrides</span> <span class="kwrd">Sub</span> Update(<span class="kwrd">ByVal</span> gameTime <span class="kwrd">As</span> Microsoft.Xna.Framework.GameTime)
        SpriteX += 1
        SpriteY += 1
        <span class="kwrd">MyBase</span>.Update(gameTime)
    <span class="kwrd">End</span> <span class="kwrd">Sub</span>

    <span class="kwrd">Protected</span> <span class="kwrd">Overrides</span> <span class="kwrd">Sub</span> Draw(<span class="kwrd">ByVal</span> gameTime <span class="kwrd">As</span> Microsoft.Xna.Framework.GameTime)
        <span class="kwrd">Me</span>.Gfx.GraphicsDevice.Clear(Microsoft.Xna.Framework.Graphics.Color.Black)
        <span class="kwrd">Me</span>.Sb.Begin(Microsoft.Xna.Framework.Graphics.SpriteBlendMode.AlphaBlend)
        <span class="kwrd">Me</span>.Sb.Draw(<span class="kwrd">Me</span>.SpriteTexture, <span class="kwrd">New</span> Microsoft.Xna.Framework.Rectangle(<span class="kwrd">Me</span>.SpriteX, <span class="kwrd">Me</span>.SpriteY, 32, 32), _
                Microsoft.Xna.Framework.Graphics.Color.Red)
        <span class="kwrd">Me</span>.Sb.<span class="kwrd">End</span>()
        <span class="kwrd">MyBase</span>.Draw(gameTime)
    <span class="kwrd">End</span> <span class="kwrd">Sub</span>

<span class="kwrd">End</span> <span class="kwrd">Class</span>
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.winsoft.se/2010/01/hardware-accelerated-graphics-through-xna-getting-started/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The simplest query tool ever</title>
		<link>http://www.winsoft.se/2009/12/the-simplest-query-tool-ever/</link>
		<comments>http://www.winsoft.se/2009/12/the-simplest-query-tool-ever/#comments</comments>
		<pubDate>Mon, 21 Dec 2009 18:04:07 +0000</pubDate>
		<dc:creator>Anders Hesselbom</dc:creator>
				<category><![CDATA[Visual Basic 10]]></category>
		<category><![CDATA[.NET Framework]]></category>
		<category><![CDATA[QTool]]></category>

		<guid isPermaLink="false">http://www.winsoft.se/?p=748</guid>
		<description><![CDATA[A colleague wanted to do a database query from a computer without any database client. He needed a tool that allowed him to type in a SQL query, and receive a sortable grid with the result set. All of these features are built-in in the .NET Framework, and it didn’t take me more than 2 [...]]]></description>
			<content:encoded><![CDATA[<p>A colleague wanted to do a database query from a computer without any database client. He needed a tool that allowed him to type in a SQL query, and receive a sortable grid with the result set. All of these features are built-in in the .NET Framework, and it didn’t take me more than 2 minutes to do an exe file with these features using Visual Studio 2010. I used .NET 2.0 because these basic features are available in that version, and he did not want to install a newer version of the .NET Framework.</p>
<p>This is the user interface: A tab strip with three tabs. One for a connection string, one for the query and one for the result grid. The first two contains a textbox each, and the third contains a DataGridView control. Also, the program has a status bar with a label and a toolstrip with two buttons; one for testing the connectionstring that the user enters in the textbox of the first tab, and one for executing the query and presenting the result in the grid.</p>
<p><img class="alignnone" title="QTool" src="http://imghost.winsoft.se/upload/754531261416897qtool.jpg" alt="" width="537" height="318" /></p>
<p>The program consist one variable and four event handlers in one form. The variable holds the result set.</p>
<pre class="csharpcode">
<span class="kwrd">Private</span> Ds <span class="kwrd">As</span> DataSet</pre>
<p>The first function responds to the Load event of the form. This function restores the last values that from the textboxes. This is just for user convenience.</p>
<pre class="csharpcode">
<span class="kwrd">Private</span> <span class="kwrd">Sub</span> Form1_Load(<span class="kwrd">ByVal</span> sender <span class="kwrd">As</span> System.<span class="kwrd">Object</span>, <span class="kwrd">ByVal</span> e <span class="kwrd">As</span> System.EventArgs) _
<span class="kwrd">Handles</span> <span class="kwrd">MyBase</span>.Load
    txtCn.Text = <span class="kwrd">CType</span>(Application.UserAppDataRegistry.GetValue(<span class="str">"Cn"</span>, <span class="str">""</span>), <span class="kwrd">String</span>)
    txtQuery.Text = <span class="kwrd">CType</span>(Application.UserAppDataRegistry.GetValue(<span class="str">"Query"</span>, <span class="str">""</span>), <span class="kwrd">String</span>)
<span class="kwrd">End</span> Sub</pre>
<p>The second function responds to the Close event of the form. This function saves the values from the textboxes so that they can be restored (in the Load event) in the next session. Also, if needed, it disposes the dataset variable.</p>
<pre class="csharpcode">
<span class="kwrd">Private</span> <span class="kwrd">Sub</span> Form1_FormClosed(<span class="kwrd">ByVal</span> sender <span class="kwrd">As</span> <span class="kwrd">Object</span>, <span class="kwrd">ByVal</span> e <span class="kwrd">As</span> System.Windows.Forms.FormClosedEventArgs) _
<span class="kwrd">Handles</span> <span class="kwrd">Me</span>.FormClosed
    Application.UserAppDataRegistry.SetValue(<span class="str">"Cn"</span>, txtCn.Text)
    Application.UserAppDataRegistry.SetValue(<span class="str">"Query"</span>, txtQuery.Text)
    <span class="kwrd">If</span> <span class="kwrd">Not</span> Ds <span class="kwrd">Is</span> <span class="kwrd">Nothing</span> <span class="kwrd">Then</span>
        Ds.Dispose()
    <span class="kwrd">End</span> <span class="kwrd">If</span>
<span class="kwrd">End</span> Sub</pre>
<p>This is the handler for the test button. It simply connects to the given data source, and tells if it succeeds or fails.</p>
<pre class="csharpcode">
<span class="kwrd">Private</span> <span class="kwrd">Sub</span> btnTestConnection_Click(<span class="kwrd">ByVal</span> sender <span class="kwrd">As</span> System.<span class="kwrd">Object</span>, <span class="kwrd">ByVal</span> e <span class="kwrd">As</span> System.EventArgs) _
<span class="kwrd">Handles</span> btnTestConnection.Click
    <span class="rem">'Jump to the connection tab (the first one).</span>
    TabControl1.SelectedTab = tabConnection

    <span class="rem">'Do the test.</span>
    <span class="kwrd">Me</span>.Cursor = Cursors.WaitCursor
    <span class="kwrd">Dim</span> Success <span class="kwrd">As</span> <span class="kwrd">Boolean</span> = <span class="kwrd">False</span>
    <span class="kwrd">Try</span>
        Using Cn <span class="kwrd">As</span> <span class="kwrd">New</span> SqlClient.SqlConnection(txtCn.Text)
            Cn.Open()
            Success = (Cn.State = ConnectionState.Open)
            Cn.Close()
        <span class="kwrd">End</span> Using
    <span class="kwrd">Catch</span> ex <span class="kwrd">As</span> Exception
    <span class="kwrd">End</span> <span class="kwrd">Try</span>
    <span class="kwrd">Me</span>.Cursor = Cursors.<span class="kwrd">Default</span>
    <span class="kwrd">If</span> Success <span class="kwrd">Then</span>
        lblStatus.Text = <span class="str">"Connection test succeeded."</span>
        MessageBox.Show(<span class="str">"Connection test succeeded."</span>, <span class="kwrd">Me</span>.Text, _
            MessageBoxButtons.OK, MessageBoxIcon.Information)
    <span class="kwrd">Else</span>
        lblStatus.Text = <span class="str">"Connection test failed."</span>
        MessageBox.Show(<span class="str">"Connection test failed."</span>, <span class="kwrd">Me</span>.Text, MessageBoxButtons.OK, _
            MessageBoxIcon.<span class="kwrd">Error</span>)
    <span class="kwrd">End</span> <span class="kwrd">If</span>
<span class="kwrd">End</span> Sub</pre>
<p>Finally, this is the handler for the execute button.</p>
<pre class="csharpcode">
<span class="kwrd">Private</span> <span class="kwrd">Sub</span> btnExecute_Click(<span class="kwrd">ByVal</span> sender <span class="kwrd">As</span> System.<span class="kwrd">Object</span>, <span class="kwrd">ByVal</span> e <span class="kwrd">As</span> System.EventArgs) _
<span class="kwrd">Handles</span> btnExecute.Click
    <span class="rem">'Remove the current data table as data source of the grid.</span>
    DataGridView1.DataSource = <span class="kwrd">Nothing</span>

    <span class="kwrd">If</span> <span class="kwrd">Not</span> <span class="kwrd">Me</span>.Ds <span class="kwrd">Is</span> <span class="kwrd">Nothing</span> <span class="kwrd">Then</span>
        <span class="rem">'If there is an old data set in memory, dispose that.</span>
        <span class="kwrd">Me</span>.Ds.Dispose()
        <span class="rem">'To remember that no data is present, set the variable to NULL.</span>
        <span class="kwrd">Me</span>.Ds = <span class="kwrd">Nothing</span>
    <span class="kwrd">End</span> <span class="kwrd">If</span>

    <span class="rem">'Jump to the result tab (the third one).</span>
    TabControl1.SelectedTab = tabResult

    <span class="rem">'Do the query and bind the result. Quick and dirty error "handling".</span>
    <span class="kwrd">Me</span>.Cursor = Cursors.WaitCursor
    <span class="kwrd">Try</span>
        Using Cn <span class="kwrd">As</span> <span class="kwrd">New</span> SqlClient.SqlConnection(txtCn.Text)
            Cn.Open()
            Using Cmd <span class="kwrd">As</span> <span class="kwrd">New</span> SqlClient.SqlCommand(txtQuery.Text, Cn)
                Using Da <span class="kwrd">As</span> <span class="kwrd">New</span> SqlClient.SqlDataAdapter(Cmd)
                    Ds = <span class="kwrd">New</span> DataSet()
                    Da.Fill(Ds)
                    <span class="kwrd">If</span> Ds.Tables.Count &gt; 0 <span class="kwrd">Then</span>
                        DataGridView1.DataSource = Ds.Tables(0)
                        <span class="kwrd">If</span> Ds.Tables.Count &gt; 1 <span class="kwrd">Then</span>
                            <span class="kwrd">Me</span>.Cursor = Cursors.<span class="kwrd">Default</span>
                            MessageBox.Show(<span class="str">"More than one dataset was returned."</span>, <span class="str">"Query"</span>, _
                                MessageBoxButtons.OK, MessageBoxIcon.Information)
                        <span class="kwrd">End</span> <span class="kwrd">If</span>
                    <span class="kwrd">Else</span>
                        <span class="kwrd">Me</span>.Cursor = Cursors.<span class="kwrd">Default</span>
                        MessageBox.Show(<span class="str">"No dataset was returned."</span>, <span class="str">"Query"</span>, _
                            MessageBoxButtons.OK, MessageBoxIcon.Information)
                    <span class="kwrd">End</span> <span class="kwrd">If</span>
                <span class="kwrd">End</span> Using
            <span class="kwrd">End</span> Using
            Cn.Close()
        <span class="kwrd">End</span> Using
        lblStatus.Text = <span class="str">"Success."</span>
    <span class="kwrd">Catch</span> ex <span class="kwrd">As</span> Exception
        lblStatus.Text = <span class="str">"Failed. "</span> &amp; ex.Message
            <span class="kwrd">Me</span>.Cursor = Cursors.<span class="kwrd">Default</span>
        MessageBox.Show(ex.Message, <span class="str">"Failed"</span>, MessageBoxButtons.OK, MessageBoxIcon.<span class="kwrd">Error</span>)
    <span class="kwrd">End</span> <span class="kwrd">Try</span>
    <span class="kwrd">Me</span>.Cursor = Cursors.<span class="kwrd">Default</span>
<span class="kwrd">End</span> Sub</pre>
<p>So, making a personal query tool doesn&#8217;t have to take more than a couple of minutes in .NET.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.winsoft.se/2009/12/the-simplest-query-tool-ever/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>ASP.NET 4.0: Diagrams</title>
		<link>http://www.winsoft.se/2009/12/asp-net-4-0-diagrams/</link>
		<comments>http://www.winsoft.se/2009/12/asp-net-4-0-diagrams/#comments</comments>
		<pubDate>Fri, 18 Dec 2009 17:05:37 +0000</pubDate>
		<dc:creator>Anders Hesselbom</dc:creator>
				<category><![CDATA[Visual Basic 10]]></category>

		<guid isPermaLink="false">http://www.winsoft.se/?p=744</guid>
		<description><![CDATA[To get your hands on this new and cool feature, create an ASP.NET 4.0 application or web site from within Visual Studio 2010. Check the Data section of the Toolbox window for a new control called Chart. Dragging out a Chart onto a web page creates the following code: &#60;asp:Chart ID="Chart1" runat="server"&#62; &#60;Series&#62; &#60;asp:Series Name="Series1"&#62; [...]]]></description>
			<content:encoded><![CDATA[<p>To get your hands on this new and cool feature, create an ASP.NET 4.0 application or web site from within Visual Studio 2010. Check the Data section of the Toolbox window for a new control called <strong>Chart</strong>. Dragging out a Chart onto a web page creates the following code:</p>
<pre>&lt;asp:Chart ID="Chart1" runat="server"&gt;
  &lt;Series&gt;
    &lt;asp:Series Name="Series1"&gt;
  &lt;/asp:Series&gt;
  &lt;/Series&gt;
    &lt;ChartAreas&gt;
      &lt;asp:ChartArea Name="ChartArea1"&gt;
    &lt;/asp:ChartArea&gt;
  &lt;/ChartAreas&gt;
&lt;/asp:Chart&gt;</pre>
<p>There is a huge amount of properties available for the chart. They control the look of the chart, the chart type among other things. I don’t have any databases installed on this computer, so to get some data to do a chart from; I connect the control to a data source that represents the system database master. I use the following query to get a bunch of large numbers:</p>
<p><strong>SELECT [name],[number] FROM dbo.spt_values WHERE [number]&gt;17000</strong></p>
<p>I use <em>number</em> as Y value member.</p>
<p><img class="alignnone" src="http://imghost.winsoft.se/upload/994461261154655chart1.jpg" alt="" width="302" height="209" /></p>
<p>This is what I have to do to get the fully functional chart! Fooling around with chart types and visual properties is dangerously amusing.</p>
<p><img class="alignnone" src="http://imghost.winsoft.se/upload/497261261155042chart2.jpg" alt="" width="275" height="278" /></p>
<p>If you haven’t got a database server at all, you can quickly create an object data source in Visual Basic, and assign that to your chart. Connection this code&#8230;</p>
<pre class="csharpcode"><span class="kwrd">Public</span> <span class="kwrd">Class</span> MyChartData

    <span class="kwrd">Private</span> mValue <span class="kwrd">As</span> <span class="kwrd">Integer</span>

    <span class="kwrd">Public</span> <span class="kwrd">Sub</span> <span class="kwrd">New</span>(<span class="kwrd">ByVal</span> Value <span class="kwrd">As</span> <span class="kwrd">Integer</span>)
        <span class="kwrd">Me</span>.mValue = Value
    <span class="kwrd">End</span> <span class="kwrd">Sub</span>

    <span class="kwrd">Public</span> <span class="kwrd">ReadOnly</span> <span class="kwrd">Property</span> Value() <span class="kwrd">As</span> <span class="kwrd">Integer</span>
        <span class="kwrd">Get</span>
            <span class="kwrd">Return</span> <span class="kwrd">Me</span>.mValue
        <span class="kwrd">End</span> <span class="kwrd">Get</span>
    <span class="kwrd">End</span> <span class="kwrd">Property</span>

    <span class="kwrd">Public</span> <span class="kwrd">Shared</span> <span class="kwrd">Function</span> GetItems() <span class="kwrd">As</span> MyChartData()
        <span class="kwrd">Dim</span> Ret <span class="kwrd">As</span> <span class="kwrd">New</span> List(Of MyChartData)()
        Ret.Add(<span class="kwrd">New</span> MyChartData(10))
        Ret.Add(<span class="kwrd">New</span> MyChartData(20))
        Ret.Add(<span class="kwrd">New</span> MyChartData(15))
        Ret.Add(<span class="kwrd">New</span> MyChartData(25))
        <span class="kwrd">Return</span> Ret.ToArray()
    <span class="kwrd">End</span> <span class="kwrd">Function</span>

<span class="kwrd">End</span> Class</pre>
<p>&#8230;gives you this beautiful result:</p>
<p><img class="alignnone" src="http://imghost.winsoft.se/upload/948151261155562chart3.jpg" alt="" width="279" height="279" /></p>
<p>Ah, the simplicity! Aaaaah, the power!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.winsoft.se/2009/12/asp-net-4-0-diagrams/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

