<?xml version="1.0" encoding="ISO-8859-1"?>

<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/">
	<channel>
		<title>VBForums - CodeBank - Visual Basic .NET</title>
		<link>http://www.vbforums.com/</link>
		<description>Find cool or practical code examples using Visual Basic .NET.</description>
		<language>en</language>
		<lastBuildDate>Sat, 25 May 2013 18:47:40 GMT</lastBuildDate>
		<generator>vBulletin</generator>
		<ttl>60</ttl>
		<image>
			<url>http://www.vbforums.com/images/misc/rss.png</url>
			<title>VBForums - CodeBank - Visual Basic .NET</title>
			<link>http://www.vbforums.com/</link>
		</image>
		<item>
			<title>Match Two Game</title>
			<link>http://www.vbforums.com/showthread.php?722573-Match-Two-Game&amp;goto=newpost</link>
			<pubDate>Thu, 23 May 2013 05:54:21 GMT</pubDate>
			<description><![CDATA[I saw someone asking about this the other day so I thought that I'd throw a demo together.  It's a simple game that displays a 5x4 grid of cards containing 10 matching pairs.  The back of all cards is displayed initially and, after starting a game, the user clicks on a pair to reveal them.  If the pair matches then both cards are removed and if they don't match then they are turned over again.  The application times the game and displays the running time as well as the total time when the game is completed.  The game can also be paused and restarted.

I'm considering adding some more features to the game in the future, e.g. a list of best times and the ability to load an arbitrary number of image files from an arbitrary folder.  We'll see if the mood strikes me.

The attached solution was created in VS 2010 and contains projects in both VB and C#.  If you're using VB Express 2010 or C# Express 2010 then only one of the projects will be loaded.  If you try to open the MainWindow form in the designer and it won't display, just close it and then open it in the code window first and you should be OK from there.]]></description>
			<content:encoded><![CDATA[<div>I saw someone asking about this the other day so I thought that I'd throw a demo together.  It's a simple game that displays a 5x4 grid of cards containing 10 matching pairs.  The back of all cards is displayed initially and, after starting a game, the user clicks on a pair to reveal them.  If the pair matches then both cards are removed and if they don't match then they are turned over again.  The application times the game and displays the running time as well as the total time when the game is completed.  The game can also be paused and restarted.<br />
<br />
I'm considering adding some more features to the game in the future, e.g. a list of best times and the ability to load an arbitrary number of image files from an arbitrary folder.  We'll see if the mood strikes me.<br />
<br />
The attached solution was created in VS 2010 and contains projects in both VB and C#.  If you're using VB Express 2010 or C# Express 2010 then only one of the projects will be loaded.  If you try to open the MainWindow form in the designer and it won't display, just close it and then open it in the code window first and you should be OK from there.</div>


	<div style="padding:10px">

	

	

	

	
		<fieldset class="fieldset">
			<legend>Attached Files</legend>
			<ul>
			<li>
	<img class="inlineimg" src="http://www.vbforums.com/images/attach/zip.gif" alt="File Type: zip" />
	<a href="http://www.vbforums.com/attachment.php?attachmentid=100449&amp;d=1369288360">MatchTwoDemo.zip</a> 
(47.9 KB)
</li>
			</ul>
		</fieldset>
	

	</div>
]]></content:encoded>
			<category domain="http://www.vbforums.com/forumdisplay.php?46-CodeBank-Visual-Basic-NET">CodeBank - Visual Basic .NET</category>
			<dc:creator>jmcilhinney</dc:creator>
			<guid isPermaLink="true">http://www.vbforums.com/showthread.php?722573-Match-Two-Game</guid>
		</item>
		<item>
			<title>A More Random Random Class</title>
			<link>http://www.vbforums.com/showthread.php?722445-A-More-Random-Random-Class&amp;goto=newpost</link>
			<pubDate>Wed, 22 May 2013 05:03:22 GMT</pubDate>
			<description><![CDATA[C# version here (http://www.vbforums.com/showthread.php?722469-A-More-Random-Random-Class).

The .NET Framework includes the System.Random class, whose job it is to generate random numbers.  It does so using a sequence based on a seed value, which is based on the system time by default.  There are numerous possible seeds and predicting the exact time that a Random object will be created is not easy.  That, coupled with the fact that the distribution of numbers generated by the sequence satisfies various statistical requirements for randomness, means that the Random class is quite suitable for most of your random number needs.

The main issue with the Random class is that, given a particular seed, the sequence will always produce the same numbers.  That can actually be good for some testing scenarios but it does mean that the results could be manipulated.  Where very high levels of unpredictability are required, the Random class is not suitable.

I've seen a number of people use various methods to generate more random random numbers.  That's not really necessary though.  The .NET Framework also includes the System.Security.Cryptography.RNGCryptoServiceProvider class for generating random numbers.  It's output is sufficiently random for use in cryptography, so there's really no need for anything more random than that.

One issue with the RNGCryptoServiceProvider class, though, is that it populates Byte arrays with random values.  That's not always completely convenient though, as the most common need in applications is a random Integer within a specific range.  The Random class is nice and easy to use in that scenario, thanks to its Next method.  What if we could combine the ease of use of the Random class with the increased randomness of the RNGCryptoServiceProvider class?

As it happens, we can.  The Random class has a Protected method named Sample that generates a Double in the range 0.0 <= x < 1.0.  The result of that method is then used in the other methods to generate Integers in a range.  We can define our own class that inherits Random and overrides that Sample method to use RNGCryptoServiceProvider internally.  Here's one I prepared earlier:Imports System.Security.Cryptography

''' <summary>
''' Represents a random number generator, a device that produces a sequence of numbers that meet cryptographic requirements for randomness.
''' </summary>
''' <remarks>
''' Seed values are meaningless because this class uses a cryptographic service provider internally rather than a pseudo-random sequence.
''' </remarks>
Public Class CryptoRandom
    Inherits Random
    Implements IDisposable

    ''' <summary>
    ''' The internal random number generator.
    ''' </summary>
    Private ReadOnly rng As New RNGCryptoServiceProvider

    ''' <summary>
    ''' Returns a random number between 0.0 and 1.0.
    ''' </summary>
    ''' <returns>
    ''' A double-precision floating point number greater than or equal to 0.0, and less than 1.0.
    ''' </returns>
    ''' <remarks>
    ''' Uses a cryptographic service provider internally rather than a pseudo-random sequence.
    ''' </remarks>
    Protected Overrides Function Sample() As Double
        Dim data(7) As Byte
        Dim number As ULong

        Do
            'Get 8 random bytes.
            rng.GetBytes(data)

            'Convert the bytes to an unsigned 64-bit number.
            number = BitConverter.ToUInt64(data, 0)
        Loop While number = ULong.MaxValue 'The result must be less than 1.0

        'Divide the number by the largest possible unsigned 64-bit number to get a value in the range 0.0 <= N < 1.0.
        Return number / ULong.MaxValue
    End Function

#Region "IDisposable Support"

    Private disposedValue As Boolean ' To detect redundant calls

    ' IDisposable
    Protected Overridable Sub Dispose(disposing As Boolean)
        If Not Me.disposedValue Then
            If disposing Then
                'Dispose the underlying cryptographic random number generator.
                rng.Dispose()
            End If
        End If

        Me.disposedValue = True
    End Sub

    ' This code added by Visual Basic to correctly implement the disposable pattern.
    Public Sub Dispose() Implements IDisposable.Dispose
        ' Do not change this code.  Put cleanup code in Dispose(disposing As Boolean) above.
        Dispose(True)
        GC.SuppressFinalize(Me)
    End Sub

#End Region

End ClassYou can create an instance of that class and use it in pretty much exactly the same way as you would a Random object.  The only difference is that you will need to call its Dispose method when you're done, in order to dispose the internal RNGCryptoServiceProvider object.  Sample usage:Public Class Form1

    Private ReadOnly rng As New CryptoRandom

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        'Generate 10 random numbers.
        Dim numbers(9) As Integer

        For i = 0 To numbers.GetUpperBound(0)
            'Generate numbers in the range 0 <= n <= 1000
            numbers(i) = rng.Next(1001)
        Next

        MessageBox.Show(String.Join(Environment.NewLine, numbers),
                        "10 Random Numbers")
    End Sub

    Private Sub Form1_FormClosed(sender As Object, e As FormClosedEventArgs) Handles Me.FormClosed
        rng.Dispose()
    End Sub

End Class]]></description>
			<content:encoded><![CDATA[<div>C# version <a rel="nofollow" href="http://www.vbforums.com/showthread.php?722469-A-More-Random-Random-Class" target="_blank">here</a>.<br />
<br />
The .NET Framework includes the System.Random class, whose job it is to generate random numbers.  It does so using a sequence based on a seed value, which is based on the system time by default.  There are numerous possible seeds and predicting the exact time that a Random object will be created is not easy.  That, coupled with the fact that the distribution of numbers generated by the sequence satisfies various statistical requirements for randomness, means that the Random class is quite suitable for most of your random number needs.<br />
<br />
The main issue with the Random class is that, given a particular seed, the sequence will always produce the same numbers.  That can actually be good for some testing scenarios but it does mean that the results could be manipulated.  Where very high levels of unpredictability are required, the Random class is not suitable.<br />
<br />
I've seen a number of people use various methods to generate more random random numbers.  That's not really necessary though.  The .NET Framework also includes the System.Security.Cryptography.RNGCryptoServiceProvider class for generating random numbers.  It's output is sufficiently random for use in cryptography, so there's really no need for anything more random than that.<br />
<br />
One issue with the RNGCryptoServiceProvider class, though, is that it populates Byte arrays with random values.  That's not always completely convenient though, as the most common need in applications is a random Integer within a specific range.  The Random class is nice and easy to use in that scenario, thanks to its Next method.  What if we could combine the ease of use of the Random class with the increased randomness of the RNGCryptoServiceProvider class?<br />
<br />
As it happens, we can.  The Random class has a Protected method named Sample that generates a Double in the range 0.0 &lt;= x &lt; 1.0.  The result of that method is then used in the other methods to generate Integers in a range.  We can define our own class that inherits Random and overrides that Sample method to use RNGCryptoServiceProvider internally.  Here's one I prepared earlier:<div style="margin:20px; margin-top:5px">
	<div class="smallfont" style="margin-bottom:2px">vb.net Code:</div>
	<pre class="alt2" style="margin:0px; padding:px; border:1px inset; width:; max-height:372px;overflow:auto"><div dir="ltr" style="text-align:left;"><div class="vbnet" style="font-family: monospace;"><ol><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0600FF;">Imports</span> System.<span style="color: #0000FF;">Security</span>.<span style="color: #0000FF;">Cryptography</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #008080; font-style: italic;">''' &lt;summary&gt;</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #008080; font-style: italic;">''' Represents a random number generator, a device that produces a sequence of numbers that meet cryptographic requirements for randomness.</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #008080; font-style: italic;">''' &lt;/summary&gt;</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #008080; font-style: italic;">''' &lt;remarks&gt;</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #008080; font-style: italic;">''' Seed values are meaningless because this class uses a cryptographic service provider internally rather than a pseudo-random sequence.</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #008080; font-style: italic;">''' &lt;/remarks&gt;</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #FF8000;">Public</span> <span style="color: #0600FF;">Class</span> CryptoRandom</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #0600FF;">Inherits</span> Random</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #0600FF;">Implements</span> IDisposable</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">''' &lt;summary&gt;</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">''' The internal random number generator.</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">''' &lt;/summary&gt;</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #FF8000;">Private</span> <span style="color: #0600FF;">ReadOnly</span> rng <span style="color: #FF8000;">As</span> <span style="color: #FF8000;">New</span> RNGCryptoServiceProvider</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">''' &lt;summary&gt;</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">''' Returns a random number between 0.0 and 1.0.</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">''' &lt;/summary&gt;</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">''' &lt;returns&gt;</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">''' A double-precision floating point number greater than or equal to 0.0, and less than 1.0.</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">''' &lt;/returns&gt;</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">''' &lt;remarks&gt;</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">''' Uses a cryptographic service provider internally rather than a pseudo-random sequence.</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">''' &lt;/remarks&gt;</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; Protected Overrides <span style="color: #0600FF;">Function</span> Sample<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #FF8000;">As</span> <span style="color: #FF0000;">Double</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">Dim</span> data<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">7</span><span style="color: #000000;">&#41;</span> <span style="color: #FF8000;">As</span> <span style="color: #FF0000;">Byte</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">Dim</span> number <span style="color: #FF8000;">As</span> ULong</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">Do</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">'Get 8 random bytes.</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; rng.<span style="color: #0000FF;">GetBytes</span><span style="color: #000000;">&#40;</span>data<span style="color: #000000;">&#41;</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">'Convert the bytes to an unsigned 64-bit number.</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; number = BitConverter.<span style="color: #0000FF;">ToUInt64</span><span style="color: #000000;">&#40;</span>data, <span style="color: #FF0000;">0</span><span style="color: #000000;">&#41;</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">Loop</span> <span style="color: #0600FF;">While</span> number = ULong.<span style="color: #0000FF;">MaxValue</span> <span style="color: #008080; font-style: italic;">'The result must be less than 1.0</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">'Divide the number by the largest possible unsigned 64-bit number to get a value in the range 0.0 &lt;= N &lt; 1.0.</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; Return number / ULong.<span style="color: #0000FF;">MaxValue</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #0600FF;">End</span> <span style="color: #0600FF;">Function</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">#Region <span style="color: #808080;">&quot;IDisposable Support&quot;</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #FF8000;">Private</span> disposedValue <span style="color: #FF8000;">As</span> <span style="color: #FF0000;">Boolean</span> <span style="color: #008080; font-style: italic;">' To detect redundant calls</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">' IDisposable</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; Protected <span style="color: #FF8000;">Overridable</span> <span style="color: #0600FF;">Sub</span> Dispose<span style="color: #000000;">&#40;</span>disposing <span style="color: #FF8000;">As</span> <span style="color: #FF0000;">Boolean</span><span style="color: #000000;">&#41;</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">If</span> <span style="color: #804040;">Not</span> <span style="color: #FF8000;">Me</span>.<span style="color: #0000FF;">disposedValue</span> <span style="color: #FF8000;">Then</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">If</span> disposing <span style="color: #FF8000;">Then</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">'Dispose the underlying cryptographic random number generator.</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; rng.<span style="color: #0000FF;">Dispose</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">End</span> <span style="color: #0600FF;">If</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">End</span> <span style="color: #0600FF;">If</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #FF8000;">Me</span>.<span style="color: #0000FF;">disposedValue</span> = <span style="color: #0600FF;">True</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #0600FF;">End</span> <span style="color: #0600FF;">Sub</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #008080; font-style: italic;">' This code added by Visual Basic to correctly implement the disposable pattern.</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #FF8000;">Public</span> <span style="color: #0600FF;">Sub</span> Dispose<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #0600FF;">Implements</span> IDisposable.<span style="color: #0000FF;">Dispose</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">' Do not change this code. &nbsp;Put cleanup code in Dispose(disposing As Boolean) above.</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; Dispose<span style="color: #000000;">&#40;</span><span style="color: #0600FF;">True</span><span style="color: #000000;">&#41;</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; GC.<span style="color: #0000FF;">SuppressFinalize</span><span style="color: #000000;">&#40;</span><span style="color: #FF8000;">Me</span><span style="color: #000000;">&#41;</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #0600FF;">End</span> <span style="color: #0600FF;">Sub</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">#End Region</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0600FF;">End</span> <span style="color: #0600FF;">Class</span></div></li></ol></div></div></pre>
</div>You can create an instance of that class and use it in pretty much exactly the same way as you would a Random object.  The only difference is that you will need to call its Dispose method when you're done, in order to dispose the internal RNGCryptoServiceProvider object.  Sample usage:<div style="margin:20px; margin-top:5px">
	<div class="smallfont" style="margin-bottom:2px">vb.net Code:</div>
	<pre class="alt2" style="margin:0px; padding:px; border:1px inset; width:; max-height:372px;overflow:auto"><div dir="ltr" style="text-align:left;"><div class="vbnet" style="font-family: monospace;"><ol><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #FF8000;">Public</span> <span style="color: #0600FF;">Class</span> Form1</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #FF8000;">Private</span> <span style="color: #0600FF;">ReadOnly</span> rng <span style="color: #FF8000;">As</span> <span style="color: #FF8000;">New</span> CryptoRandom</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #FF8000;">Private</span> <span style="color: #0600FF;">Sub</span> Button1_Click<span style="color: #000000;">&#40;</span>sender <span style="color: #FF8000;">As</span> <span style="color: #FF0000;">Object</span>, e <span style="color: #FF8000;">As</span> EventArgs<span style="color: #000000;">&#41;</span> <span style="color: #FF8000;">Handles</span> Button1.<span style="color: #0000FF;">Click</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">'Generate 10 random numbers.</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">Dim</span> numbers<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">9</span><span style="color: #000000;">&#41;</span> <span style="color: #FF8000;">As</span> <span style="color: #FF0000;">Integer</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #FF8000;">For</span> i = <span style="color: #FF0000;">0</span> <span style="color: #FF8000;">To</span> numbers.<span style="color: #0000FF;">GetUpperBound</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">0</span><span style="color: #000000;">&#41;</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">'Generate numbers in the range 0 &lt;= n &lt;= 1000</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; numbers<span style="color: #000000;">&#40;</span>i<span style="color: #000000;">&#41;</span> = rng.<span style="color: #FF8000;">Next</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">1001</span><span style="color: #000000;">&#41;</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #FF8000;">Next</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; MessageBox.<span style="color: #0000FF;">Show</span><span style="color: #000000;">&#40;</span><span style="color: #FF8000;">String</span>.<span style="color: #0600FF;">Join</span><span style="color: #000000;">&#40;</span>Environment.<span style="color: #0600FF;">NewLine</span>, numbers<span style="color: #000000;">&#41;</span>,</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080;">&quot;10 Random Numbers&quot;</span><span style="color: #000000;">&#41;</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #0600FF;">End</span> <span style="color: #0600FF;">Sub</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #FF8000;">Private</span> <span style="color: #0600FF;">Sub</span> Form1_FormClosed<span style="color: #000000;">&#40;</span>sender <span style="color: #FF8000;">As</span> <span style="color: #FF0000;">Object</span>, e <span style="color: #FF8000;">As</span> FormClosedEventArgs<span style="color: #000000;">&#41;</span> <span style="color: #FF8000;">Handles</span> <span style="color: #FF8000;">Me</span>.<span style="color: #0000FF;">FormClosed</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; rng.<span style="color: #0000FF;">Dispose</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #0600FF;">End</span> <span style="color: #0600FF;">Sub</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0600FF;">End</span> <span style="color: #0600FF;">Class</span></div></li></ol></div></div></pre>
</div></div>


	<div style="padding:10px">

	

	

	

	
		<fieldset class="fieldset">
			<legend>Attached Files</legend>
			<ul>
			<li>
	<img class="inlineimg" src="http://www.vbforums.com/images/attach/vb.gif" alt="File Type: vb" />
	<a href="http://www.vbforums.com/attachment.php?attachmentid=100391&amp;d=1369212483">CryptoRandom.vb</a> 
(2.3 KB)
</li>
			</ul>
		</fieldset>
	

	</div>
]]></content:encoded>
			<category domain="http://www.vbforums.com/forumdisplay.php?46-CodeBank-Visual-Basic-NET">CodeBank - Visual Basic .NET</category>
			<dc:creator>jmcilhinney</dc:creator>
			<guid isPermaLink="true">http://www.vbforums.com/showthread.php?722445-A-More-Random-Random-Class</guid>
		</item>
		<item>
			<title>Customisable Form Title Bar - The Easy Way</title>
			<link>http://www.vbforums.com/showthread.php?721625-Customisable-Form-Title-Bar-The-Easy-Way&amp;goto=newpost</link>
			<pubDate>Tue, 14 May 2013 15:01:56 GMT</pubDate>
			<description><![CDATA[Antonio Sánchez Fajardo in this Code Project Article (http://www.codeproject.com/Tips/592446/How-to-create-your-own-advanced-TitleBar) reveals this little trick to dismiss the standard title bar but retain the border.

Public Class Form1
' with Form1.ControlBox = False
    Protected Overrides ReadOnly Property CreateParams As System.Windows.Forms.CreateParams
        Get
            Dim CP = MyBase.CreateParams
            CP.Style = CP.Style And Not &HC00000
            Return CP
        End Get
    End Property
End Class
The great advantage of VB.Net at this point is that its more robust support for forms means that it is not required to add handlers for resizing and other form manipulation and you can get on to the design of your title/control bars without further adjustments.

Attachment 100111 (http://www.vbforums.com/attachment.php?attachmentid=100111)

Attachment 100113 (http://www.vbforums.com/attachment.php?attachmentid=100113)]]></description>
			<content:encoded><![CDATA[<div>Antonio Sánchez Fajardo in <a rel="nofollow" href="http://www.codeproject.com/Tips/592446/How-to-create-your-own-advanced-TitleBar" target="_blank">this Code Project Article</a> reveals this little trick to dismiss the standard title bar but retain the border.<br />
<br />
<div style="margin:20px; margin-top:5px">
	<div class="smallfont" style="margin-bottom:2px">vb.net Code:</div>
	<pre class="alt2" style="margin:0px; padding:px; border:1px inset; width:; max-height:372px;overflow:auto"><div dir="ltr" style="text-align:left;"><div class="vbnet" style="font-family: monospace;"><ol><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #FF8000;">Public</span> <span style="color: #0600FF;">Class</span> Form1</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #008080; font-style: italic;">' with Form1.ControlBox = False</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; Protected Overrides <span style="color: #0600FF;">ReadOnly</span> <span style="color: #FF8000;">Property</span> CreateParams <span style="color: #FF8000;">As</span> System.<span style="color: #0000FF;">Windows</span>.<span style="color: #0000FF;">Forms</span>.<span style="color: #0000FF;">CreateParams</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #FF8000;">Get</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">Dim</span> CP = <span style="color: #FF8000;">MyBase</span>.<span style="color: #0000FF;">CreateParams</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; CP.<span style="color: #0000FF;">Style</span> = CP.<span style="color: #0000FF;">Style</span> <span style="color: #804040;">And</span> <span style="color: #804040;">Not</span> &amp;HC00000</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Return CP</div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">End</span> <span style="color: #FF8000;">Get</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #0600FF;">End</span> <span style="color: #FF8000;">Property</span></div></li><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0600FF;">End</span> <span style="color: #0600FF;">Class</span></div></li></ol></div></div></pre>
</div><br />
The great advantage of VB.Net at this point is that its more robust support for forms means that it is not required to add handlers for resizing and other form manipulation and you can get on to the design of your title/control bars without further adjustments.<br />
<br />
<img src="http://www.vbforums.com/attachment.php?attachmentid=100111&amp;d=1368543620" border="0" alt="Name:  a.png
Views: 79
Size:  10.9 KB"  /><br />
<br />
<img src="http://www.vbforums.com/attachment.php?attachmentid=100113&amp;d=1368543621" border="0" alt="Name:  b.png
Views: 109
Size:  5.0 KB"  /></div>


	<div style="padding:10px">

	

	
		<fieldset class="fieldset">
			<legend>Attached Images</legend>
				<div style="padding:10px">
				<img class="attach" src="http://www.vbforums.com/attachment.php?attachmentid=100111&amp;stc=1&amp;d=1368543620" alt="" />&nbsp;<img class="attach" src="http://www.vbforums.com/attachment.php?attachmentid=100113&amp;stc=1&amp;d=1368543621" alt="" />&nbsp;
			</div>
		</fieldset>
	

	

	

	</div>
]]></content:encoded>
			<category domain="http://www.vbforums.com/forumdisplay.php?46-CodeBank-Visual-Basic-NET">CodeBank - Visual Basic .NET</category>
			<dc:creator>dunfiddlin</dc:creator>
			<guid isPermaLink="true">http://www.vbforums.com/showthread.php?721625-Customisable-Form-Title-Bar-The-Easy-Way</guid>
		</item>
		<item>
			<title>Play Shoutcast radios stations (vb.net 2010)</title>
			<link>http://www.vbforums.com/showthread.php?721159-Play-Shoutcast-radios-stations-(vb-net-2010)&amp;goto=newpost</link>
			<pubDate>Fri, 10 May 2013 12:27:45 GMT</pubDate>
			<description>hi this is a source code to play Shoutcast radios stations 

this code deals with .pls .wpl (windows media player ) playlists 

Attachment 99921 (http://www.vbforums.com/attachment.php?attachmentid=99921)</description>
			<content:encoded><![CDATA[<div>hi this is a source code to play Shoutcast radios stations <br />
<br />
this code deals with .pls .wpl (windows media player ) playlists <br />
<br />
<img src="http://www.vbforums.com/attachment.php?attachmentid=99921&amp;d=1368188772" border="0" alt="Name:  331g6s3.jpg
Views: 103
Size:  397.2 KB"  /></div>


	<div style="padding:10px">

	

	
		<fieldset class="fieldset">
			<legend>Attached Images</legend>
				<div style="padding:10px">
				<img class="attach" src="http://www.vbforums.com/attachment.php?attachmentid=99921&amp;stc=1&amp;d=1368188772" alt="" />&nbsp;
			</div>
		</fieldset>
	

	

	
		<fieldset class="fieldset">
			<legend>Attached Files</legend>
			<ul>
			<li>
	<img class="inlineimg" src="http://www.vbforums.com/images/attach/zip.gif" alt="File Type: zip" />
	<a href="http://www.vbforums.com/attachment.php?attachmentid=99929&amp;d=1368190889">ShoutcastEcouteRadiov21.zip</a> 
(58.1 KB)
</li>
			</ul>
		</fieldset>
	

	</div>
]]></content:encoded>
			<category domain="http://www.vbforums.com/forumdisplay.php?46-CodeBank-Visual-Basic-NET">CodeBank - Visual Basic .NET</category>
			<dc:creator>s8514</dc:creator>
			<guid isPermaLink="true">http://www.vbforums.com/showthread.php?721159-Play-Shoutcast-radios-stations-(vb-net-2010)</guid>
		</item>
		<item>
			<title>Simple Winsock client/server file uploader demo.</title>
			<link>http://www.vbforums.com/showthread.php?721075-Simple-Winsock-client-server-file-uploader-demo&amp;goto=newpost</link>
			<pubDate>Thu, 09 May 2013 20:05:29 GMT</pubDate>
			<description><![CDATA[Recently I've seen a few about questions sending data using Winsock across a network and a lot of the times people have trouble figuring out when their data has been fully sent/received or if there is more. TCP/IP being a streaming protocol, doesn't lend itself well to this. My answer is to implement your own scheme to do this over TCP/IP. It usually involves sending a length prefix along with the data so the receiver can count the bytes to determine when it has received all the data.

The attached applications are a client application and a server application that can transfer a file between them. The client application sends the file and the server receives the file and saves it to a configurable location. I've set default values that should allow you to test the programs right away on the same machine using the loop back adapter.

You must start both applications and click the "listen" button on the server and then you click the "connect" button on the client application and the status bars of both application should read "connected" if it succeeds. From there you click the "upload" button on the client application and select a file using the dialog that pops up. The client should begin the upload after selecting a file. I recommend using a large file to see the progress. The loopback and even LAN is very fast so small files will be transferred instantly.

Note: These applications were created using Visual Studio 2010 so you would need that or later to open the projects.

On last thing. The apps are not meant to be usable. They are made to demonstrate the basic idea behind creating your own protocols for data transfer. In an effort to keep it as simple as possible I didn't add too many complexities to it. The sever is limited to being able to accept one connection and there can only be one file transfer at a time. It cannot in its current state transfer multiple files at the same time. Also, I did not put too many error traps so expect that if you push it by doing weird things, it will crash.

Feel free to ask any questions about it. Any suggestions to improve it will also be welcomed.]]></description>
			<content:encoded><![CDATA[<div>Recently I've seen a few about questions sending data using Winsock across a network and a lot of the times people have trouble figuring out when their data has been fully sent/received or if there is more. TCP/IP being a streaming protocol, doesn't lend itself well to this. My answer is to implement your own scheme to do this over TCP/IP. It usually involves sending a length prefix along with the data so the receiver can count the bytes to determine when it has received all the data.<br />
<br />
The attached applications are a client application and a server application that can transfer a file between them. The client application sends the file and the server receives the file and saves it to a configurable location. I've set default values that should allow you to test the programs right away on the same machine using the loop back adapter.<br />
<br />
You must start both applications and click the &quot;listen&quot; button on the server and then you click the &quot;connect&quot; button on the client application and the status bars of both application should read &quot;connected&quot; if it succeeds. From there you click the &quot;upload&quot; button on the client application and select a file using the dialog that pops up. The client should begin the upload after selecting a file. I recommend using a large file to see the progress. The loopback and even LAN is very fast so small files will be transferred instantly.<br />
<br />
Note: These applications were created using Visual Studio 2010 so you would need that or later to open the projects.<br />
<br />
On last thing. The apps are not meant to be usable. They are made to demonstrate the basic idea behind creating your own protocols for data transfer. In an effort to keep it as simple as possible I didn't add too many complexities to it. The sever is limited to being able to accept one connection and there can only be one file transfer at a time. It cannot in its current state transfer multiple files at the same time. Also, I did not put too many error traps so expect that if you push it by doing weird things, it will crash.<br />
<br />
Feel free to ask any questions about it. Any suggestions to improve it will also be welcomed.</div>


	<div style="padding:10px">

	

	

	

	
		<fieldset class="fieldset">
			<legend>Attached Files</legend>
			<ul>
			<li>
	<img class="inlineimg" src="http://www.vbforums.com/images/attach/zip.gif" alt="File Type: zip" />
	<a href="http://www.vbforums.com/attachment.php?attachmentid=99881&amp;d=1368129919">Winsock Demo.zip</a> 
(40.0 KB)
</li>
			</ul>
		</fieldset>
	

	</div>
]]></content:encoded>
			<category domain="http://www.vbforums.com/forumdisplay.php?46-CodeBank-Visual-Basic-NET">CodeBank - Visual Basic .NET</category>
			<dc:creator>Niya</dc:creator>
			<guid isPermaLink="true">http://www.vbforums.com/showthread.php?721075-Simple-Winsock-client-server-file-uploader-demo</guid>
		</item>
		<item>
			<title>SQL Databases Create, Update, and Query</title>
			<link>http://www.vbforums.com/showthread.php?720695-SQL-Databases-Create-Update-and-Query&amp;goto=newpost</link>
			<pubDate>Mon, 06 May 2013 15:00:11 GMT</pubDate>
			<description><![CDATA[One thing Visual Basic has always been good at is interacting with databases. VB.NET continues this great tradition. In fact this tutorial and source sample shows how you can create a SQL database, create a Table, create a Stored Procedure to populate the Table, , Create a View, and Execute the Stored Procedure to insert sample data. Lastly we will see how we can query the data using the View we created and store this into a DataSet and then display it in a DataGridView.

Before we start I recommend you download the source code sample and follow along:

Database Sample Source Code

The Connection String

The first step to any database handling code in VB.NET is to figure out your connection string so you can get to the database. In a real application this value is usually read from a configuration file or gathered from the user in some way. For a simple sample like ours we will just declare the string as a constant at the top of our file (See line 13 of Form1.vb).

Protected Const SqlConnectionString As String = _
	"Server=(local);" & _
	"DataBase=;" & _
	"Integrated Security=SSPI"

Notice that the connection string has information about what server to hit, what default database to use, and security information. In our case we are telling it to hit our local SQL server, we don’t want to use a default DataBase, and we will use Integrated Security. This means that you need to be running as a user that has access to your SQL server (if all else fails try running Visual Studio as Administrator).

Note: If you have SQL Server Express installed you might need to modify the connection string to look like this:

Protected Const SqlConnectionString As String = _
	"Server=(local)\sqlexpress;" & _
	"DataBase=;" & _
	"Integrated Security=SSPI"

The Sample UI

If you look at the sample source code provided with this article you will see a simple form that has six buttons on it. Each button demonstrates a different Database task we can do using VB.NET.

image

The tasks we will be covering in this sample and tutorial are:

    Create the Database we will put everything in
    Create the Table that will store our actual data
    Create the SPROC (Stored Procedure) that we will use to populate our table with some data
    Create the View that we will query to look at our data
    Populate our Table with data using our Store Procedure
    Lastly query our data, put it in a DataSet, and then display it in the GridView control

Create The Database

Creating a database in VB.NET is relatively straight forward. The key is to know the SQL code to create the database. With this we can create a SqlConnection to our Sql Server (using our connection string above), Create a Sql Command, and execute the SQL code to create the Database.

You can see an example of this in our VB.NET Source sample’s CreateDatabase Subroutine (around line 55):

Dim sqlStatement As String = _
	"IF EXISTS (" & _
	"SELECT * " & _
	"FROM master..sysdatabases " & _
	"WHERE Name = 'HowToDemo')" & vbCrLf & _
	"DROP DATABASE HowToDemo" & vbCrLf & _
	"CREATE DATABASE HowToDemo"
 
 Dim connection As New SqlConnection(connectionString)
 
' A SqlCommand object is used to execute the SQL commands.
Dim cmd As New SqlCommand(sqlStatement, connection)
 
connection.Open()
cmd.ExecuteNonQuery()
connection.Close()

The SQL portion of this code checks to see if the “HowToDemo” database exists already. If it does we drop the old database. We then create the HowToDemo database. Notice that for the VB.NET code we create a SqlConnection object and point it to our server using the connectionString we created earlier. We then create a SqlCommand object and tell it to use the SQL code we created above and the connection we already created. Finally once everything is set up we open the connection, execute our SQL code, and then close the connection. Notice we call the ExecuteNonQuery method on the SqlCommand object. This method is the fastest one to call as all it does is “blindly” executes the SQL code and doesn’t return anything back to us.

Create The Table

Now that we have a database created we need to create a table that will have our rows of data in it. For those of you that aren’t familiar with databases you can kind of think of them like Excel Spreadsheets on steroids. Each Table would be one sheet in Excel. It would have column headers (which are called Fields in SQL Server) and it would have rows of data. If you look at the code in the click event handler for the Create Table button you will see how we create a new table called Contact (Around line 144).

Dim strSQL As String = _
	"USE HowToDemo" & vbCrLf & _
	"IF EXISTS (" & _
	"SELECT * " & _
	"FROM HowToDemo.dbo.sysobjects " & _
	"WHERE Name = 'Contact' " & _
	"AND TYPE = 'u')" & vbCrLf & _
	"BEGIN" & vbCrLf & _
	"DROP TABLE HowToDemo.dbo.Contact" & vbCrLf & _
	"END" & vbCrLf & _
	"CREATE TABLE Contact (" & _
	"ContactID Int NOT NULL," & _
	"FirstName NVarChar(40) NOT NULL," & _
	"LastName NVarChar(40) NOT NULL" & ")"
 
Dim dbConnection As New SqlConnection(connectionString)
 
' A SqlCommand object is used to execute the SQL commands.
Dim cmd As New SqlCommand(strSQL, dbConnection)
 
dbConnection.Open()
cmd.ExecuteNonQuery()
dbConnection.Close()

The VB.NET portion of this code should look very familiar to you. In fact it looks the exact same as our code above for creating the database. The difference is in the SQL code. Notice that this time we check to see if the Table named Contact exists. If it does we drop the table and then re-create it. Our table will have 3 fields: ContactId, FirstName, and LastName.

Create The Stored Procedure (SPROC)

A stored procedure is like a subroutine (or procedure) that is stored in the database – hence the name. Stored procedures can be used for all sorts of things when doing database development. In our sample we are using it to populate our Contact table with some initial data. Here is what the code looks like to do this (See click handler for our Create Sproc Button – around line 206).

Dim dbConnection As New SqlConnection(connectionString)
 
Dim strSQL As String = _
	"USE HowToDemo" & vbCrLf & _
	"IF EXISTS (" & _
	"SELECT * " & _
	"FROM HowToDemo.dbo.sysobjects " & _
	"WHERE Name = 'AddContacts' " & _
	"AND TYPE = 'p')" & vbCrLf & _
	"BEGIN" & vbCrLf & _
	"DROP PROCEDURE AddContacts" & vbCrLf & _
	"END"
 
' A SqlCommand object is used to execute the SQL commands.
Dim cmd As New SqlCommand(strSQL, dbConnection)
 
dbConnection.Open()
cmd.ExecuteNonQuery()
 
cmd.CommandText = _
	"CREATE PROCEDURE AddContacts AS" & vbCrLf & _
	"INSERT INTO Contact" & vbCrLf & _
	"(ContactID, FirstName, LastName)" & _
	"SELECT EmployeeID, FirstName, LastName " & _
	"FROM Northwind.dbo.Employees"
 
cmd.ExecuteNonQuery()
dbConnection.Close()

By now this code should be making sense to you. Notice we are actually executing two commands this time. Also notice that we only open the connection once. We use that same connection for both command executions and then we close the connection. The first chunk of SQL we execute is similar to what we did before. We check to see if our stored procedure already exists. If it does we remove it.

The second command we execute is the SQL to create a new procedure. Notice all our procedure does is insert the values from the sample northwind database that Microsoft lets us use for free.

Important Note: If you don’t have the sample Northwind database installed when you go to populate the database (on Step 5) will see an error like this one:

image

If this happens you will either need to download and install the Northwind database or you can populate the table with just three contacts by replacing the create procedure SQL code above with this code:

cmd.CommandText = _
	"CREATE PROCEDURE AddContacts AS" & vbCrLf & _
	"INSERT INTO Contact" & vbCrLf & _
	"(ContactID, FirstName, LastName)" & _
	"SELECT 1, 'Joe', 'Smith' UNION " & _
	"SELECT 2, 'Billy', 'Bob' UNION " & _
	"SELECT 3, 'Jane', 'Doe'"

Create The View

A view is simply another way to look at data in a table. In our sample all our view does is returns everything from the table. In a real world application your views will often be much more complex. Displaying data from multiple tables with filters and other things applied. The code to create our view looks like this (In the Create View button click event – around line 274):

Dim dbConnection As New SqlConnection(connectionString)
 
Dim strSQL As String = _
	"USE HowToDemo" & vbCrLf & _
	"IF EXISTS (" & _
	"SELECT * " & _
	"FROM HowToDemo.dbo.sysobjects " & _
	"WHERE Name = 'GetContacts' " & _
	"AND TYPE = 'v')" & vbCrLf & _
	"BEGIN" & vbCrLf & _
	"DROP VIEW GetContacts" & vbCrLf & _
	"END"
 
' A SqlCommand object is used to execute the SQL commands.
Dim cmd As New SqlCommand(strSQL, dbConnection)
 
dbConnection.Open()
cmd.ExecuteNonQuery()
 
cmd.CommandText = _
	"CREATE VIEW GetContacts AS " & _
	"SELECT * " & _
	"FROM Contact"
 
cmd.ExecuteNonQuery()
dbConnection.Close()

This code is about the same as all the earlier code so I’m not going to explain it in more detail.
Populate the Table with Data

Now that we have everything in place its an easy task for us to populate our table with some sample data. All we need to do is execute the stored procedure we created above. You can find the code for this in the Populate button’s click event (around line 333):

Dim strSQL As String = "EXECUTE HowToDemo.dbo.AddContacts"
 
Dim cmd As New SqlCommand(strSQL, dbConnection)
 
dbConnection.Open()
cmd.ExecuteNonQuery()
dbConnection.Close()

If when you go to run this code you get an exception see the note above. This is where the stored procedure you created is actually executed so if your Northwind database isn’t set up you will either have to set it up or use the work around I described above.
Display Data using a DataSet and a DataGrid

Now for the final step. Lets query our database and see the data we created. To start with lets take a look at the code to query the database and populate a DataSet (around line 389):

Dim strSQL As String = _
	"USE HowToDemo" & vbCrLf & _
	"SELECT * " & _
	"FROM GetContacts"
 
Dim dbConnection As New SqlConnection(connectionString)
 
' A SqlCommand object is used to execute the SQL commands.
Dim cmd As New SqlCommand(strSQL, dbConnection)
 
' The SqlDataAdapter is responsible for using a SqlCommand object to 
' fill a DataSet.
Dim da As New SqlDataAdapter(cmd)
Dim dsContacts As New DataSet()
da.Fill(dsContacts, "Contact")

Notice the beginning of this code looks very similar to what we’ve already seen. We make a connection to our database, create a Command, and set it up to use our SQL code and our connection. Notice the difference here though. Instead of executing our SqlCommand directly we instead pass it into our SqlDataAdapter. We then create our DataSet and use call the Fill function on our DataAdapter. The Fill method takes two parameters. The first is our DataSet we want to populate. The second parameter is the name of the Table – in our case Contact.

Now we have a DataSet that is filled with the contents of our table. Next we will get our DataGrid set up so that it will display our data:

With Me.DataGridView1
	.Visible = True
	.AutoGenerateColumns = False
	.AlternatingRowsDefaultCellStyle.BackColor = Color.Lavender
	.BackColor = Color.WhiteSmoke
	.ForeColor = Color.MidnightBlue
	.CellBorderStyle = DataGridViewCellBorderStyle.None
	.ColumnHeadersDefaultCellStyle.Font = New Font("Tahoma", 8.0!, FontStyle.Bold)
	.ColumnHeadersDefaultCellStyle.BackColor = Color.MidnightBlue
	.ColumnHeadersDefaultCellStyle.ForeColor = Color.WhiteSmoke
	.DefaultCellStyle.ForeColor = Color.MidnightBlue
	.DefaultCellStyle.BackColor = Color.WhiteSmoke
End With

Notice that we make our Grid visable we also set it to not Auto Generate its columns. The rest of the code is to just make the DataGrid look a little nicer as it displays our data.

Lastly we tell the Data Grid View to display our data:

Me.DataGridView1.DataSource = dsContacts.Tables(0)
Dim newColumn As Integer = Me.DataGridView1.Columns.Add("ContactID", "Contact ID")
Me.DataGridView1.Columns(newColumn).DataPropertyName = "ContactID"
 
newColumn = Me.DataGridView1.Columns.Add("FirstName", "First Name")
Me.DataGridView1.Columns(newColumn).DataPropertyName = "FirstName"
 
newColumn = Me.DataGridView1.Columns.Add("LastName", "Last Name")
Me.DataGridView1.Columns(newColumn).DataPropertyName = "LastName"

The first line of the code above is how you get data to show up in the Grid. You set its DataSource property. In our case we are setting it the first (and only) table in our DataSet we created before. Next we create Add a column to the DataGrid. Notice we keep track of the newColumn number so that we can reference it again and set its DataPropertyName. This value needs to match the FieldName of our table. We do this for all three columns and we are good to go.
Summary

Business applications and many other programs need to make use of Databases. This tutorial gave us a good introduction to how we can interact with SQL databases to store our data and to display it in the GridView control. If you haven’t already done so I recommend you donwload the source code sample below: …]]></description>
			<content:encoded><![CDATA[<div>One thing Visual Basic has always been good at is interacting with databases. VB.NET continues this great tradition. In fact this tutorial and source sample shows how you can create a SQL database, create a Table, create a Stored Procedure to populate the Table, , Create a View, and Execute the Stored Procedure to insert sample data. Lastly we will see how we can query the data using the View we created and store this into a DataSet and then display it in a DataGridView.<br />
<br />
Before we start I recommend you download the source code sample and follow along:<br />
<br />
Database Sample Source Code<br />
<br />
The Connection String<br />
<br />
The first step to any database handling code in VB.NET is to figure out your connection string so you can get to the database. In a real application this value is usually read from a configuration file or gathered from the user in some way. For a simple sample like ours we will just declare the string as a constant at the top of our file (See line 13 of Form1.vb).<br />
<br />
Protected Const SqlConnectionString As String = _<br />
	&quot;Server=(local);&quot; &amp; _<br />
	&quot;DataBase=;&quot; &amp; _<br />
	&quot;Integrated Security=SSPI&quot;<br />
<br />
Notice that the connection string has information about what server to hit, what default database to use, and security information. In our case we are telling it to hit our local SQL server, we don’t want to use a default DataBase, and we will use Integrated Security. This means that you need to be running as a user that has access to your SQL server (if all else fails try running Visual Studio as Administrator).<br />
<br />
Note: If you have SQL Server Express installed you might need to modify the connection string to look like this:<br />
<br />
Protected Const SqlConnectionString As String = _<br />
	&quot;Server=(local)\sqlexpress;&quot; &amp; _<br />
	&quot;DataBase=;&quot; &amp; _<br />
	&quot;Integrated Security=SSPI&quot;<br />
<br />
The Sample UI<br />
<br />
If you look at the sample source code provided with this article you will see a simple form that has six buttons on it. Each button demonstrates a different Database task we can do using VB.NET.<br />
<br />
image<br />
<br />
The tasks we will be covering in this sample and tutorial are:<br />
<br />
    Create the Database we will put everything in<br />
    Create the Table that will store our actual data<br />
    Create the SPROC (Stored Procedure) that we will use to populate our table with some data<br />
    Create the View that we will query to look at our data<br />
    Populate our Table with data using our Store Procedure<br />
    Lastly query our data, put it in a DataSet, and then display it in the GridView control<br />
<br />
Create The Database<br />
<br />
Creating a database in VB.NET is relatively straight forward. The key is to know the SQL code to create the database. With this we can create a SqlConnection to our Sql Server (using our connection string above), Create a Sql Command, and execute the SQL code to create the Database.<br />
<br />
You can see an example of this in our VB.NET Source sample’s CreateDatabase Subroutine (around line 55):<br />
<br />
Dim sqlStatement As String = _<br />
	&quot;IF EXISTS (&quot; &amp; _<br />
	&quot;SELECT * &quot; &amp; _<br />
	&quot;FROM master..sysdatabases &quot; &amp; _<br />
	&quot;WHERE Name = 'HowToDemo')&quot; &amp; vbCrLf &amp; _<br />
	&quot;DROP DATABASE HowToDemo&quot; &amp; vbCrLf &amp; _<br />
	&quot;CREATE DATABASE HowToDemo&quot;<br />
 <br />
 Dim connection As New SqlConnection(connectionString)<br />
 <br />
' A SqlCommand object is used to execute the SQL commands.<br />
Dim cmd As New SqlCommand(sqlStatement, connection)<br />
 <br />
connection.Open()<br />
cmd.ExecuteNonQuery()<br />
connection.Close()<br />
<br />
The SQL portion of this code checks to see if the “HowToDemo” database exists already. If it does we drop the old database. We then create the HowToDemo database. Notice that for the VB.NET code we create a SqlConnection object and point it to our server using the connectionString we created earlier. We then create a SqlCommand object and tell it to use the SQL code we created above and the connection we already created. Finally once everything is set up we open the connection, execute our SQL code, and then close the connection. Notice we call the ExecuteNonQuery method on the SqlCommand object. This method is the fastest one to call as all it does is “blindly” executes the SQL code and doesn’t return anything back to us.<br />
<br />
Create The Table<br />
<br />
Now that we have a database created we need to create a table that will have our rows of data in it. For those of you that aren’t familiar with databases you can kind of think of them like Excel Spreadsheets on steroids. Each Table would be one sheet in Excel. It would have column headers (which are called Fields in SQL Server) and it would have rows of data. If you look at the code in the click event handler for the Create Table button you will see how we create a new table called Contact (Around line 144).<br />
<br />
Dim strSQL As String = _<br />
	&quot;USE HowToDemo&quot; &amp; vbCrLf &amp; _<br />
	&quot;IF EXISTS (&quot; &amp; _<br />
	&quot;SELECT * &quot; &amp; _<br />
	&quot;FROM HowToDemo.dbo.sysobjects &quot; &amp; _<br />
	&quot;WHERE Name = 'Contact' &quot; &amp; _<br />
	&quot;AND TYPE = 'u')&quot; &amp; vbCrLf &amp; _<br />
	&quot;BEGIN&quot; &amp; vbCrLf &amp; _<br />
	&quot;DROP TABLE HowToDemo.dbo.Contact&quot; &amp; vbCrLf &amp; _<br />
	&quot;END&quot; &amp; vbCrLf &amp; _<br />
	&quot;CREATE TABLE Contact (&quot; &amp; _<br />
	&quot;ContactID Int NOT NULL,&quot; &amp; _<br />
	&quot;FirstName NVarChar(40) NOT NULL,&quot; &amp; _<br />
	&quot;LastName NVarChar(40) NOT NULL&quot; &amp; &quot;)&quot;<br />
 <br />
Dim dbConnection As New SqlConnection(connectionString)<br />
 <br />
' A SqlCommand object is used to execute the SQL commands.<br />
Dim cmd As New SqlCommand(strSQL, dbConnection)<br />
 <br />
dbConnection.Open()<br />
cmd.ExecuteNonQuery()<br />
dbConnection.Close()<br />
<br />
The VB.NET portion of this code should look very familiar to you. In fact it looks the exact same as our code above for creating the database. The difference is in the SQL code. Notice that this time we check to see if the Table named Contact exists. If it does we drop the table and then re-create it. Our table will have 3 fields: ContactId, FirstName, and LastName.<br />
<br />
Create The Stored Procedure (SPROC)<br />
<br />
A stored procedure is like a subroutine (or procedure) that is stored in the database – hence the name. Stored procedures can be used for all sorts of things when doing database development. In our sample we are using it to populate our Contact table with some initial data. Here is what the code looks like to do this (See click handler for our Create Sproc Button – around line 206).<br />
<br />
Dim dbConnection As New SqlConnection(connectionString)<br />
 <br />
Dim strSQL As String = _<br />
	&quot;USE HowToDemo&quot; &amp; vbCrLf &amp; _<br />
	&quot;IF EXISTS (&quot; &amp; _<br />
	&quot;SELECT * &quot; &amp; _<br />
	&quot;FROM HowToDemo.dbo.sysobjects &quot; &amp; _<br />
	&quot;WHERE Name = 'AddContacts' &quot; &amp; _<br />
	&quot;AND TYPE = 'p')&quot; &amp; vbCrLf &amp; _<br />
	&quot;BEGIN&quot; &amp; vbCrLf &amp; _<br />
	&quot;DROP PROCEDURE AddContacts&quot; &amp; vbCrLf &amp; _<br />
	&quot;END&quot;<br />
 <br />
' A SqlCommand object is used to execute the SQL commands.<br />
Dim cmd As New SqlCommand(strSQL, dbConnection)<br />
 <br />
dbConnection.Open()<br />
cmd.ExecuteNonQuery()<br />
 <br />
cmd.CommandText = _<br />
	&quot;CREATE PROCEDURE AddContacts AS&quot; &amp; vbCrLf &amp; _<br />
	&quot;INSERT INTO Contact&quot; &amp; vbCrLf &amp; _<br />
	&quot;(ContactID, FirstName, LastName)&quot; &amp; _<br />
	&quot;SELECT EmployeeID, FirstName, LastName &quot; &amp; _<br />
	&quot;FROM Northwind.dbo.Employees&quot;<br />
 <br />
cmd.ExecuteNonQuery()<br />
dbConnection.Close()<br />
<br />
By now this code should be making sense to you. Notice we are actually executing two commands this time. Also notice that we only open the connection once. We use that same connection for both command executions and then we close the connection. The first chunk of SQL we execute is similar to what we did before. We check to see if our stored procedure already exists. If it does we remove it.<br />
<br />
The second command we execute is the SQL to create a new procedure. Notice all our procedure does is insert the values from the sample northwind database that Microsoft lets us use for free.<br />
<br />
Important Note: If you don’t have the sample Northwind database installed when you go to populate the database (on Step 5) will see an error like this one:<br />
<br />
image<br />
<br />
If this happens you will either need to download and install the Northwind database or you can populate the table with just three contacts by replacing the create procedure SQL code above with this code:<br />
<br />
cmd.CommandText = _<br />
	&quot;CREATE PROCEDURE AddContacts AS&quot; &amp; vbCrLf &amp; _<br />
	&quot;INSERT INTO Contact&quot; &amp; vbCrLf &amp; _<br />
	&quot;(ContactID, FirstName, LastName)&quot; &amp; _<br />
	&quot;SELECT 1, 'Joe', 'Smith' UNION &quot; &amp; _<br />
	&quot;SELECT 2, 'Billy', 'Bob' UNION &quot; &amp; _<br />
	&quot;SELECT 3, 'Jane', 'Doe'&quot;<br />
<br />
Create The View<br />
<br />
A view is simply another way to look at data in a table. In our sample all our view does is returns everything from the table. In a real world application your views will often be much more complex. Displaying data from multiple tables with filters and other things applied. The code to create our view looks like this (In the Create View button click event – around line 274):<br />
<br />
Dim dbConnection As New SqlConnection(connectionString)<br />
 <br />
Dim strSQL As String = _<br />
	&quot;USE HowToDemo&quot; &amp; vbCrLf &amp; _<br />
	&quot;IF EXISTS (&quot; &amp; _<br />
	&quot;SELECT * &quot; &amp; _<br />
	&quot;FROM HowToDemo.dbo.sysobjects &quot; &amp; _<br />
	&quot;WHERE Name = 'GetContacts' &quot; &amp; _<br />
	&quot;AND TYPE = 'v')&quot; &amp; vbCrLf &amp; _<br />
	&quot;BEGIN&quot; &amp; vbCrLf &amp; _<br />
	&quot;DROP VIEW GetContacts&quot; &amp; vbCrLf &amp; _<br />
	&quot;END&quot;<br />
 <br />
' A SqlCommand object is used to execute the SQL commands.<br />
Dim cmd As New SqlCommand(strSQL, dbConnection)<br />
 <br />
dbConnection.Open()<br />
cmd.ExecuteNonQuery()<br />
 <br />
cmd.CommandText = _<br />
	&quot;CREATE VIEW GetContacts AS &quot; &amp; _<br />
	&quot;SELECT * &quot; &amp; _<br />
	&quot;FROM Contact&quot;<br />
 <br />
cmd.ExecuteNonQuery()<br />
dbConnection.Close()<br />
<br />
This code is about the same as all the earlier code so I’m not going to explain it in more detail.<br />
Populate the Table with Data<br />
<br />
Now that we have everything in place its an easy task for us to populate our table with some sample data. All we need to do is execute the stored procedure we created above. You can find the code for this in the Populate button’s click event (around line 333):<br />
<br />
Dim strSQL As String = &quot;EXECUTE HowToDemo.dbo.AddContacts&quot;<br />
 <br />
Dim cmd As New SqlCommand(strSQL, dbConnection)<br />
 <br />
dbConnection.Open()<br />
cmd.ExecuteNonQuery()<br />
dbConnection.Close()<br />
<br />
If when you go to run this code you get an exception see the note above. This is where the stored procedure you created is actually executed so if your Northwind database isn’t set up you will either have to set it up or use the work around I described above.<br />
Display Data using a DataSet and a DataGrid<br />
<br />
Now for the final step. Lets query our database and see the data we created. To start with lets take a look at the code to query the database and populate a DataSet (around line 389):<br />
<br />
Dim strSQL As String = _<br />
	&quot;USE HowToDemo&quot; &amp; vbCrLf &amp; _<br />
	&quot;SELECT * &quot; &amp; _<br />
	&quot;FROM GetContacts&quot;<br />
 <br />
Dim dbConnection As New SqlConnection(connectionString)<br />
 <br />
' A SqlCommand object is used to execute the SQL commands.<br />
Dim cmd As New SqlCommand(strSQL, dbConnection)<br />
 <br />
' The SqlDataAdapter is responsible for using a SqlCommand object to <br />
' fill a DataSet.<br />
Dim da As New SqlDataAdapter(cmd)<br />
Dim dsContacts As New DataSet()<br />
da.Fill(dsContacts, &quot;Contact&quot;)<br />
<br />
Notice the beginning of this code looks very similar to what we’ve already seen. We make a connection to our database, create a Command, and set it up to use our SQL code and our connection. Notice the difference here though. Instead of executing our SqlCommand directly we instead pass it into our SqlDataAdapter. We then create our DataSet and use call the Fill function on our DataAdapter. The Fill method takes two parameters. The first is our DataSet we want to populate. The second parameter is the name of the Table – in our case Contact.<br />
<br />
Now we have a DataSet that is filled with the contents of our table. Next we will get our DataGrid set up so that it will display our data:<br />
<br />
With Me.DataGridView1<br />
	.Visible = True<br />
	.AutoGenerateColumns = False<br />
	.AlternatingRowsDefaultCellStyle.BackColor = Color.Lavender<br />
	.BackColor = Color.WhiteSmoke<br />
	.ForeColor = Color.MidnightBlue<br />
	.CellBorderStyle = DataGridViewCellBorderStyle.None<br />
	.ColumnHeadersDefaultCellStyle.Font = New Font(&quot;Tahoma&quot;, 8.0!, FontStyle.Bold)<br />
	.ColumnHeadersDefaultCellStyle.BackColor = Color.MidnightBlue<br />
	.ColumnHeadersDefaultCellStyle.ForeColor = Color.WhiteSmoke<br />
	.DefaultCellStyle.ForeColor = Color.MidnightBlue<br />
	.DefaultCellStyle.BackColor = Color.WhiteSmoke<br />
End With<br />
<br />
Notice that we make our Grid visable we also set it to not Auto Generate its columns. The rest of the code is to just make the DataGrid look a little nicer as it displays our data.<br />
<br />
Lastly we tell the Data Grid View to display our data:<br />
<br />
Me.DataGridView1.DataSource = dsContacts.Tables(0)<br />
Dim newColumn As Integer = Me.DataGridView1.Columns.Add(&quot;ContactID&quot;, &quot;Contact ID&quot;)<br />
Me.DataGridView1.Columns(newColumn).DataPropertyName = &quot;ContactID&quot;<br />
 <br />
newColumn = Me.DataGridView1.Columns.Add(&quot;FirstName&quot;, &quot;First Name&quot;)<br />
Me.DataGridView1.Columns(newColumn).DataPropertyName = &quot;FirstName&quot;<br />
 <br />
newColumn = Me.DataGridView1.Columns.Add(&quot;LastName&quot;, &quot;Last Name&quot;)<br />
Me.DataGridView1.Columns(newColumn).DataPropertyName = &quot;LastName&quot;<br />
<br />
The first line of the code above is how you get data to show up in the Grid. You set its DataSource property. In our case we are setting it the first (and only) table in our DataSet we created before. Next we create Add a column to the DataGrid. Notice we keep track of the newColumn number so that we can reference it again and set its DataPropertyName. This value needs to match the FieldName of our table. We do this for all three columns and we are good to go.<br />
Summary<br />
<br />
Business applications and many other programs need to make use of Databases. This tutorial gave us a good introduction to how we can interact with SQL databases to store our data and to display it in the GridView control. If you haven’t already done so I recommend you donwload the source code sample below: …</div>

]]></content:encoded>
			<category domain="http://www.vbforums.com/forumdisplay.php?46-CodeBank-Visual-Basic-NET">CodeBank - Visual Basic .NET</category>
			<dc:creator>skyman2610</dc:creator>
			<guid isPermaLink="true">http://www.vbforums.com/showthread.php?720695-SQL-Databases-Create-Update-and-Query</guid>
		</item>
		<item>
			<title>Syntax Highlighter</title>
			<link>http://www.vbforums.com/showthread.php?720119-Syntax-Highlighter&amp;goto=newpost</link>
			<pubDate>Wed, 01 May 2013 18:48:26 GMT</pubDate>
			<description><![CDATA[I've been around the forums now for quite a while, and something I see come up quite regularly is someone wanting to develop an IDE. Well an IDE is *_very_* hard work, take visual studio's for example. Visual Studio's has intellisense, syntax highlighting, compiler... the list goes on! Well I've taken it upon my self to at least knock out one portion for those wanting to take on the challenge and that's the syntax highlighter.
*_The pro's:_*

* Highlights syntax in a pure managed .Net way!



*_The con's:_*

* It's not complete, I will constantly work on it
* Sort of a memory hog!



The way I do it is first set up a textfile and have it in a Token{delimiter}Color format. So in my example I post the text file I use looks like this:

---Quote---
<html>,Goldenrod
</html>,Goldenrod
<head>,Goldenrod
</head>,Goldenrod
<body>,Goldenrod
</body>,Goldenrod
<title>,CornflowerBlue
</title>,CornflowerBlue
<h1>,CornflowerBlue
</h1>,CornflowerBlue
<h2>,CornflowerBlue
</h2>,CornflowerBlue
<h3>,CornflowerBlue
</h3>,CornflowerBlue
<h4>,CornflowerBlue
</h4>,CornflowerBlue
<h5>,CornflowerBlue
</h5>,CornflowerBlue
<h6>,CornflowerBlue
</h6>,CornflowerBlue
<p>,CornflowerBlue
</p>,CornflowerBlue
<br/>,BlueViolet
<hr/>,BlueViolet
<div>,CornflowerBlue
</div>,CornflowerBlue
<ol>,CornflowerBlue
</ol>,CornflowerBlue
<li>,CornflowerBlue
</li>,CornflowerBlue
---End Quote---
What I do next is declare a Dictionary(Of String, Color). Then fill that dictionary using this function:

Code:
---------
    Private Function txt_to_dictionary(ByVal content As String, ByVal delimiter As String) As Dictionary(Of String, Color)
        'Declare a new instance of a dictionary
        Dim dic As New Dictionary(Of String, Color)

        'Split up the content by the newline b/c in our textfile we have:
        'value,color
        'value,color
        'etc.
        Dim str() As String = content.Split({Environment.NewLine}, StringSplitOptions.RemoveEmptyEntries)

        'Return nothing if there's nothing in the content
        If str.Count = -1 Then
            Return Nothing
        End If

        'Iterate through each row, or line
        For rows As Integer = 0 To str.Count - 1
            'Declare the token and color
            'We get the token by getting the substring from 0 to where the delimiter is
            'We get the color by getting the substring from where the delimiter + 1 is to the end
            Dim token As String = str(rows).Substring(0, str(rows).IndexOf(delimiter))
            Dim color As Color = color.FromName(str(rows).Substring(str(rows).IndexOf(delimiter) + 1))

            'Add it to our dictionary
            dic.Add(token, color)
        Next

        Return dic
    End Function
---------
 The reason I have ByVal content As String, instead of say ByVal filename As String and use a streamreader to read the contents of the text file is because when I use textfiles, I generally add them in My.Resources and that's simply not necessary. Finally in the text_changed event of a RichTextBox I add:

Code:
---------
        'Get the current location of the cursor
        Dim cursor_location As Integer = RichTextBox1.SelectionStart

        'Get the line we're editing
        Dim current_line As Integer = RichTextBox1.GetLineFromCharIndex(cursor_location)

        'Iterate through each token
        For Each token As String In token_dictionary.Keys
            'If the line contains the token
            If RichTextBox1.Lines(current_line).Contains(token) Then
                'Select and color it
                RichTextBox1.Select(RichTextBox1.Find(token), token.Length)
                RichTextBox1.SelectionColor = token_dictionary(token)
            End If
        Next

        'Finally set the selection color back to black and set the cursor wher it was
        RichTextBox1.SelectionStart = cursor_location
        RichTextBox1.SelectionLength = 0
        RichTextBox1.SelectionColor = Color.Black
---------
All in all, the final code looks like this:

Code:
---------
'Come on now, everyone needs Option Strict/Explicit ON!
Option Strict On
Option Explicit On
Public Class Form1
    Private token_dictionary As Dictionary(Of String, Color)

    Private Function txt_to_dictionary(ByVal content As String, ByVal delimiter As String) As Dictionary(Of String, Color)
        'Declare a new instance of a dictionary
        Dim dic As New Dictionary(Of String, Color)

        'Split up the content by the newline b/c in our textfile we have:
        'value,color
        'value,color
        'etc.
        Dim str() As String = content.Split({Environment.NewLine}, StringSplitOptions.RemoveEmptyEntries)

        'Return nothing if there's nothing in the content
        If str.Count = -1 Then
            Return Nothing
        End If

        'Iterate through each row, or line
        For rows As Integer = 0 To str.Count - 1
            'Declare the token and color
            'We get the token by getting the substring from 0 to where the delimiter is
            'We get the color by getting the substring from where the delimiter + 1 is to the end
            Dim token As String = str(rows).Substring(0, str(rows).IndexOf(delimiter))
            Dim color As Color = color.FromName(str(rows).Substring(str(rows).IndexOf(delimiter) + 1))

            'Add it to our dictionary
            dic.Add(token, color)
        Next

        Return dic
    End Function


    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        token_dictionary = txt_to_dictionary(My.Resources.Tokens, ",")
    End Sub

    Private Sub RichTextBox1_TextChanged(sender As System.Object, e As System.EventArgs) Handles RichTextBox1.TextChanged
        'Get the current location of the cursor
        Dim cursor_location As Integer = RichTextBox1.SelectionStart

        'Get the line we're editing
        Dim current_line As Integer = RichTextBox1.GetLineFromCharIndex(cursor_location)

        'Iterate through each token
        For Each token As String In token_dictionary.Keys
            'If the line contains the token
            If RichTextBox1.Lines(current_line).Contains(token) Then
                'Select and color it
                RichTextBox1.Select(RichTextBox1.Find(token), token.Length)
                RichTextBox1.SelectionColor = token_dictionary(token)
            End If
        Next

        'Finally set the selection color back to black and set the cursor wher it was
        RichTextBox1.SelectionStart = cursor_location
        RichTextBox1.SelectionLength = 0
        RichTextBox1.SelectionColor = Color.Black

    End Sub
End Class
---------
To go back to the con's, one thing I haven't figured out yet is for strings. In most cases strings are defined by the text inside double quotation marks: "This is a string!". The problem with my method is that I haven't figured out how to highlight both the double quote and everything inside of it yet. But like I said this is a work in progress, but a good jumping point. Here is an image of the work in progress:
Attachment 99685 (http://www.vbforums.com/attachment.php?attachmentid=99685)]]></description>
			<content:encoded><![CDATA[<div>I've been around the forums now for quite a while, and something I see come up quite regularly is someone wanting to develop an IDE. Well an IDE is <b><u>very</u></b> hard work, take visual studio's for example. Visual Studio's has intellisense, syntax highlighting, compiler... the list goes on! Well I've taken it upon my self to at least knock out one portion for those wanting to take on the challenge and that's the syntax highlighter.<br />
<b><u>The pro's:</u></b><br />
<ul><li style="">Highlights syntax in a pure managed .Net way!</li></ul><br />
<br />
<b><u>The con's:</u></b><br />
<ul><li style="">It's not complete, I will constantly work on it</li><li style="">Sort of a memory hog!</li></ul><br />
<br />
The way I do it is first set up a textfile and have it in a Token{delimiter}Color format. So in my example I post the text file I use looks like this:<br />
<div class="bbcode_container">
	<div class="bbcode_description">Quote:</div>
	<div class="bbcode_quote printable">
		<hr />
		
			&lt;html&gt;,Goldenrod<br />
&lt;/html&gt;,Goldenrod<br />
&lt;head&gt;,Goldenrod<br />
&lt;/head&gt;,Goldenrod<br />
&lt;body&gt;,Goldenrod<br />
&lt;/body&gt;,Goldenrod<br />
&lt;title&gt;,CornflowerBlue<br />
&lt;/title&gt;,CornflowerBlue<br />
&lt;h1&gt;,CornflowerBlue<br />
&lt;/h1&gt;,CornflowerBlue<br />
&lt;h2&gt;,CornflowerBlue<br />
&lt;/h2&gt;,CornflowerBlue<br />
&lt;h3&gt;,CornflowerBlue<br />
&lt;/h3&gt;,CornflowerBlue<br />
&lt;h4&gt;,CornflowerBlue<br />
&lt;/h4&gt;,CornflowerBlue<br />
&lt;h5&gt;,CornflowerBlue<br />
&lt;/h5&gt;,CornflowerBlue<br />
&lt;h6&gt;,CornflowerBlue<br />
&lt;/h6&gt;,CornflowerBlue<br />
&lt;p&gt;,CornflowerBlue<br />
&lt;/p&gt;,CornflowerBlue<br />
&lt;br/&gt;,BlueViolet<br />
&lt;hr/&gt;,BlueViolet<br />
&lt;div&gt;,CornflowerBlue<br />
&lt;/div&gt;,CornflowerBlue<br />
&lt;ol&gt;,CornflowerBlue<br />
&lt;/ol&gt;,CornflowerBlue<br />
&lt;li&gt;,CornflowerBlue<br />
&lt;/li&gt;,CornflowerBlue
			
		<hr />
	</div>
</div>What I do next is declare a Dictionary(Of String, Color). Then fill that dictionary using this function:<br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<hr /><code class="bbcode_code">&nbsp; &nbsp; Private Function txt_to_dictionary(ByVal content As String, ByVal delimiter As String) As Dictionary(Of String, Color)<br />
&nbsp; &nbsp; &nbsp; &nbsp; 'Declare a new instance of a dictionary<br />
&nbsp; &nbsp; &nbsp; &nbsp; Dim dic As New Dictionary(Of String, Color)<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; 'Split up the content by the newline b/c in our textfile we have:<br />
&nbsp; &nbsp; &nbsp; &nbsp; 'value,color<br />
&nbsp; &nbsp; &nbsp; &nbsp; 'value,color<br />
&nbsp; &nbsp; &nbsp; &nbsp; 'etc.<br />
&nbsp; &nbsp; &nbsp; &nbsp; Dim str() As String = content.Split({Environment.NewLine}, StringSplitOptions.RemoveEmptyEntries)<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; 'Return nothing if there's nothing in the content<br />
&nbsp; &nbsp; &nbsp; &nbsp; If str.Count = -1 Then<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Return Nothing<br />
&nbsp; &nbsp; &nbsp; &nbsp; End If<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; 'Iterate through each row, or line<br />
&nbsp; &nbsp; &nbsp; &nbsp; For rows As Integer = 0 To str.Count - 1<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'Declare the token and color<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'We get the token by getting the substring from 0 to where the delimiter is<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'We get the color by getting the substring from where the delimiter + 1 is to the end<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Dim token As String = str(rows).Substring(0, str(rows).IndexOf(delimiter))<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Dim color As Color = color.FromName(str(rows).Substring(str(rows).IndexOf(delimiter) + 1))<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'Add it to our dictionary<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dic.Add(token, color)<br />
&nbsp; &nbsp; &nbsp; &nbsp; Next<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; Return dic<br />
&nbsp; &nbsp; End Function</code><hr />
</div> The reason I have ByVal content As String, instead of say ByVal filename As String and use a streamreader to read the contents of the text file is because when I use textfiles, I generally add them in My.Resources and that's simply not necessary. Finally in the text_changed event of a RichTextBox I add:<br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<hr /><code class="bbcode_code">&nbsp; &nbsp; &nbsp; &nbsp; 'Get the current location of the cursor<br />
&nbsp; &nbsp; &nbsp; &nbsp; Dim cursor_location As Integer = RichTextBox1.SelectionStart<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; 'Get the line we're editing<br />
&nbsp; &nbsp; &nbsp; &nbsp; Dim current_line As Integer = RichTextBox1.GetLineFromCharIndex(cursor_location)<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; 'Iterate through each token<br />
&nbsp; &nbsp; &nbsp; &nbsp; For Each token As String In token_dictionary.Keys<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'If the line contains the token<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; If RichTextBox1.Lines(current_line).Contains(token) Then<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'Select and color it<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; RichTextBox1.Select(RichTextBox1.Find(token), token.Length)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; RichTextBox1.SelectionColor = token_dictionary(token)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; End If<br />
&nbsp; &nbsp; &nbsp; &nbsp; Next<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; 'Finally set the selection color back to black and set the cursor wher it was<br />
&nbsp; &nbsp; &nbsp; &nbsp; RichTextBox1.SelectionStart = cursor_location<br />
&nbsp; &nbsp; &nbsp; &nbsp; RichTextBox1.SelectionLength = 0<br />
&nbsp; &nbsp; &nbsp; &nbsp; RichTextBox1.SelectionColor = Color.Black</code><hr />
</div>All in all, the final code looks like this:<br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<hr /><code class="bbcode_code">'Come on now, everyone needs Option Strict/Explicit ON!<br />
Option Strict On<br />
Option Explicit On<br />
Public Class Form1<br />
&nbsp; &nbsp; Private token_dictionary As Dictionary(Of String, Color)<br />
<br />
&nbsp; &nbsp; Private Function txt_to_dictionary(ByVal content As String, ByVal delimiter As String) As Dictionary(Of String, Color)<br />
&nbsp; &nbsp; &nbsp; &nbsp; 'Declare a new instance of a dictionary<br />
&nbsp; &nbsp; &nbsp; &nbsp; Dim dic As New Dictionary(Of String, Color)<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; 'Split up the content by the newline b/c in our textfile we have:<br />
&nbsp; &nbsp; &nbsp; &nbsp; 'value,color<br />
&nbsp; &nbsp; &nbsp; &nbsp; 'value,color<br />
&nbsp; &nbsp; &nbsp; &nbsp; 'etc.<br />
&nbsp; &nbsp; &nbsp; &nbsp; Dim str() As String = content.Split({Environment.NewLine}, StringSplitOptions.RemoveEmptyEntries)<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; 'Return nothing if there's nothing in the content<br />
&nbsp; &nbsp; &nbsp; &nbsp; If str.Count = -1 Then<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Return Nothing<br />
&nbsp; &nbsp; &nbsp; &nbsp; End If<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; 'Iterate through each row, or line<br />
&nbsp; &nbsp; &nbsp; &nbsp; For rows As Integer = 0 To str.Count - 1<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'Declare the token and color<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'We get the token by getting the substring from 0 to where the delimiter is<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'We get the color by getting the substring from where the delimiter + 1 is to the end<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Dim token As String = str(rows).Substring(0, str(rows).IndexOf(delimiter))<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Dim color As Color = color.FromName(str(rows).Substring(str(rows).IndexOf(delimiter) + 1))<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'Add it to our dictionary<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dic.Add(token, color)<br />
&nbsp; &nbsp; &nbsp; &nbsp; Next<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; Return dic<br />
&nbsp; &nbsp; End Function<br />
<br />
<br />
&nbsp; &nbsp; Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load<br />
&nbsp; &nbsp; &nbsp; &nbsp; token_dictionary = txt_to_dictionary(My.Resources.Tokens, &quot;,&quot;)<br />
&nbsp; &nbsp; End Sub<br />
<br />
&nbsp; &nbsp; Private Sub RichTextBox1_TextChanged(sender As System.Object, e As System.EventArgs) Handles RichTextBox1.TextChanged<br />
&nbsp; &nbsp; &nbsp; &nbsp; 'Get the current location of the cursor<br />
&nbsp; &nbsp; &nbsp; &nbsp; Dim cursor_location As Integer = RichTextBox1.SelectionStart<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; 'Get the line we're editing<br />
&nbsp; &nbsp; &nbsp; &nbsp; Dim current_line As Integer = RichTextBox1.GetLineFromCharIndex(cursor_location)<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; 'Iterate through each token<br />
&nbsp; &nbsp; &nbsp; &nbsp; For Each token As String In token_dictionary.Keys<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'If the line contains the token<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; If RichTextBox1.Lines(current_line).Contains(token) Then<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'Select and color it<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; RichTextBox1.Select(RichTextBox1.Find(token), token.Length)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; RichTextBox1.SelectionColor = token_dictionary(token)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; End If<br />
&nbsp; &nbsp; &nbsp; &nbsp; Next<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; 'Finally set the selection color back to black and set the cursor wher it was<br />
&nbsp; &nbsp; &nbsp; &nbsp; RichTextBox1.SelectionStart = cursor_location<br />
&nbsp; &nbsp; &nbsp; &nbsp; RichTextBox1.SelectionLength = 0<br />
&nbsp; &nbsp; &nbsp; &nbsp; RichTextBox1.SelectionColor = Color.Black<br />
<br />
&nbsp; &nbsp; End Sub<br />
End Class</code><hr />
</div>To go back to the con's, one thing I haven't figured out yet is for strings. In most cases strings are defined by the text inside double quotation marks: <font color="#FF0000">&quot;This is a string!&quot;</font>. The problem with my method is that I haven't figured out how to highlight both the double quote and everything inside of it yet. But like I said this is a work in progress, but a good jumping point. Here is an image of the work in progress:<br />
<img src="http://www.vbforums.com/attachment.php?attachmentid=99685&amp;d=1367434103" border="0" alt="Name:  syntax highlighter.png
Views: 115
Size:  24.1 KB"  /></div>


	<div style="padding:10px">

	

	
		<fieldset class="fieldset">
			<legend>Attached Images</legend>
				<div style="padding:10px">
				<img class="attach" src="http://www.vbforums.com/attachment.php?attachmentid=99685&amp;stc=1&amp;d=1367434103" alt="" />&nbsp;
			</div>
		</fieldset>
	

	

	

	</div>
]]></content:encoded>
			<category domain="http://www.vbforums.com/forumdisplay.php?46-CodeBank-Visual-Basic-NET">CodeBank - Visual Basic .NET</category>
			<dc:creator>dday9</dc:creator>
			<guid isPermaLink="true">http://www.vbforums.com/showthread.php?720119-Syntax-Highlighter</guid>
		</item>
		<item>
			<title>Converting textfile to datatable and converting datatable to textfile</title>
			<link>http://www.vbforums.com/showthread.php?719825-Converting-textfile-to-datatable-and-converting-datatable-to-textfile&amp;goto=newpost</link>
			<pubDate>Mon, 29 Apr 2013 18:27:00 GMT</pubDate>
			<description><![CDATA[I wrote a function that will convert the contents of a text file to a datatable:

Code:
---------
    Private Function txt_to_data(ByVal filename As String, ByVal header As Boolean, ByVal delimiter As String) As DataTable
        'New datatable
        Dim dt As New DataTable

        'Read the contents of the textfile into an array
        Dim sr As New IO.StreamReader(filename)
        Dim txtlines() As String = sr.ReadToEnd.Split({Environment.NewLine}, StringSplitOptions.RemoveEmptyEntries)

        'Return nothing if there's nothing in the textfile
        If txtlines.Count = -1 Then
            Return Nothing
        End If

        Dim column_count As Integer = 0
        For Each col As String In txtlines(0).Split({delimiter}, StringSplitOptions.None)
            If header Then
                'If there's a header then add it by it's name
                dt.Columns.Add(col)
                dt.Columns(column_count).Caption = col
            Else
                'If there's no header then add it by the column count
                dt.Columns.Add(String.Format("Column{0}", column_count))
                dt.Columns(column_count).Caption = String.Format("Column{0}", column_count + 1)
            End If

            column_count += 1
        Next

        If header Then
            For rows As Integer = 1 To txtlines.Count - 1 'start at one because there's a header for the first line(0)
                'Declare a new datarow
                Dim dr As DataRow = dt.NewRow

                'Set the column count back to 0, we can reuse this variable ;]
                column_count = 0
                For Each col As String In txtlines(rows).Split({delimiter}, StringSplitOptions.None) 'Each column in the row
                    'The column in cue is set for the datarow
                    dr(column_count) = col
                    column_count += 1
                Next

                'Add the row
                dt.Rows.Add(dr)
            Next
        Else
            For rows As Integer = 0 To txtlines.Count - 1 'start at zero because there's no header
                'Declare a new datarow
                Dim dr As DataRow = dt.NewRow

                'Set the column count back to 0, we can reuse this variable ;]
                column_count = 0
                For Each col As String In txtlines(rows).Split({delimiter}, StringSplitOptions.None) 'Each column in the row
                    'The column in cue is set for the datarow
                    dr(column_count) = col
                    column_count += 1
                Next

                'Add the row
                dt.Rows.Add(dr)
            Next
        End If

        Return dt
    End Function
---------
here is an instance of how to use it: Let's say you have a datagridview and for whatever reason the data you receive is a comma delimited with a header in the form of a text file. The user's requesting that they can chose the data file on-the-fly and display it in the datagridview by simply clicking a button. You'd use this:

Code:
---------
    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        Dim ofd As New OpenFileDialog
        With ofd
            .FileName = ""
            .Filter = "Text File|*.txt"
            .Multiselect = False
        End With

        If ofd.ShowDialog = Windows.Forms.DialogResult.OK Then
            Dim dt As DataTable = txt_to_data(ofd.FileName, True, ",")

            DataGridView1.DataSource = dt
        End If
    End Sub
---------
*_Update!_*
I've decided to add how to convert the datatable back to a textfile. This is the sub that I wrote:

Code:
---------
    Private Sub data_to_txt(ByVal dt As DataTable, ByVal filename As String, ByVal header As Boolean, ByVal delimiter As String)
        'New instance of a streamwriter
        Dim sw As New IO.StreamWriter(filename, False)

        'Exit if there's nothing in the textfile
        If dt.Columns.Count < 0 OrElse dt.Rows.Count < 0 Then
            Exit Sub
        End If

        If header Then
            For Each col As DataColumn In dt.Columns
                'Write the header
                sw.Write(col.Caption & delimiter)
            Next
            'Start a new line
            sw.WriteLine()
        End If

        'Loop through all the cells in the datatable
        For row As Integer = 0 To dt.Rows.Count - 1
            For col As Integer = 0 To dt.Columns.Count - 1

                sw.Write(dt.Rows(row).Item(col).ToString & delimiter)
            Next
            'At the final column, start a new line
            sw.Write(Environment.NewLine)
        Next

        'Close the streamwriter
        sw.Close()
    End Sub
---------
Here is an instance of how to use it: 

Code:
---------
    Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
        Dim sfd As New SaveFileDialog
        With sfd
            .FileName = ""
            .Filter = "Text File|*.txt"
        End With

        If sfd.ShowDialog = Windows.Forms.DialogResult.OK Then
            Call data_to_txt(dt, sfd.FileName, True, ",")
        End If

    End Sub
---------
I would advice against storing data into a textfile, but if you must here is a way to convert it to a datatable and back.]]></description>
			<content:encoded><![CDATA[<div>I wrote a function that will convert the contents of a text file to a datatable:<br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<hr /><code class="bbcode_code">&nbsp; &nbsp; Private Function txt_to_data(ByVal filename As String, ByVal header As Boolean, ByVal delimiter As String) As DataTable<br />
&nbsp; &nbsp; &nbsp; &nbsp; 'New datatable<br />
&nbsp; &nbsp; &nbsp; &nbsp; Dim dt As New DataTable<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; 'Read the contents of the textfile into an array<br />
&nbsp; &nbsp; &nbsp; &nbsp; Dim sr As New IO.StreamReader(filename)<br />
&nbsp; &nbsp; &nbsp; &nbsp; Dim txtlines() As String = sr.ReadToEnd.Split({Environment.NewLine}, StringSplitOptions.RemoveEmptyEntries)<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; 'Return nothing if there's nothing in the textfile<br />
&nbsp; &nbsp; &nbsp; &nbsp; If txtlines.Count = -1 Then<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Return Nothing<br />
&nbsp; &nbsp; &nbsp; &nbsp; End If<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; Dim column_count As Integer = 0<br />
&nbsp; &nbsp; &nbsp; &nbsp; For Each col As String In txtlines(0).Split({delimiter}, StringSplitOptions.None)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; If header Then<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'If there's a header then add it by it's name<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dt.Columns.Add(col)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dt.Columns(column_count).Caption = col<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Else<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'If there's no header then add it by the column count<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dt.Columns.Add(String.Format(&quot;Column{0}&quot;, column_count))<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dt.Columns(column_count).Caption = String.Format(&quot;Column{0}&quot;, column_count + 1)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; End If<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; column_count += 1<br />
&nbsp; &nbsp; &nbsp; &nbsp; Next<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; If header Then<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; For rows As Integer = 1 To txtlines.Count - 1 'start at one because there's a header for the first line(0)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'Declare a new datarow<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Dim dr As DataRow = dt.NewRow<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'Set the column count back to 0, we can reuse this variable ;]<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; column_count = 0<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; For Each col As String In txtlines(rows).Split({delimiter}, StringSplitOptions.None) 'Each column in the row<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'The column in cue is set for the datarow<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dr(column_count) = col<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; column_count += 1<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Next<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'Add the row<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dt.Rows.Add(dr)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Next<br />
&nbsp; &nbsp; &nbsp; &nbsp; Else<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; For rows As Integer = 0 To txtlines.Count - 1 'start at zero because there's no header<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'Declare a new datarow<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Dim dr As DataRow = dt.NewRow<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'Set the column count back to 0, we can reuse this variable ;]<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; column_count = 0<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; For Each col As String In txtlines(rows).Split({delimiter}, StringSplitOptions.None) 'Each column in the row<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'The column in cue is set for the datarow<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dr(column_count) = col<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; column_count += 1<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Next<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'Add the row<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dt.Rows.Add(dr)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Next<br />
&nbsp; &nbsp; &nbsp; &nbsp; End If<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; Return dt<br />
&nbsp; &nbsp; End Function</code><hr />
</div>here is an instance of how to use it: Let's say you have a datagridview and for whatever reason the data you receive is a comma delimited with a header in the form of a text file. The user's requesting that they can chose the data file on-the-fly and display it in the datagridview by simply clicking a button. You'd use this:<br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<hr /><code class="bbcode_code">&nbsp; &nbsp; Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click<br />
&nbsp; &nbsp; &nbsp; &nbsp; Dim ofd As New OpenFileDialog<br />
&nbsp; &nbsp; &nbsp; &nbsp; With ofd<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .FileName = &quot;&quot;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .Filter = &quot;Text File|*.txt&quot;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .Multiselect = False<br />
&nbsp; &nbsp; &nbsp; &nbsp; End With<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; If ofd.ShowDialog = Windows.Forms.DialogResult.OK Then<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Dim dt As DataTable = txt_to_data(ofd.FileName, True, &quot;,&quot;)<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; DataGridView1.DataSource = dt<br />
&nbsp; &nbsp; &nbsp; &nbsp; End If<br />
&nbsp; &nbsp; End Sub</code><hr />
</div><b><u><font size="4"><font color="#FF0000">Update!</font></font></u></b><br />
I've decided to add how to convert the datatable back to a textfile. This is the sub that I wrote:<br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<hr /><code class="bbcode_code">&nbsp; &nbsp; Private Sub data_to_txt(ByVal dt As DataTable, ByVal filename As String, ByVal header As Boolean, ByVal delimiter As String)<br />
&nbsp; &nbsp; &nbsp; &nbsp; 'New instance of a streamwriter<br />
&nbsp; &nbsp; &nbsp; &nbsp; Dim sw As New IO.StreamWriter(filename, False)<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; 'Exit if there's nothing in the textfile<br />
&nbsp; &nbsp; &nbsp; &nbsp; If dt.Columns.Count &lt; 0 OrElse dt.Rows.Count &lt; 0 Then<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Exit Sub<br />
&nbsp; &nbsp; &nbsp; &nbsp; End If<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; If header Then<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; For Each col As DataColumn In dt.Columns<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'Write the header<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sw.Write(col.Caption &amp; delimiter)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Next<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'Start a new line<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sw.WriteLine()<br />
&nbsp; &nbsp; &nbsp; &nbsp; End If<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; 'Loop through all the cells in the datatable<br />
&nbsp; &nbsp; &nbsp; &nbsp; For row As Integer = 0 To dt.Rows.Count - 1<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; For col As Integer = 0 To dt.Columns.Count - 1<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sw.Write(dt.Rows(row).Item(col).ToString &amp; delimiter)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Next<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'At the final column, start a new line<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sw.Write(Environment.NewLine)<br />
&nbsp; &nbsp; &nbsp; &nbsp; Next<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; 'Close the streamwriter<br />
&nbsp; &nbsp; &nbsp; &nbsp; sw.Close()<br />
&nbsp; &nbsp; End Sub</code><hr />
</div>Here is an instance of how to use it: <br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<hr /><code class="bbcode_code">&nbsp; &nbsp; Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click<br />
&nbsp; &nbsp; &nbsp; &nbsp; Dim sfd As New SaveFileDialog<br />
&nbsp; &nbsp; &nbsp; &nbsp; With sfd<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .FileName = &quot;&quot;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .Filter = &quot;Text File|*.txt&quot;<br />
&nbsp; &nbsp; &nbsp; &nbsp; End With<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; If sfd.ShowDialog = Windows.Forms.DialogResult.OK Then<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Call data_to_txt(dt, sfd.FileName, True, &quot;,&quot;)<br />
&nbsp; &nbsp; &nbsp; &nbsp; End If<br />
<br />
&nbsp; &nbsp; End Sub</code><hr />
</div>I would advice against storing data into a textfile, but if you must here is a way to convert it to a datatable and back.</div>

]]></content:encoded>
			<category domain="http://www.vbforums.com/forumdisplay.php?46-CodeBank-Visual-Basic-NET">CodeBank - Visual Basic .NET</category>
			<dc:creator>dday9</dc:creator>
			<guid isPermaLink="true">http://www.vbforums.com/showthread.php?719825-Converting-textfile-to-datatable-and-converting-datatable-to-textfile</guid>
		</item>
		<item>
			<title>TextBin.net - Extract text from binary files</title>
			<link>http://www.vbforums.com/showthread.php?719503-TextBin-net-Extract-text-from-binary-files&amp;goto=newpost</link>
			<pubDate>Fri, 26 Apr 2013 18:01:50 GMT</pubDate>
			<description><![CDATA[The attached program demonstrates how to extract strings containing only specific characters from a binary file. The project contains a class called TextBinClass and a form TextBinDemoModule.
 The class allows you to specify specific characters and extract these from a binary file. The module contains a demo which shows how to use this class and filter the resulting strings for specific things such as potential .dll references, e-mail addresses, GUIDs, names and URLs.

Notes:
-The term "Unicode" (within the context of this program) simply refers to any string where every other character is a null character. 
-The class is a .NET rewrite of http://www.vbforums.com/showthread.php?702693-TextBin-Extract-text-from-binary-files]]></description>
			<content:encoded><![CDATA[<div>The attached program demonstrates how to extract strings containing only specific characters from a binary file. The project contains a class called TextBinClass and a form TextBinDemoModule.<br />
 The class allows you to specify specific characters and extract these from a binary file. The module contains a demo which shows how to use this class and filter the resulting strings for specific things such as potential .dll references, e-mail addresses, GUIDs, names and URLs.<br />
<br />
Notes:<br />
-The term &quot;Unicode&quot; (within the context of this program) simply refers to any string where every other character is a null character. <br />
-The class is a .NET rewrite of <a rel="nofollow" href="http://www.vbforums.com/showthread.php?702693-TextBin-Extract-text-from-binary-files" target="_blank">http://www.vbforums.com/showthread.p...m-binary-files</a></div>


	<div style="padding:10px">

	

	

	

	
		<fieldset class="fieldset">
			<legend>Attached Files</legend>
			<ul>
			<li>
	<img class="inlineimg" src="http://www.vbforums.com/images/attach/zip.gif" alt="File Type: zip" />
	<a href="http://www.vbforums.com/attachment.php?attachmentid=99495&amp;d=1366999403">TextBin.net.zip</a> 
(12.4 KB)
</li>
			</ul>
		</fieldset>
	

	</div>
]]></content:encoded>
			<category domain="http://www.vbforums.com/forumdisplay.php?46-CodeBank-Visual-Basic-NET">CodeBank - Visual Basic .NET</category>
			<dc:creator>Peter Swinkels</dc:creator>
			<guid isPermaLink="true">http://www.vbforums.com/showthread.php?719503-TextBin-net-Extract-text-from-binary-files</guid>
		</item>
	</channel>
</rss>
