<?xml version="1.0" encoding="UTF-8"?>

<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 - Visual Basic .NET</title>
		<link>https://www.vbforums.com/</link>
		<description>Drop in here to discuss all editions and versions of Visual Basic .NET (2002 or later) or anything to do with VB .NET programming.</description>
		<language>en</language>
		<lastBuildDate>Thu, 04 Jun 2026 03:16:47 GMT</lastBuildDate>
		<generator>vBulletin</generator>
		<ttl>60</ttl>
		<image>
			<url>https://www.vbforums.com/images/misc/rss.png</url>
			<title>VBForums - Visual Basic .NET</title>
			<link>https://www.vbforums.com/</link>
		</image>
		<item>
			<title>Read from Registry to ListView1</title>
			<link>https://www.vbforums.com/showthread.php?912059-Read-from-Registry-to-ListView1&amp;goto=newpost</link>
			<pubDate>Tue, 02 Jun 2026 17:54:37 GMT</pubDate>
			<description><![CDATA[I am trying to populate a 2-column ListView using the registry key and data. I am able to "build" the listview and save to the registry. The first column of the list view is the registry subkey and the second column is the data.

This project sat idle for over 13 years and I am basically self-taught. Things have changed.

List View owner draw is true.
rootB is Public const = "HKCU\software\my sorter."
Registry is read from at this time.
There are currently 2 keys (profiles) where each key has 2 subkeys with assigned values (test mode).
The profile argument is the last saved profile.
There are stray comments that have not been removed - my apologies.
Program has issues at the line "GetSubKeyNames()".


Code:
---------
   Private Sub GetREG(ByRef profile As String)
      'If Registry.GetValue(rootB + "\" + profile, "", Nothing) <> Nothing Then

      'clear the ListView box
      ListView1.Items.Clear()

      'rebuild the ListView box
      MessageBox.Show("Profile in argument: " + profile) '===OK.

      Dim RegKey As RegistryKey = Registry.CurrentUser.OpenSubKey("SOFTWARE\My Sorter\" + profile)
      For Each Subkey As String In RegKey.GetSubKeyNames()
         'For Each Subkey In Subkeys
         Dim tempkey As RegistryKey = RegKey.OpenSubKey(Subkey)
         MessageBox.Show("subkey name: ", Subkey)
         'ListView1.Items.Add(Subkey, Registry.GetValue(rootB + "\" + profile, Subkey, ""))

         Dim listItem As New ListViewItem(tempkey.ToString)
         listItem.SubItems.Add(Registry.GetValue(rootB + "\" + profile, tempkey.ToString, ""))
         ListView1.Items.Add(listItem)

      Next
      RegKey.Close()

      'Else
      'MessageBox.Show("No GetValue: " + profile)
      'End If

   End Sub
---------
Nested parenthesis is nothing new to me and I will be able to do so if given the chance.]]></description>
			<content:encoded><![CDATA[<div>I am trying to populate a 2-column ListView using the registry key and data. I am able to &quot;build&quot; the listview and save to the registry. The first column of the list view is the registry subkey and the second column is the data.<br />
<br />
This project sat idle for over 13 years and I am basically self-taught. Things have changed.<br />
<br />
List View owner draw is true.<br />
rootB is Public const = &quot;HKCU\software\my sorter.&quot;<br />
Registry is read from at this time.<br />
There are currently 2 keys (profiles) where each key has 2 subkeys with assigned values (test mode).<br />
The profile argument is the last saved profile.<br />
There are stray comments that have not been removed - my apologies.<br />
Program has issues at the line &quot;GetSubKeyNames()&quot;.<br />
<br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<hr /><code class="bbcode_code">&nbsp;  Private Sub GetREG(ByRef profile As String)<br />
&nbsp; &nbsp; &nbsp; 'If Registry.GetValue(rootB + &quot;\&quot; + profile, &quot;&quot;, Nothing) &lt;&gt; Nothing Then<br />
<br />
&nbsp; &nbsp; &nbsp; 'clear the ListView box<br />
&nbsp; &nbsp; &nbsp; ListView1.Items.Clear()<br />
<br />
&nbsp; &nbsp; &nbsp; 'rebuild the ListView box<br />
&nbsp; &nbsp; &nbsp; MessageBox.Show(&quot;Profile in argument: &quot; + profile) <font color="#008000">'===OK.</font><br />
<br />
&nbsp; &nbsp; &nbsp; Dim RegKey As RegistryKey = Registry.CurrentUser.OpenSubKey(&quot;SOFTWARE\My Sorter\&quot; + profile)<br />
&nbsp; &nbsp; &nbsp; For Each Subkey As String In RegKey.GetSubKeyNames()<br />
&nbsp; &nbsp; &nbsp; &nbsp;  'For Each Subkey In Subkeys<br />
&nbsp; &nbsp; &nbsp; &nbsp;  Dim tempkey As RegistryKey = RegKey.OpenSubKey(Subkey)<br />
&nbsp; &nbsp; &nbsp; &nbsp;  MessageBox.Show(&quot;subkey name: &quot;, Subkey)<br />
&nbsp; &nbsp; &nbsp; &nbsp;  'ListView1.Items.Add(Subkey, Registry.GetValue(rootB + &quot;\&quot; + profile, Subkey, &quot;&quot;))<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp;  Dim listItem As New ListViewItem(tempkey.ToString)<br />
&nbsp; &nbsp; &nbsp; &nbsp;  listItem.SubItems.Add(Registry.GetValue(rootB + &quot;\&quot; + profile, tempkey.ToString, &quot;&quot;))<br />
&nbsp; &nbsp; &nbsp; &nbsp;  ListView1.Items.Add(listItem)<br />
<br />
&nbsp; &nbsp; &nbsp; Next<br />
&nbsp; &nbsp; &nbsp; RegKey.Close()<br />
<br />
&nbsp; &nbsp; &nbsp; 'Else<br />
&nbsp; &nbsp; &nbsp; 'MessageBox.Show(&quot;No GetValue: &quot; + profile)<br />
&nbsp; &nbsp; &nbsp; 'End If<br />
<br />
&nbsp;  End Sub</code><hr />
</div>Nested parenthesis is nothing new to me and I will be able to do so if given the chance.</div>

]]></content:encoded>
			<category domain="https://www.vbforums.com/forumdisplay.php?25-Visual-Basic-NET">Visual Basic .NET</category>
			<dc:creator>scot-65</dc:creator>
			<guid isPermaLink="true">https://www.vbforums.com/showthread.php?912059-Read-from-Registry-to-ListView1</guid>
		</item>
		<item>
			<title><![CDATA[Can't hear WAVE file.  No sound, no errors.]]></title>
			<link>https://www.vbforums.com/showthread.php?912056-Can-t-hear-WAVE-file-No-sound-no-errors&amp;goto=newpost</link>
			<pubDate>Tue, 02 Jun 2026 05:37:14 GMT</pubDate>
			<description><![CDATA[Hi,

I'm sure this has been done to death but I need some help to play a WAVE file.

I'm using Windows 11 and VB.NET 2026.


Code:
---------
Try
    'My.Computer.Audio.Play("e:\MyStuff\TestTone.wav", AudioPlayMode.WaitToComplete)
    My.Computer.Audio.Play(A, AudioPlayMode.WaitToComplete)
Catch ex As Exception
    Stop
End Try
---------

If tried both a file and a byte array, no luck.

Any ideas?]]></description>
			<content:encoded><![CDATA[<div>Hi,<br />
<br />
I'm sure this has been done to death but I need some help to play a WAVE file.<br />
<br />
I'm using Windows 11 and VB.NET 2026.<br />
<br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<hr /><code class="bbcode_code">Try<br />
&nbsp; &nbsp; 'My.Computer.Audio.Play(&quot;e:\MyStuff\TestTone.wav&quot;, AudioPlayMode.WaitToComplete)<br />
&nbsp; &nbsp; My.Computer.Audio.Play(A, AudioPlayMode.WaitToComplete)<br />
Catch ex As Exception<br />
&nbsp; &nbsp; Stop<br />
End Try</code><hr />
</div><br />
If tried both a file and a byte array, no luck.<br />
<br />
Any ideas?</div>

]]></content:encoded>
			<category domain="https://www.vbforums.com/forumdisplay.php?25-Visual-Basic-NET">Visual Basic .NET</category>
			<dc:creator>OzMaz</dc:creator>
			<guid isPermaLink="true">https://www.vbforums.com/showthread.php?912056-Can-t-hear-WAVE-file-No-sound-no-errors</guid>
		</item>
		<item>
			<title><![CDATA[[RESOLVED] Determining En Passant]]></title>
			<link>https://www.vbforums.com/showthread.php?912055-RESOLVED-Determining-En-Passant&amp;goto=newpost</link>
			<pubDate>Mon, 01 Jun 2026 18:55:52 GMT</pubDate>
			<description><![CDATA[It's been a while since I've built any games and so I figured I would set out to create a chess application.

I have the concept of Squares, Moves, Pieces (so far only started on Pawn), and Boards. This is the relevant code:

*Chess Board*
Keeps track of the squares and pieces

Code:
---------
Namespace Board

    Public Class ChessBoard

        ' private variables
        Private ReadOnly _darkPieces(15) As ChessPiece
        Private ReadOnly _lightPieces(15) As ChessPiece
        Private ReadOnly _squares(63) As Square

        ' private methods
        Private Sub InitializeSquares()
            Dim counter As Integer = 0
            For rank As Byte = 0 To Square.MAX_RANK
                For file As Integer = 0 To Square.FILE_NAMES.Length - 1
                    _squares(counter) = New Square(rank, Convert.ToByte(file))
                    counter += 1
                Next
            Next
        End Sub

        Private Sub InitializePawns()
            Const darkRank As Integer = 6
            Const lightRank As Integer = 1

            Dim index As Integer = 0
            For fileIndex As Byte = 0 To Convert.ToByte(Square.FILE_NAMES.Length - 1)
                _darkPieces(index) = New Pawn(Shades.Dark, New Square(darkRank, fileIndex))
                _lightPieces(index) = New Pawn(Shades.Dark, New Square(lightRank, fileIndex))
            Next
        End Sub

        ' properties
        Public ReadOnly Property Squares As IReadOnlyList(Of Square)
            Get
                Return _squares
            End Get
        End Property

        ' public methods
        Public Function GetSquare(file As Byte, rank As Byte) As Square
            If (file > Square.FILE_NAMES.Length - 1) Then
                Throw New ArgumentOutOfRangeException(NameOf(file))
            End If
            If (rank > Square.MAX_RANK) Then
                Throw New ArgumentOutOfRangeException(NameOf(rank))
            End If

            Return _squares.Single(Function(square) square.File.Equals(file) AndAlso square.Rank.Equals(rank))
        End Function

        Public Function HasEnemyPiece(square As Square, shade As Shades) As Boolean
            Dim opposingPieces As ChessPiece() = If(shade = Shades.Dark, _lightPieces, _darkPieces)

            Return opposingPieces.Any(Function(piece) piece IsNot Nothing AndAlso piece.Square.Equals(square))
        End Function

        Public Function HasFriendlyPiece(square As Square, shade As Shades) As Boolean
            Dim friendlyPieces As ChessPiece() = If(shade = Shades.Dark, _darkPieces, _lightPieces)

            Return friendlyPieces.Any(Function(piece) piece IsNot Nothing AndAlso piece.Square.Equals(square))
        End Function

        Public Function IsEmpty(square As Square) As Boolean
            Return _
                _darkPieces.All(Function(piece) piece Is Nothing OrElse Not piece.Square.Equals(square)) AndAlso
                _lightPieces.All(Function(piece) piece Is Nothing OrElse Not piece.Square.Equals(square))
        End Function

        Public Sub Reset()
            ' WIP
            InitializePawns()
        End Sub

        ' constructor
        Public Sub New()
            InitializeSquares()
        End Sub

    End Class

End Namespace
---------
*Square*
Represents a physical space on the chess board

Code:
---------
Namespace Board

    Public Class Square
        Implements IEquatable(Of Square)

        ' private variables/constants
        Friend Const FILE_NAMES As String = "ABCDEFGH"

        Friend Const MAX_RANK As Integer = 7

        Private ReadOnly _file As Byte = 0
        Private ReadOnly _rank As Byte = 0

        ' properties
        Public ReadOnly Property Shade As Shades
            Get
                Dim evenRank As Boolean = _rank Mod 2 = 0
                Dim evenFile As Boolean = _file Mod 2 = 0
                Return If(
                    (evenRank AndAlso evenFile) OrElse (Not evenRank AndAlso Not evenFile),
                    Shades.Dark,
                    Shades.Light
                )
            End Get
        End Property

        Public ReadOnly Property File As Byte
            Get
                Return _file
            End Get
        End Property

        Public ReadOnly Property FileName As String
            Get
                Return FILE_NAMES(_file).ToString()
            End Get
        End Property

        Public ReadOnly Property Name As String
            Get
                Return String.Concat(FileName, RankName)
            End Get
        End Property

        Public ReadOnly Property Rank As Byte
            Get
                Return _rank
            End Get
        End Property

        Public ReadOnly Property RankName As String
            Get
                Return (_rank + 1).ToString()
            End Get
        End Property

        ' public methods
        Public Overloads Function Equals(other As Square) As Boolean Implements IEquatable(Of Square).Equals
            If (other Is Nothing) Then
                Return False
            End If
            If (ReferenceEquals(Me, other)) Then
                Return True
            End If
            Return File = other.File AndAlso Rank = other.Rank
        End Function

        Public Overrides Function Equals(obj As Object) As Boolean
            Return Equals(TryCast(obj, Square))
        End Function

        Public Overrides Function GetHashCode() As Integer
            Return HashCode.Combine(File, Rank)
        End Function

        Public Shared Operator =(square1 As Square, square2 As Square) As Boolean
            If (square1 Is Nothing) Then
                Return square2 Is Nothing
            End If
            Return square1.Equals(square2)
        End Operator

        Public Shared Operator <>(square1 As Square, square2 As Square) As Boolean
            If (square1 Is Nothing) Then
                Return square2 IsNot Nothing
            End If
            Return Not square1.Equals(square2)
        End Operator

        Public Overrides Function ToString() As String
            Return Name
        End Function

        Public Sub New(rank As Byte, file As Byte)
            _rank = rank
            _file = file
        End Sub

    End Class

End Namespace
---------
*ChessPiece*
Parent class representing a chess piece; must be inherited

Code:
---------
Namespace Pieces

    Public MustInherit Class ChessPiece

        Public MustOverride ReadOnly Property PieceType As PieceTypes
        Public ReadOnly Property Shade As Shades
        Public Property Square As Square

        Public MustOverride Function GetMoves(board As ChessBoard) As IEnumerable(Of Move)

        Public Sub New(shade As Shades)
            _Shade = shade
        End Sub

        Public Sub New(shade As Shades, square As Square)
            _Shade = shade
            _Square = square
        End Sub

    End Class

End Namespace
---------
*Pawn*
Child chess piece for a pawn

Code:
---------
Namespace Pieces

    Public Class Pawn
        Inherits ChessPiece

        ' private variables
        Private Shared ReadOnly PromotionPieceTypes As PieceTypes() = {
            PieceTypes.Queen,
            PieceTypes.Rook,
            PieceTypes.Bishop,
            PieceTypes.Knight
        }

        ' private methods
        Private Sub AddForwardMoves(board As ChessBoard, moves As List(Of Move), targetRank As Byte)
            Dim targetSquare As Square = board.GetSquare(Square.File, targetRank)

            If (Not board.IsEmpty(targetSquare)) Then
                Return
            End If

            If (IsPromotionRank(targetRank)) Then
                AddPromotionMoves(moves, Square, targetSquare, MoveTypes.Promotion)
            Else
                Dim nextMove As New Move(Square, targetSquare, MoveTypes.Normal)
                moves.Add(nextMove)

                If (IsStartingRank(Square.Rank)) Then
                    Dim skipRankNumber As Byte = Convert.ToByte(Square.Rank + If(Shade.Equals(Shades.Dark), 2, -2))
                    Dim skipSquare As Square = board.GetSquare(Square.File, skipRankNumber)

                    If (board.IsEmpty(skipSquare)) Then
                        moves.Add(New Move(Square, skipSquare, MoveTypes.Normal))
                    End If
                End If
            End If
        End Sub

        Private Sub AddPawnCaptureMove(board As ChessBoard, moves As List(Of Move), targetFile As Byte, targetRank As Byte)
            Dim targetSquare As Square = board.GetSquare(targetFile, targetRank)
            If (Not board.HasEnemyPiece(targetSquare, Shade)) Then
                Return
            End If

            If IsPromotionRank(targetRank) Then
                AddPromotionMoves(moves, Square, targetSquare, MoveTypes.PromotionCapture)
            Else
                moves.Add(New Move(Square, targetSquare, MoveTypes.Capture))
            End If
        End Sub

        Private Shared Sub AddPromotionMoves(moves As List(Of Move), fromSquare As Square, toSquare As Square, moveType As MoveTypes)
            For Each promotionPieceType As PieceTypes In PromotionPieceTypes
                moves.Add(New Move(fromSquare, toSquare, moveType, promotionPieceType))
            Next
        End Sub

        Private Function IsStartingRank(rank As Byte) As Boolean
            Return If(Shade.Equals(Shades.Dark), rank = 1, rank = 6)
        End Function

        Private Function IsPromotionRank(rank As Byte) As Boolean
            Return If(Shade.Equals(Shades.Dark), rank = 7, rank = 0)
        End Function

        ' properties
        Public Overrides ReadOnly Property PieceType As PieceTypes = PieceTypes.Pawn

        ' public methods
        Public Overrides Function GetMoves(board As ChessBoard) As IEnumerable(Of Move)
            If (Square Is Nothing) Then
                Return Enumerable.Empty(Of Move)()
            End If

            Dim nextRankNumber As Byte = Convert.ToByte(Square.Rank + If(Shade.Equals(Shades.Dark), -1, 1))
            Dim moves As New List(Of Move)

            AddForwardMoves(board, moves, nextRankNumber)
            If (Square.File > 0) Then
                AddPawnCaptureMove(board, moves, CByte(Square.File - 1), nextRankNumber)
            End If
            If (Square.File < 7) Then
                AddPawnCaptureMove(board, moves, CByte(Square.File + 1), nextRankNumber)
            End If

            Return moves
        End Function

        ' constructor
        Public Sub New(shade As Shades)
            MyBase.New(shade)
        End Sub

        Public Sub New(shade As Shades, square As Square)
            MyBase.New(shade, square)
        End Sub

    End Class

End Namespace
---------
The pawn works for the most part, except I cannot figure out how to handle en passant.

The rules for en passant are that the capturing pawn can take an opponent's pawn if:

1.  The opponent's previously moved piece was a pawn
2.  The opponent's pawn moved forward 2 spaces (which can only happen the first time its moved)
3.  The opponent's pawn falls on the same rank as the capturing pawn



This is essentially game logic, but as you can tell from my setup, I'm trying to lay out all the potential moves of a given piece inside the Pawn class. My issue is that I'm not quite sure how to square those two concepts.]]></description>
			<content:encoded><![CDATA[<div>It's been a while since I've built any games and so I figured I would set out to create a chess application.<br />
<br />
I have the concept of Squares, Moves, Pieces (so far only started on Pawn), and Boards. This is the relevant code:<br />
<br />
<b>Chess Board</b><br />
<i>Keeps track of the squares and pieces</i><br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<hr /><code class="bbcode_code">Namespace Board<br />
<br />
&nbsp; &nbsp; Public Class ChessBoard<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; ' private variables<br />
&nbsp; &nbsp; &nbsp; &nbsp; Private ReadOnly _darkPieces(15) As ChessPiece<br />
&nbsp; &nbsp; &nbsp; &nbsp; Private ReadOnly _lightPieces(15) As ChessPiece<br />
&nbsp; &nbsp; &nbsp; &nbsp; Private ReadOnly _squares(63) As Square<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; ' private methods<br />
&nbsp; &nbsp; &nbsp; &nbsp; Private Sub InitializeSquares()<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Dim counter As Integer = 0<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; For rank As Byte = 0 To Square.MAX_RANK<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; For file As Integer = 0 To Square.FILE_NAMES.Length - 1<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _squares(counter) = New Square(rank, Convert.ToByte(file))<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; counter += 1<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Next<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Next<br />
&nbsp; &nbsp; &nbsp; &nbsp; End Sub<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; Private Sub InitializePawns()<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Const darkRank As Integer = 6<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Const lightRank As Integer = 1<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Dim index As Integer = 0<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; For fileIndex As Byte = 0 To Convert.ToByte(Square.FILE_NAMES.Length - 1)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _darkPieces(index) = New Pawn(Shades.Dark, New Square(darkRank, fileIndex))<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _lightPieces(index) = New Pawn(Shades.Dark, New Square(lightRank, fileIndex))<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Next<br />
&nbsp; &nbsp; &nbsp; &nbsp; End Sub<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; ' properties<br />
&nbsp; &nbsp; &nbsp; &nbsp; Public ReadOnly Property Squares As IReadOnlyList(Of Square)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Get<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Return _squares<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; End Get<br />
&nbsp; &nbsp; &nbsp; &nbsp; End Property<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; ' public methods<br />
&nbsp; &nbsp; &nbsp; &nbsp; Public Function GetSquare(file As Byte, rank As Byte) As Square<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; If (file &gt; Square.FILE_NAMES.Length - 1) Then<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Throw New ArgumentOutOfRangeException(NameOf(file))<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; End If<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; If (rank &gt; Square.MAX_RANK) Then<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Throw New ArgumentOutOfRangeException(NameOf(rank))<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; End If<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Return _squares.Single(Function(square) square.File.Equals(file) AndAlso square.Rank.Equals(rank))<br />
&nbsp; &nbsp; &nbsp; &nbsp; End Function<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; Public Function HasEnemyPiece(square As Square, shade As Shades) As Boolean<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Dim opposingPieces As ChessPiece() = If(shade = Shades.Dark, _lightPieces, _darkPieces)<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Return opposingPieces.Any(Function(piece) piece IsNot Nothing AndAlso piece.Square.Equals(square))<br />
&nbsp; &nbsp; &nbsp; &nbsp; End Function<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; Public Function HasFriendlyPiece(square As Square, shade As Shades) As Boolean<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Dim friendlyPieces As ChessPiece() = If(shade = Shades.Dark, _darkPieces, _lightPieces)<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Return friendlyPieces.Any(Function(piece) piece IsNot Nothing AndAlso piece.Square.Equals(square))<br />
&nbsp; &nbsp; &nbsp; &nbsp; End Function<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; Public Function IsEmpty(square As Square) As Boolean<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Return _<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _darkPieces.All(Function(piece) piece Is Nothing OrElse Not piece.Square.Equals(square)) AndAlso<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _lightPieces.All(Function(piece) piece Is Nothing OrElse Not piece.Square.Equals(square))<br />
&nbsp; &nbsp; &nbsp; &nbsp; End Function<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; Public Sub Reset()<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ' WIP<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; InitializePawns()<br />
&nbsp; &nbsp; &nbsp; &nbsp; End Sub<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; ' constructor<br />
&nbsp; &nbsp; &nbsp; &nbsp; Public Sub New()<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; InitializeSquares()<br />
&nbsp; &nbsp; &nbsp; &nbsp; End Sub<br />
<br />
&nbsp; &nbsp; End Class<br />
<br />
End Namespace</code><hr />
</div><b>Square</b><br />
<i>Represents a physical space on the chess board</i><br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<hr /><code class="bbcode_code">Namespace Board<br />
<br />
&nbsp; &nbsp; Public Class Square<br />
&nbsp; &nbsp; &nbsp; &nbsp; Implements IEquatable(Of Square)<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; ' private variables/constants<br />
&nbsp; &nbsp; &nbsp; &nbsp; Friend Const FILE_NAMES As String = &quot;ABCDEFGH&quot;<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; Friend Const MAX_RANK As Integer = 7<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; Private ReadOnly _file As Byte = 0<br />
&nbsp; &nbsp; &nbsp; &nbsp; Private ReadOnly _rank As Byte = 0<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; ' properties<br />
&nbsp; &nbsp; &nbsp; &nbsp; Public ReadOnly Property Shade As Shades<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Get<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Dim evenRank As Boolean = _rank Mod 2 = 0<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Dim evenFile As Boolean = _file Mod 2 = 0<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Return If(<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; (evenRank AndAlso evenFile) OrElse (Not evenRank AndAlso Not evenFile),<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Shades.Dark,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Shades.Light<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; )<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; End Get<br />
&nbsp; &nbsp; &nbsp; &nbsp; End Property<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; Public ReadOnly Property File As Byte<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Get<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Return _file<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; End Get<br />
&nbsp; &nbsp; &nbsp; &nbsp; End Property<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; Public ReadOnly Property FileName As String<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Get<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Return FILE_NAMES(_file).ToString()<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; End Get<br />
&nbsp; &nbsp; &nbsp; &nbsp; End Property<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; Public ReadOnly Property Name As String<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Get<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Return String.Concat(FileName, RankName)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; End Get<br />
&nbsp; &nbsp; &nbsp; &nbsp; End Property<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; Public ReadOnly Property Rank As Byte<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Get<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Return _rank<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; End Get<br />
&nbsp; &nbsp; &nbsp; &nbsp; End Property<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; Public ReadOnly Property RankName As String<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Get<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Return (_rank + 1).ToString()<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; End Get<br />
&nbsp; &nbsp; &nbsp; &nbsp; End Property<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; ' public methods<br />
&nbsp; &nbsp; &nbsp; &nbsp; Public Overloads Function Equals(other As Square) As Boolean Implements IEquatable(Of Square).Equals<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; If (other Is Nothing) Then<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Return False<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; End If<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; If (ReferenceEquals(Me, other)) Then<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Return True<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; End If<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Return File = other.File AndAlso Rank = other.Rank<br />
&nbsp; &nbsp; &nbsp; &nbsp; End Function<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; Public Overrides Function Equals(obj As Object) As Boolean<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Return Equals(TryCast(obj, Square))<br />
&nbsp; &nbsp; &nbsp; &nbsp; End Function<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; Public Overrides Function GetHashCode() As Integer<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Return HashCode.Combine(File, Rank)<br />
&nbsp; &nbsp; &nbsp; &nbsp; End Function<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; Public Shared Operator =(square1 As Square, square2 As Square) As Boolean<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; If (square1 Is Nothing) Then<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Return square2 Is Nothing<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; End If<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Return square1.Equals(square2)<br />
&nbsp; &nbsp; &nbsp; &nbsp; End Operator<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; Public Shared Operator &lt;&gt;(square1 As Square, square2 As Square) As Boolean<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; If (square1 Is Nothing) Then<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Return square2 IsNot Nothing<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; End If<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Return Not square1.Equals(square2)<br />
&nbsp; &nbsp; &nbsp; &nbsp; End Operator<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; Public Overrides Function ToString() As String<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Return Name<br />
&nbsp; &nbsp; &nbsp; &nbsp; End Function<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; Public Sub New(rank As Byte, file As Byte)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _rank = rank<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _file = file<br />
&nbsp; &nbsp; &nbsp; &nbsp; End Sub<br />
<br />
&nbsp; &nbsp; End Class<br />
<br />
End Namespace</code><hr />
</div><b>ChessPiece</b><br />
<i>Parent class representing a chess piece; must be inherited</i><br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<hr /><code class="bbcode_code">Namespace Pieces<br />
<br />
&nbsp; &nbsp; Public MustInherit Class ChessPiece<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; Public MustOverride ReadOnly Property PieceType As PieceTypes<br />
&nbsp; &nbsp; &nbsp; &nbsp; Public ReadOnly Property Shade As Shades<br />
&nbsp; &nbsp; &nbsp; &nbsp; Public Property Square As Square<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; Public MustOverride Function GetMoves(board As ChessBoard) As IEnumerable(Of Move)<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; Public Sub New(shade As Shades)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _Shade = shade<br />
&nbsp; &nbsp; &nbsp; &nbsp; End Sub<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; Public Sub New(shade As Shades, square As Square)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _Shade = shade<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _Square = square<br />
&nbsp; &nbsp; &nbsp; &nbsp; End Sub<br />
<br />
&nbsp; &nbsp; End Class<br />
<br />
End Namespace</code><hr />
</div><b>Pawn</b><br />
<i>Child chess piece for a pawn</i><br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<hr /><code class="bbcode_code">Namespace Pieces<br />
<br />
&nbsp; &nbsp; Public Class Pawn<br />
&nbsp; &nbsp; &nbsp; &nbsp; Inherits ChessPiece<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; ' private variables<br />
&nbsp; &nbsp; &nbsp; &nbsp; Private Shared ReadOnly PromotionPieceTypes As PieceTypes() = {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; PieceTypes.Queen,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; PieceTypes.Rook,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; PieceTypes.Bishop,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; PieceTypes.Knight<br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; ' private methods<br />
&nbsp; &nbsp; &nbsp; &nbsp; Private Sub AddForwardMoves(board As ChessBoard, moves As List(Of Move), targetRank As Byte)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Dim targetSquare As Square = board.GetSquare(Square.File, targetRank)<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; If (Not board.IsEmpty(targetSquare)) Then<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Return<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; End If<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; If (IsPromotionRank(targetRank)) Then<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; AddPromotionMoves(moves, Square, targetSquare, MoveTypes.Promotion)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Else<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Dim nextMove As New Move(Square, targetSquare, MoveTypes.Normal)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; moves.Add(nextMove)<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; If (IsStartingRank(Square.Rank)) Then<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Dim skipRankNumber As Byte = Convert.ToByte(Square.Rank + If(Shade.Equals(Shades.Dark), 2, -2))<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Dim skipSquare As Square = board.GetSquare(Square.File, skipRankNumber)<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; If (board.IsEmpty(skipSquare)) Then<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; moves.Add(New Move(Square, skipSquare, MoveTypes.Normal))<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; End If<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; End If<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; End If<br />
&nbsp; &nbsp; &nbsp; &nbsp; End Sub<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; Private Sub AddPawnCaptureMove(board As ChessBoard, moves As List(Of Move), targetFile As Byte, targetRank As Byte)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Dim targetSquare As Square = board.GetSquare(targetFile, targetRank)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; If (Not board.HasEnemyPiece(targetSquare, Shade)) Then<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Return<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; End If<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; If IsPromotionRank(targetRank) Then<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; AddPromotionMoves(moves, Square, targetSquare, MoveTypes.PromotionCapture)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Else<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; moves.Add(New Move(Square, targetSquare, MoveTypes.Capture))<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; End If<br />
&nbsp; &nbsp; &nbsp; &nbsp; End Sub<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; Private Shared Sub AddPromotionMoves(moves As List(Of Move), fromSquare As Square, toSquare As Square, moveType As MoveTypes)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; For Each promotionPieceType As PieceTypes In PromotionPieceTypes<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; moves.Add(New Move(fromSquare, toSquare, moveType, promotionPieceType))<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Next<br />
&nbsp; &nbsp; &nbsp; &nbsp; End Sub<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; Private Function IsStartingRank(rank As Byte) As Boolean<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Return If(Shade.Equals(Shades.Dark), rank = 1, rank = 6)<br />
&nbsp; &nbsp; &nbsp; &nbsp; End Function<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; Private Function IsPromotionRank(rank As Byte) As Boolean<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Return If(Shade.Equals(Shades.Dark), rank = 7, rank = 0)<br />
&nbsp; &nbsp; &nbsp; &nbsp; End Function<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; ' properties<br />
&nbsp; &nbsp; &nbsp; &nbsp; Public Overrides ReadOnly Property PieceType As PieceTypes = PieceTypes.Pawn<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; ' public methods<br />
&nbsp; &nbsp; &nbsp; &nbsp; Public Overrides Function GetMoves(board As ChessBoard) As IEnumerable(Of Move)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; If (Square Is Nothing) Then<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Return Enumerable.Empty(Of Move)()<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; End If<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Dim nextRankNumber As Byte = Convert.ToByte(Square.Rank + If(Shade.Equals(Shades.Dark), -1, 1))<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Dim moves As New List(Of Move)<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; AddForwardMoves(board, moves, nextRankNumber)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; If (Square.File &gt; 0) Then<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; AddPawnCaptureMove(board, moves, CByte(Square.File - 1), nextRankNumber)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; End If<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; If (Square.File &lt; 7) Then<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; AddPawnCaptureMove(board, moves, CByte(Square.File + 1), nextRankNumber)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; End If<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Return moves<br />
&nbsp; &nbsp; &nbsp; &nbsp; End Function<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; ' constructor<br />
&nbsp; &nbsp; &nbsp; &nbsp; Public Sub New(shade As Shades)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; MyBase.New(shade)<br />
&nbsp; &nbsp; &nbsp; &nbsp; End Sub<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; Public Sub New(shade As Shades, square As Square)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; MyBase.New(shade, square)<br />
&nbsp; &nbsp; &nbsp; &nbsp; End Sub<br />
<br />
&nbsp; &nbsp; End Class<br />
<br />
End Namespace</code><hr />
</div>The pawn works for the most part, except I cannot figure out how to handle en passant.<br />
<br />
The rules for en passant are that the capturing pawn can take an opponent's pawn if:<br />
<ol class="decimal"><li style=""> The opponent's previously moved piece was a pawn</li><li style=""> The opponent's pawn moved forward 2 spaces (which can only happen the first time its moved)</li><li style=""> The opponent's pawn falls on the same rank as the capturing pawn</li></ol><br />
<br />
This is essentially game logic, but as you can tell from my setup, I'm trying to lay out all the potential moves of a given piece inside the Pawn class. My issue is that I'm not quite sure how to square those two concepts.</div>

]]></content:encoded>
			<category domain="https://www.vbforums.com/forumdisplay.php?25-Visual-Basic-NET">Visual Basic .NET</category>
			<dc:creator>dday9</dc:creator>
			<guid isPermaLink="true">https://www.vbforums.com/showthread.php?912055-RESOLVED-Determining-En-Passant</guid>
		</item>
		<item>
			<title>PictureBox.SetPixel Timing</title>
			<link>https://www.vbforums.com/showthread.php?912053-PictureBox-SetPixel-Timing&amp;goto=newpost</link>
			<pubDate>Mon, 01 Jun 2026 12:12:33 GMT</pubDate>
			<description><![CDATA[Hi. I'm receiving through a USB connection the data for 16 image pixels at a time. The data comes in as RGB565 in two bytes per pixel for a 160 x 120 pixels image. 

If I receive the pixels data with an interval of 1 millisecond between data packets, my vb.net program works fine displaying the image. My USB device can send data a lot faster than this, so if I try to decrease the interval below 1 mS (speed up the data transfer), the display process of the image in the PictureBox starts losing data and it won't display the whole picture. This makes me think that my vb.net program is taking too long to display the image.

How do I speed up my code? What are the lines in the code that are taking more time to process? I remember there is a way to run the code in a second thread. Is this going to help? Any ideas? Thanks.


Code:
---------
For IvarImage = 0 To 15       'PROCESS DATA FOR 16 PIXELS FOR IMAGE IN PICTUREBOX. RGB565 DATA.

   '248 = b11111000, SHIFT 3 SPACES TO THE RIGHT.
   RedValueImage = (ALL64.Item(DevNum).Get_SquaresArray(((IvarImage * 2) + 1)) And 248) >> 3
   '7 = b00000111, SHIFT 3 SPACES TO THE LEFT. 224 = b11100000, SHIFT 5 SPACES TO THE RIGHT.
   GreenValueImage = ((ALL64.Item(DevNum).Get_SquaresArray(((IvarImage * 2) + 1)) And 7) << 3) +
      ((ALL64.Item(DevNum).Get_SquaresArray((IvarImage * 2)) And 224) >> 5)
   '31 = b00011111.
   BlueValueImage = ALL64.Item(DevNum).Get_SquaresArray((IvarImage * 2)) And 31

   'NEED TO SCALE UP COLOR VARIABLES.
   RedValueImage = RedValueImage * 255 / 31            '31 CORRESPONDS TO 5 BITS FOR RED
   GreenValueImage = GreenValueImage * 255 / 63        '63 CORRESPONDS TO 6 BITS FOR GRREN
   BlueValueImage = BlueValueImage * 255 / 31          '31 CORRESPONDS TO 5 BITS FOR BLUE

   Dim pixelColor As Color = Color.FromArgb(RedValueImage, GreenValueImage, BlueValueImage)
   bmpImage.SetPixel(xImage, yImage, pixelColor)

   xImage = xImage + 1         'NEXT POINT. IMAGE SIZE IS 160 X 120 PIXELS.
   If xImage > 159 Then
      xImage = 0
      yImage = yImage + 1
      If yImage > 119 Then
         yImage = 0
      End If
   End If

Next

' Display the generated image in a PictureBox. 16 pixels at a time.
pbxCameraImage.Image = bmpImage
---------
]]></description>
			<content:encoded><![CDATA[<div>Hi. I'm receiving through a USB connection the data for 16 image pixels at a time. The data comes in as RGB565 in two bytes per pixel for a 160 x 120 pixels image. <br />
<br />
If I receive the pixels data with an interval of 1 millisecond between data packets, my vb.net program works fine displaying the image. My USB device can send data a lot faster than this, so if I try to decrease the interval below 1 mS (speed up the data transfer), the display process of the image in the PictureBox starts losing data and it won't display the whole picture. This makes me think that my vb.net program is taking too long to display the image.<br />
<br />
How do I speed up my code? What are the lines in the code that are taking more time to process? I remember there is a way to run the code in a second thread. Is this going to help? Any ideas? Thanks.<br />
<br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<hr /><code class="bbcode_code">For IvarImage = 0 To 15&nbsp; &nbsp; &nbsp;  'PROCESS DATA FOR 16 PIXELS FOR IMAGE IN PICTUREBOX. RGB565 DATA.<br />
<br />
&nbsp;  '248 = b11111000, SHIFT 3 SPACES TO THE RIGHT.<br />
&nbsp;  RedValueImage = (ALL64.Item(DevNum).Get_SquaresArray(((IvarImage * 2) + 1)) And 248) &gt;&gt; 3<br />
&nbsp;  '7 = b00000111, SHIFT 3 SPACES TO THE LEFT. 224 = b11100000, SHIFT 5 SPACES TO THE RIGHT.<br />
&nbsp;  GreenValueImage = ((ALL64.Item(DevNum).Get_SquaresArray(((IvarImage * 2) + 1)) And 7) &lt;&lt; 3) +<br />
&nbsp; &nbsp; &nbsp; ((ALL64.Item(DevNum).Get_SquaresArray((IvarImage * 2)) And 224) &gt;&gt; 5)<br />
&nbsp;  '31 = b00011111.<br />
&nbsp;  BlueValueImage = ALL64.Item(DevNum).Get_SquaresArray((IvarImage * 2)) And 31<br />
<br />
&nbsp;  'NEED TO SCALE UP COLOR VARIABLES.<br />
&nbsp;  RedValueImage = RedValueImage * 255 / 31&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; '31 CORRESPONDS TO 5 BITS FOR RED<br />
&nbsp;  GreenValueImage = GreenValueImage * 255 / 63&nbsp; &nbsp; &nbsp; &nbsp; '63 CORRESPONDS TO 6 BITS FOR GRREN<br />
&nbsp;  BlueValueImage = BlueValueImage * 255 / 31&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; '31 CORRESPONDS TO 5 BITS FOR BLUE<br />
<br />
&nbsp;  Dim pixelColor As Color = Color.FromArgb(RedValueImage, GreenValueImage, BlueValueImage)<br />
&nbsp;  bmpImage.SetPixel(xImage, yImage, pixelColor)<br />
<br />
&nbsp;  xImage = xImage + 1&nbsp; &nbsp; &nbsp; &nbsp;  'NEXT POINT. IMAGE SIZE IS 160 X 120 PIXELS.<br />
&nbsp;  If xImage &gt; 159 Then<br />
&nbsp; &nbsp; &nbsp; xImage = 0<br />
&nbsp; &nbsp; &nbsp; yImage = yImage + 1<br />
&nbsp; &nbsp; &nbsp; If yImage &gt; 119 Then<br />
&nbsp; &nbsp; &nbsp; &nbsp;  yImage = 0<br />
&nbsp; &nbsp; &nbsp; End If<br />
&nbsp;  End If<br />
<br />
Next<br />
<br />
' Display the generated image in a PictureBox. 16 pixels at a time.<br />
pbxCameraImage.Image = bmpImage</code><hr />
</div></div>

]]></content:encoded>
			<category domain="https://www.vbforums.com/forumdisplay.php?25-Visual-Basic-NET">Visual Basic .NET</category>
			<dc:creator>VB-MCU-User</dc:creator>
			<guid isPermaLink="true">https://www.vbforums.com/showthread.php?912053-PictureBox-SetPixel-Timing</guid>
		</item>
		<item>
			<title>VS 2015 Free stock API?</title>
			<link>https://www.vbforums.com/showthread.php?912050-Free-stock-API&amp;goto=newpost</link>
			<pubDate>Sat, 30 May 2026 03:22:15 GMT</pubDate>
			<description>Since many of the Windows 7 desktop gadgets no longer work, I wrote one to show me the current prices of my stock holdings. I use the twelvedata.com API for the data and my program is configured to access the API not more than several hundred times per day (which assumes my computer is on for the entire active stock day), so it is not terribly demanding.

The API worked without issue for several years, but a while ago, it stopped showing the value for the indices DJI, IXIC, and SPX. Today (and I checked this by entering the API URL into my browser), the twelvedata.com API indicated that these index strings are not valid.

Question: Can anyone suggest a free API that will provide the current-ish value for these indices about 50 times per day? Not sure that this is the proper forum in which this question should be asked, and if you have any ideas of better forums where this can be asked, please share.</description>
			<content:encoded><![CDATA[<div>Since many of the Windows 7 desktop gadgets no longer work, I wrote one to show me the current prices of my stock holdings. I use the twelvedata.com API for the data and my program is configured to access the API not more than several hundred times per day (which assumes my computer is on for the entire active stock day), so it is not terribly demanding.<br />
<br />
The API worked without issue for several years, but a while ago, it stopped showing the value for the indices DJI, IXIC, and SPX. Today (and I checked this by entering the API URL into my browser), the twelvedata.com API indicated that these index strings are not valid.<br />
<br />
Question: Can anyone suggest a free API that will provide the current-ish value for these indices about 50 times per day? Not sure that this is the proper forum in which this question should be asked, and if you have any ideas of better forums where this can be asked, please share.</div>

]]></content:encoded>
			<category domain="https://www.vbforums.com/forumdisplay.php?25-Visual-Basic-NET">Visual Basic .NET</category>
			<dc:creator>groston</dc:creator>
			<guid isPermaLink="true">https://www.vbforums.com/showthread.php?912050-Free-stock-API</guid>
		</item>
		<item>
			<title>VS Code Plotting persistent graphics to an object then rendering to PictureBox</title>
			<link>https://www.vbforums.com/showthread.php?912044-Plotting-persistent-graphics-to-an-object-then-rendering-to-PictureBox&amp;goto=newpost</link>
			<pubDate>Wed, 27 May 2026 03:20:59 GMT</pubDate>
			<description><![CDATA[Hi Guys,

I am having a little challenge drawing and rendering persistent graphics.

I am attempting to plot an XY graph using dynamic data where I receive a time value (X) and an increment value (Y)
I have created a picturebox object to plot the values to  and programmatically define my centreline zero
I then take the incoming time event in seconds and the incoming incremental value which can range from -6 through to 6 inclusively.
Then I add that value to the incremental total and if that value is positive, I plot a Blue vertical line from the zero point to the value on the Y axis, where the X axis is automatically incremented by one (time in seconds) and if it is a negative value then I plot it in Red with a descending line from the zero point.

The above is both a description of what I am trying to do with the incoming data.

Where I am having difficulty is drawing the graphics in a persistent manner so that as the data arrives, the previous plot is not erased by the new incoming plot.

If I simulate the information and draw it all in one routine, then I get a nice graphic but when I attempt to plot it as the data arrives, I either get a single line that plots each time or I get nothing (most frustrating)

Here is my simulated data code which should plot some simulated red and blue solid arcs. (not actual arcs as the data is in column form)

I initially tried plotting direct to the form which worked if I did it all in one go, but of course I couldn't add any new data as calling the routine refreshed the form and I lost the previous plots.

Then I created a picturebox object and defined a rectangle area, I also defined a bufferedgraphicscontext object so that I could draw the column to the object and then render the object to the rectangle on the picturebox so that I could cumulatively add columns to the buffered object and then render the object, thus preventing the loss of previous plots as the whole plot graph would be rendered each time.  This is where I am at and other than getting the render to flash on and instantly disappear, I have been unable to figure out how to keep the rendered image persistent.

I am hoping that you might be able to point out where I am going wrong?


Code:
---------

Public Class Form1
    Public MyImage As New BufferedGraphicsContext
    Public rectangle = New Rectangle(x:=0, y:=0, width:=755, height:=201)
    Public MyWorm As System.Drawing.BufferedGraphics
    Public pen1 As Pen = New Pen(Color.White, 2)
    Public pen2 As Pen = New Pen(Color.DarkRed, 1)
    Public pen3 As Pen = New Pen(Color.Navy, 1)
    Dim x As Integer
    Private Sub Form_Load(sender As Object, e As PaintEventArgs) Handles MyBase.Paint
        Me.Width = 820
        Me.Height = 253
        Me.BackColor = Color.DarkSlateGray
        DoubleBuffered = True
        MyWorm = MyImage.Allocate(PictureBox1.CreateGraphics, rectangle)
        With MyWorm.Graphics
            .CompositingMode = Drawing2D.CompositingMode.SourceOver
            .CompositingQuality = Drawing2D.CompositingQuality.AssumeLinear
            .SmoothingMode = Drawing2D.SmoothingMode.HighQuality
            .InterpolationMode = CType(Drawing2D.QualityMode.High, Drawing2D.InterpolationMode)
            .PixelOffsetMode = Drawing2D.PixelOffsetMode.None
        End With
        PlotWorm(Nothing, Nothing)
    End Sub
    Public Sub PlotWorm(sender As Object, e As PaintEventArgs) Handles MyBase.Paint
        Do While x < 121
            For y = 0 To 60 Step 6
                x += 1
                MyWorm.Graphics.DrawLine(pen3, 34 + x, 106 - y, 34 + x, 2 + y)
                MyWorm.Render()
            Next y
            For y = 60 To 0 Step -6
                x += 1
                MyWorm.Graphics.DrawLine(pen3, 34 + x, 106 - y, 34 + x, 2 + y)
                MyWorm.Render()
            Next y
        Loop
        Do While x < 241
            For y = 0 To -60 Step -5
                x += 1
                MyWorm.Graphics.DrawLine(pen2, 42 + x, 108 - y, 42 + x, 2 + y)
                MyWorm.Render()
            Next y
            For y = -60 To 0 Step 5
                x += 1
                MyWorm.Graphics.DrawLine(pen2, 42 + x, 108 - y, 42 + x, 2 + y)
                MyWorm.Render()
            Next y
        Loop
        Do While x < 361
            For y = 0 To 60 Step 4
                x += 1
                MyWorm.Graphics.DrawLine(pen3, 54 + x, 106 - y, 54 + x, 2 + y)
                MyWorm.Render()
            Next y
            For y = 60 To 0 Step -4
                x += 1
                MyWorm.Graphics.DrawLine(pen3, 54 + x, 106 - y, 54 + x, 2 + y)
                MyWorm.Render()
            Next y
        Loop
        Do While x < 481
            For y = 0 To -60 Step -3
                x += 1
                MyWorm.Graphics.DrawLine(pen2, 66 + x, 108 - y, 66 + x, 2 + y)
                MyWorm.Render()
            Next y
            For y = -60 To 0 Step 3
                x += 1
                MyWorm.Graphics.DrawLine(pen2, 66 + x, 108 - y, 66 + x, 2 + y)
                MyWorm.Render()
            Next y
        Loop
    End Sub

End Class
---------
I am looking forward to your advice and guidance.

Regards,
Antony]]></description>
			<content:encoded><![CDATA[<div>Hi Guys,<br />
<br />
I am having a little challenge drawing and rendering persistent graphics.<br />
<br />
I am attempting to plot an XY graph using dynamic data where I receive a time value (X) and an increment value (Y)<br />
I have created a picturebox object to plot the values to  and programmatically define my centreline zero<br />
I then take the incoming time event in seconds and the incoming incremental value which can range from -6 through to 6 inclusively.<br />
Then I add that value to the incremental total and if that value is positive, I plot a Blue vertical line from the zero point to the value on the Y axis, where the X axis is automatically incremented by one (time in seconds) and if it is a negative value then I plot it in Red with a descending line from the zero point.<br />
<br />
The above is both a description of what I am trying to do with the incoming data.<br />
<br />
Where I am having difficulty is drawing the graphics in a persistent manner so that as the data arrives, the previous plot is not erased by the new incoming plot.<br />
<br />
If I simulate the information and draw it all in one routine, then I get a nice graphic but when I attempt to plot it as the data arrives, I either get a single line that plots each time or I get nothing (most frustrating)<br />
<br />
Here is my simulated data code which should plot some simulated red and blue solid arcs. (not actual arcs as the data is in column form)<br />
<br />
I initially tried plotting direct to the form which worked if I did it all in one go, but of course I couldn't add any new data as calling the routine refreshed the form and I lost the previous plots.<br />
<br />
Then I created a picturebox object and defined a rectangle area, I also defined a bufferedgraphicscontext object so that I could draw the column to the object and then render the object to the rectangle on the picturebox so that I could cumulatively add columns to the buffered object and then render the object, thus preventing the loss of previous plots as the whole plot graph would be rendered each time.  This is where I am at and other than getting the render to flash on and instantly disappear, I have been unable to figure out how to keep the rendered image persistent.<br />
<br />
I am hoping that you might be able to point out where I am going wrong?<br />
<br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<hr /><code class="bbcode_code"><br />
Public Class Form1<br />
&nbsp; &nbsp; Public MyImage As New BufferedGraphicsContext<br />
&nbsp; &nbsp; Public rectangle = New Rectangle(x:=0, y:=0, width:=755, height:=201)<br />
&nbsp; &nbsp; Public MyWorm As System.Drawing.BufferedGraphics<br />
&nbsp; &nbsp; Public pen1 As Pen = New Pen(Color.White, 2)<br />
&nbsp; &nbsp; Public pen2 As Pen = New Pen(Color.DarkRed, 1)<br />
&nbsp; &nbsp; Public pen3 As Pen = New Pen(Color.Navy, 1)<br />
&nbsp; &nbsp; Dim x As Integer<br />
&nbsp; &nbsp; Private Sub Form_Load(sender As Object, e As PaintEventArgs) Handles MyBase.Paint<br />
&nbsp; &nbsp; &nbsp; &nbsp; Me.Width = 820<br />
&nbsp; &nbsp; &nbsp; &nbsp; Me.Height = 253<br />
&nbsp; &nbsp; &nbsp; &nbsp; Me.BackColor = Color.DarkSlateGray<br />
&nbsp; &nbsp; &nbsp; &nbsp; DoubleBuffered = True<br />
&nbsp; &nbsp; &nbsp; &nbsp; MyWorm = MyImage.Allocate(PictureBox1.CreateGraphics, rectangle)<br />
&nbsp; &nbsp; &nbsp; &nbsp; With MyWorm.Graphics<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .CompositingMode = Drawing2D.CompositingMode.SourceOver<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .CompositingQuality = Drawing2D.CompositingQuality.AssumeLinear<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .SmoothingMode = Drawing2D.SmoothingMode.HighQuality<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .InterpolationMode = CType(Drawing2D.QualityMode.High, Drawing2D.InterpolationMode)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .PixelOffsetMode = Drawing2D.PixelOffsetMode.None<br />
&nbsp; &nbsp; &nbsp; &nbsp; End With<br />
&nbsp; &nbsp; &nbsp; &nbsp; PlotWorm(Nothing, Nothing)<br />
&nbsp; &nbsp; End Sub<br />
&nbsp; &nbsp; Public Sub PlotWorm(sender As Object, e As PaintEventArgs) Handles MyBase.Paint<br />
&nbsp; &nbsp; &nbsp; &nbsp; Do While x &lt; 121<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; For y = 0 To 60 Step 6<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; x += 1<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; MyWorm.Graphics.DrawLine(pen3, 34 + x, 106 - y, 34 + x, 2 + y)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; MyWorm.Render()<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Next y<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; For y = 60 To 0 Step -6<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; x += 1<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; MyWorm.Graphics.DrawLine(pen3, 34 + x, 106 - y, 34 + x, 2 + y)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; MyWorm.Render()<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Next y<br />
&nbsp; &nbsp; &nbsp; &nbsp; Loop<br />
&nbsp; &nbsp; &nbsp; &nbsp; Do While x &lt; 241<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; For y = 0 To -60 Step -5<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; x += 1<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; MyWorm.Graphics.DrawLine(pen2, 42 + x, 108 - y, 42 + x, 2 + y)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; MyWorm.Render()<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Next y<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; For y = -60 To 0 Step 5<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; x += 1<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; MyWorm.Graphics.DrawLine(pen2, 42 + x, 108 - y, 42 + x, 2 + y)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; MyWorm.Render()<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Next y<br />
&nbsp; &nbsp; &nbsp; &nbsp; Loop<br />
&nbsp; &nbsp; &nbsp; &nbsp; Do While x &lt; 361<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; For y = 0 To 60 Step 4<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; x += 1<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; MyWorm.Graphics.DrawLine(pen3, 54 + x, 106 - y, 54 + x, 2 + y)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; MyWorm.Render()<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Next y<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; For y = 60 To 0 Step -4<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; x += 1<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; MyWorm.Graphics.DrawLine(pen3, 54 + x, 106 - y, 54 + x, 2 + y)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; MyWorm.Render()<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Next y<br />
&nbsp; &nbsp; &nbsp; &nbsp; Loop<br />
&nbsp; &nbsp; &nbsp; &nbsp; Do While x &lt; 481<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; For y = 0 To -60 Step -3<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; x += 1<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; MyWorm.Graphics.DrawLine(pen2, 66 + x, 108 - y, 66 + x, 2 + y)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; MyWorm.Render()<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Next y<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; For y = -60 To 0 Step 3<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; x += 1<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; MyWorm.Graphics.DrawLine(pen2, 66 + x, 108 - y, 66 + x, 2 + y)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; MyWorm.Render()<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Next y<br />
&nbsp; &nbsp; &nbsp; &nbsp; Loop<br />
&nbsp; &nbsp; End Sub<br />
<br />
End Class</code><hr />
</div>I am looking forward to your advice and guidance.<br />
<br />
Regards,<br />
Antony</div>

]]></content:encoded>
			<category domain="https://www.vbforums.com/forumdisplay.php?25-Visual-Basic-NET">Visual Basic .NET</category>
			<dc:creator>AntonyL</dc:creator>
			<guid isPermaLink="true">https://www.vbforums.com/showthread.php?912044-Plotting-persistent-graphics-to-an-object-then-rendering-to-PictureBox</guid>
		</item>
		<item>
			<title>VB 2026 trying to access form controls as part of a class?</title>
			<link>https://www.vbforums.com/showthread.php?912037-VB-2026-trying-to-access-form-controls-as-part-of-a-class&amp;goto=newpost</link>
			<pubDate>Fri, 22 May 2026 17:09:53 GMT</pubDate>
			<description><![CDATA[Using VB 2026.

So I can't be sure this worked in 2022 version, but I thought you could do something like:

Code:
---------
Private Class MyClass
    Public Yo as String
    Public lbName as Label
    Public cmbChoice as ComboBox
End Class

... (button click, can't be bothered to type it out)
  Dim myVar as New MyClass
  myVar.Yo = "Hey there, you beautiful code."
  myVar.lbName = Label1
  myVar.cmbChoice = ComboBox1
....
---------
This seems to work just fine for Yo and lbName, but... MyVar.cmbChoice throws an error: Value of type 'ComboBox' cannot be converted to 'VisualStyleElement.ComboBox'.

Obviously I plan to make an array or list of these as there's going to be lots of them, with multiple controls needing to be assigned to one variable so they can all be altered or read with respect to that item. So I'd like a variable class that just points to the controls instead of trying to make control arrays and accessing them all that way. I think it just makes it clearer what's going on, why they're being recorded that way, and so on. Would this work in VB 2022? If so... I may just go back to it rather than trying to figure out this mess.]]></description>
			<content:encoded><![CDATA[<div>Using VB 2026.<br />
<br />
So I can't be sure this worked in 2022 version, but I <i>thought</i> you could do something like:<br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<hr /><code class="bbcode_code">Private Class MyClass<br />
&nbsp; &nbsp; Public Yo as String<br />
&nbsp; &nbsp; Public lbName as Label<br />
&nbsp; &nbsp; Public cmbChoice as ComboBox<br />
End Class<br />
<br />
... (button click, can't be bothered to type it out)<br />
&nbsp; Dim myVar as New MyClass<br />
&nbsp; myVar.Yo = &quot;Hey there, you beautiful code.&quot;<br />
&nbsp; myVar.lbName = Label1<br />
&nbsp; myVar.cmbChoice = ComboBox1<br />
....</code><hr />
</div>This seems to work just fine for Yo and lbName, but... MyVar.cmbChoice throws an error: Value of type 'ComboBox' cannot be converted to 'VisualStyleElement.ComboBox'.<br />
<br />
Obviously I plan to make an array or list of these as there's going to be lots of them, with multiple controls needing to be assigned to one variable so they can all be altered or read with respect to that item. So I'd like a variable class that just points to the controls instead of trying to make control arrays and accessing them all that way. I think it just makes it clearer what's going on, why they're being recorded that way, and so on. Would this work in VB 2022? If so... I may just go back to it rather than trying to figure out this mess.</div>

]]></content:encoded>
			<category domain="https://www.vbforums.com/forumdisplay.php?25-Visual-Basic-NET">Visual Basic .NET</category>
			<dc:creator>OddGamer</dc:creator>
			<guid isPermaLink="true">https://www.vbforums.com/showthread.php?912037-VB-2026-trying-to-access-form-controls-as-part-of-a-class</guid>
		</item>
		<item>
			<title>Zoom and move picture within picturebox</title>
			<link>https://www.vbforums.com/showthread.php?912034-Zoom-and-move-picture-within-picturebox&amp;goto=newpost</link>
			<pubDate>Thu, 21 May 2026 15:40:28 GMT</pubDate>
			<description>I have a project where the user can load a picture into a picturebox on a form.

I would like the user to be able to click on the picture and then the wheel mouse to zoom in and out (enlarge) and the click to move the picture within the box around.
Now - I use VB.NET and have never tried anything like this before...

Well I did but got nowhere ... clueless!

Is this achievable in VB.NET or do I have to look to ourchase a user control add in.

Thank you in advance for any feedback

Terry</description>
			<content:encoded><![CDATA[<div>I have a project where the user can load a picture into a picturebox on a form.<br />
<br />
I would like the user to be able to click on the picture and then the wheel mouse to zoom in and out (enlarge) and the click to move the picture within the box around.<br />
Now - I use VB.NET and have never tried anything like this before...<br />
<br />
Well I did but got nowhere ... clueless!<br />
<br />
Is this achievable in VB.NET or do I have to look to ourchase a user control add in.<br />
<br />
Thank you in advance for any feedback<br />
<br />
Terry</div>

]]></content:encoded>
			<category domain="https://www.vbforums.com/forumdisplay.php?25-Visual-Basic-NET">Visual Basic .NET</category>
			<dc:creator>terryfoster60</dc:creator>
			<guid isPermaLink="true">https://www.vbforums.com/showthread.php?912034-Zoom-and-move-picture-within-picturebox</guid>
		</item>
		<item>
			<title><![CDATA[VS 2022 [RESOLVED] The user should be allowed to enter only these 3 numbers,1, 2, or 3, in a textbox.]]></title>
			<link>https://www.vbforums.com/showthread.php?912031-RESOLVED-The-user-should-be-allowed-to-enter-only-these-3-numbers-1-2-or-3-in-a-textbox&amp;goto=newpost</link>
			<pubDate>Wed, 20 May 2026 21:04:39 GMT</pubDate>
			<description>Hi,

The user should be allowed to enter only these 3 numbers,1, 2, or 3, in a textbox. How to restrict him from entering other characters?

Please help.</description>
			<content:encoded><![CDATA[<div>Hi,<br />
<br />
The user should be allowed to enter only these 3 numbers,1, 2, or 3, in a textbox. How to restrict him from entering other characters?<br />
<br />
Please help.</div>

]]></content:encoded>
			<category domain="https://www.vbforums.com/forumdisplay.php?25-Visual-Basic-NET">Visual Basic .NET</category>
			<dc:creator>VS2013</dc:creator>
			<guid isPermaLink="true">https://www.vbforums.com/showthread.php?912031-RESOLVED-The-user-should-be-allowed-to-enter-only-these-3-numbers-1-2-or-3-in-a-textbox</guid>
		</item>
		<item>
			<title>Position of a PictureBox</title>
			<link>https://www.vbforums.com/showthread.php?912029-Position-of-a-PictureBox&amp;goto=newpost</link>
			<pubDate>Tue, 19 May 2026 11:37:23 GMT</pubDate>
			<description>Hello, i want to center a picturebox but i dont understand the maths

For exemple, i set the form size to 400*200 and the picture size to 300*100, so the picture location should be 50*50, but its no centered (it s ok at location 40*30)
What is wrong in my maths ?

Thanks</description>
			<content:encoded><![CDATA[<div>Hello, i want to center a picturebox but i dont understand the maths<br />
<br />
For exemple, i set the form size to 400*200 and the picture size to 300*100, so the picture location should be 50*50, but its no centered (it s ok at location 40*30)<br />
What is wrong in my maths ?<br />
<br />
Thanks</div>

]]></content:encoded>
			<category domain="https://www.vbforums.com/forumdisplay.php?25-Visual-Basic-NET">Visual Basic .NET</category>
			<dc:creator>Grenoblus</dc:creator>
			<guid isPermaLink="true">https://www.vbforums.com/showthread.php?912029-Position-of-a-PictureBox</guid>
		</item>
		<item>
			<title>VS Code Outline Text in a Label</title>
			<link>https://www.vbforums.com/showthread.php?912024-Outline-Text-in-a-Label&amp;goto=newpost</link>
			<pubDate>Sun, 17 May 2026 07:39:47 GMT</pubDate>
			<description><![CDATA[Hello All,

I have been struggling with a little project that needs a label to contain text with an outline aka stroke.
The Text is white and the background in teal.  I would like to be able to add a black stroke to the text contained in a Label

I came across lots of interesting code and have figured out how to create just outline text but I need to have the text white with a black outline.

The code I have been trying to use to achieve this is as follows


Code:
---------

Imports System.Drawing.Drawing2D

Public Class BorderLabel
    Inherits Label
    Public outline_color As Color = Color.Black
    Public border_thickness As Integer = 5
    Public Sub New()
        MyBase.New
    End Sub


    Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
        e.Graphics.FillRectangle(New SolidBrush(BackColor), ClientRectangle)
        Dim gp As GraphicsPath = New GraphicsPath
        Dim outline As Pen = New Pen(Me.outline_color, Me.border_thickness)
        Dim sf As StringFormat = New StringFormat
        Dim foreBrush As Brush = New SolidBrush(ForeColor)
        gp.AddString(GV.Text, Font.FontFamily, CType(Font.Style, Integer), Font.Size, ClientRectangle, sf)
        e.Graphics.ScaleTransform(1.3!, 1.35!)
        e.Graphics.SmoothingMode = SmoothingMode.HighQuality
        e.Graphics.DrawPath(outline, gp)
        e.Graphics.FillPath(foreBrush, gp)
    End Sub
End Class
---------
This isn't my code but it does seem to indicate that it should do as I want.
I created a new project to test this and just using the defaults
Form1
and a label named BorderLabel1 with some text "Test TEXT"

So this is where I fall down.  I cannot get it to work at all and am hoping that someone might be able to point out where I am going wrong.

I simply want to use a label with the added functionality of being able to display the text with a border where the text color is defined, the border color is defined and the border width is defined, along with all the normal attributes associated with the control

I thought that using a label named BorderLabel1 would distinguish the it from the normal Label control.

I am looking forward to your advice and guidance

Regards,
Antony.]]></description>
			<content:encoded><![CDATA[<div>Hello All,<br />
<br />
I have been struggling with a little project that needs a label to contain text with an outline aka stroke.<br />
The Text is white and the background in teal.  I would like to be able to add a black stroke to the text contained in a Label<br />
<br />
I came across lots of interesting code and have figured out how to create just outline text but I need to have the text white with a black outline.<br />
<br />
The code I have been trying to use to achieve this is as follows<br />
<br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<hr /><code class="bbcode_code"><br />
Imports System.Drawing.Drawing2D<br />
<br />
Public Class BorderLabel<br />
&nbsp; &nbsp; Inherits Label<br />
&nbsp; &nbsp; Public outline_color As Color = Color.Black<br />
&nbsp; &nbsp; Public border_thickness As Integer = 5<br />
&nbsp; &nbsp; Public Sub New()<br />
&nbsp; &nbsp; &nbsp; &nbsp; MyBase.New<br />
&nbsp; &nbsp; End Sub<br />
<br />
<br />
&nbsp; &nbsp; Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)<br />
&nbsp; &nbsp; &nbsp; &nbsp; e.Graphics.FillRectangle(New SolidBrush(BackColor), ClientRectangle)<br />
&nbsp; &nbsp; &nbsp; &nbsp; Dim gp As GraphicsPath = New GraphicsPath<br />
&nbsp; &nbsp; &nbsp; &nbsp; Dim outline As Pen = New Pen(Me.outline_color, Me.border_thickness)<br />
&nbsp; &nbsp; &nbsp; &nbsp; Dim sf As StringFormat = New StringFormat<br />
&nbsp; &nbsp; &nbsp; &nbsp; Dim foreBrush As Brush = New SolidBrush(ForeColor)<br />
&nbsp; &nbsp; &nbsp; &nbsp; gp.AddString(GV.Text, Font.FontFamily, CType(Font.Style, Integer), Font.Size, ClientRectangle, sf)<br />
&nbsp; &nbsp; &nbsp; &nbsp; e.Graphics.ScaleTransform(1.3!, 1.35!)<br />
&nbsp; &nbsp; &nbsp; &nbsp; e.Graphics.SmoothingMode = SmoothingMode.HighQuality<br />
&nbsp; &nbsp; &nbsp; &nbsp; e.Graphics.DrawPath(outline, gp)<br />
&nbsp; &nbsp; &nbsp; &nbsp; e.Graphics.FillPath(foreBrush, gp)<br />
&nbsp; &nbsp; End Sub<br />
End Class</code><hr />
</div>This isn't my code but it does seem to indicate that it should do as I want.<br />
I created a new project to test this and just using the defaults<br />
Form1<br />
and a label named BorderLabel1 with some text &quot;Test TEXT&quot;<br />
<br />
So this is where I fall down.  I cannot get it to work at all and am hoping that someone might be able to point out where I am going wrong.<br />
<br />
I simply want to use a label with the added functionality of being able to display the text with a border where the text color is defined, the border color is defined and the border width is defined, along with all the normal attributes associated with the control<br />
<br />
I thought that using a label named BorderLabel1 would distinguish the it from the normal Label control.<br />
<br />
I am looking forward to your advice and guidance<br />
<br />
Regards,<br />
Antony.</div>

]]></content:encoded>
			<category domain="https://www.vbforums.com/forumdisplay.php?25-Visual-Basic-NET">Visual Basic .NET</category>
			<dc:creator>AntonyL</dc:creator>
			<guid isPermaLink="true">https://www.vbforums.com/showthread.php?912024-Outline-Text-in-a-Label</guid>
		</item>
		<item>
			<title>VS 2022 Passing Multiple Parameters Between Forms</title>
			<link>https://www.vbforums.com/showthread.php?912021-Passing-Multiple-Parameters-Between-Forms&amp;goto=newpost</link>
			<pubDate>Fri, 15 May 2026 19:17:52 GMT</pubDate>
			<description><![CDATA[I have been trying to figure out, albeit unsuccessfully, the magic trick for passing multiple parameters between Forms. 

The first form (frmReportLauncher) is used to select which report (of 9) to generate, and the second (frmReportBrowser) generates and displays the appropriate (unfortunately, Crystal) report in a viewer named crvReportViewer. Unless someone has a better idea, I am attempting to pass the appropriate DataSource, report Query (SQL), .rpt name, and a string to display in the report header. Right now I'm injecting the parameters into a function on the second Form to produce the report.

I've looked at countless posts related to passing parameters between forms. Most of these discuss passing a _single_ parameter, which is fairly easy to do; I already do this elsewhere in my application. A handful discuss passing more than one parameter, but pretty much keep it to two. I figured expanding the scale would work, but no joy. I've tried both a public property approach and a constructor overload approach, but neither worked. I'm hoping someone could give (or point to) an example I can follow to make things work because at this point I have no idea how to make it happen.

TBH, I would rather use FastReports (OpenSource), but unfortunately it doesn't want to work for me either and all examples are C#, which I don't know at all. Using Crystal is a last-resort thing and my headaches are exacerbated by its not working with VS2026; it works with VS2022 though...]]></description>
			<content:encoded><![CDATA[<div>I have been trying to figure out, albeit unsuccessfully, the magic trick for passing multiple parameters between Forms. <br />
<br />
The first form (<font color="#0000cd"><span style="font-family: lucida console">frmReportLauncher</span></font>) is used to select which report (of 9) to generate, and the second (<span style="font-family: lucida console"><font color="#0000cd">frmReportBrowser</font></span>) generates and displays the appropriate (unfortunately, Crystal) report in a viewer named <span style="font-family: lucida console"><font color="#0000cd">crvReportViewer</font></span>. Unless someone has a better idea, I am attempting to pass the appropriate DataSource, report Query (SQL), .rpt name, and a string to display in the report header. Right now I'm injecting the parameters into a function on the second Form to produce the report.<br />
<br />
I've looked at countless posts related to passing parameters between forms. Most of these discuss passing a <u><i>single</i></u> parameter, which is fairly easy to do; I already do this elsewhere in my application. A handful discuss passing more than one parameter, but pretty much keep it to two. I figured expanding the scale would work, but no joy. I've tried both a public property approach and a constructor overload approach, but neither worked. I'm hoping someone could give (or point to) an example I can follow to make things work because at this point I have no idea how to make it happen.<br />
<br />
TBH, I would rather use FastReports (OpenSource), but unfortunately it doesn't want to work for me either and all examples are C#, which I don't know at all. Using Crystal is a last-resort thing and my headaches are exacerbated by its not working with VS2026; it works with VS2022 though...</div>

]]></content:encoded>
			<category domain="https://www.vbforums.com/forumdisplay.php?25-Visual-Basic-NET">Visual Basic .NET</category>
			<dc:creator>Erlkoenig</dc:creator>
			<guid isPermaLink="true">https://www.vbforums.com/showthread.php?912021-Passing-Multiple-Parameters-Between-Forms</guid>
		</item>
		<item>
			<title>Question about teaching and grading tools</title>
			<link>https://www.vbforums.com/showthread.php?912020-Question-about-teaching-and-grading-tools&amp;goto=newpost</link>
			<pubDate>Fri, 15 May 2026 10:27:59 GMT</pubDate>
			<description>I teach a visual basic programming class and I have been using the cengage tools for class management.

I hate these tools and I want to move to an open source solution.

What I need is an efficient tool for grading assignments. Something that runs the program and validates the outputs.

Does anybody have any ideas?</description>
			<content:encoded><![CDATA[<div>I teach a visual basic programming class and I have been using the cengage tools for class management.<br />
<br />
I hate these tools and I want to move to an open source solution.<br />
<br />
What I need is an efficient tool for grading assignments. Something that runs the program and validates the outputs.<br />
<br />
Does anybody have any ideas?</div>

]]></content:encoded>
			<category domain="https://www.vbforums.com/forumdisplay.php?25-Visual-Basic-NET">Visual Basic .NET</category>
			<dc:creator>Oscillate</dc:creator>
			<guid isPermaLink="true">https://www.vbforums.com/showthread.php?912020-Question-about-teaching-and-grading-tools</guid>
		</item>
		<item>
			<title><![CDATA[[RESOLVED] Getting information to process]]></title>
			<link>https://www.vbforums.com/showthread.php?912018-RESOLVED-Getting-information-to-process&amp;goto=newpost</link>
			<pubDate>Thu, 14 May 2026 19:11:46 GMT</pubDate>
			<description>Hi.  I am new to VB.NET, prefer vb.6.  I wrote a program in NET to run several console programs sequentially.  That works fine.  The console programs have already been written.  At the end of these programs I have a MsgBox to tell me when the program is complete.  When I use the new program, to execute these sequentially, the msgbox(s0 are not necessary.  However, I would rather keep the option of being able to run these programs individually or from the new program.  Without passing an argument to the programs, how can i determine when to execute the msgbox statements.

Thanks</description>
			<content:encoded><![CDATA[<div>Hi.  I am new to VB.NET, prefer vb.6.  I wrote a program in NET to run several console programs sequentially.  That works fine.  The console programs have already been written.  At the end of these programs I have a MsgBox to tell me when the program is complete.  When I use the new program, to execute these sequentially, the msgbox(s0 are not necessary.  However, I would rather keep the option of being able to run these programs individually or from the new program.  Without passing an argument to the programs, how can i determine when to execute the msgbox statements.<br />
<br />
Thanks</div>

]]></content:encoded>
			<category domain="https://www.vbforums.com/forumdisplay.php?25-Visual-Basic-NET">Visual Basic .NET</category>
			<dc:creator>AccessShell</dc:creator>
			<guid isPermaLink="true">https://www.vbforums.com/showthread.php?912018-RESOLVED-Getting-information-to-process</guid>
		</item>
		<item>
			<title>Type Expected error when attempting to use Chart</title>
			<link>https://www.vbforums.com/showthread.php?912011-Type-Expected-error-when-attempting-to-use-Chart&amp;goto=newpost</link>
			<pubDate>Mon, 11 May 2026 04:05:58 GMT</pubDate>
			<description><![CDATA[Hi Guys,

I am getting a Type Expected error when I am using the following simple line of code

Dim chart as new Chart()

I have searched extensively but am unable to find out why the error occurs or what to do about it.
I am trying to create a simple XY Column Graph with Positive(Blue) and negative(Red) values on the Y axis and Time on the X axis

Here is the code so far.

Code:
---------

Imports System.Security.Cryptography.X509Certificates
Imports System.Windows.Forms.DataVisualization.Charting

Public Class Form1 'ColumnChartExample
    ' summary
    ' Windows Forms example for a column chart with time (seconds) on the X-axis
    ' and positive/negative values on the Y-axis.
    ' Positive values are displayed in blue; negative values are displayed in red.


    Inherits Form

    Dim chart As New Chart()
    Private chartArea As ChartArea
    Private series As Series

    Public AnalysisValues(10) As Integer
    Private Sub Form_Load()

    End Sub
    Private Sub Data()
        AnalysisValues = {1, 3, 4, 3, 2, 1, 0, -1, -3, -4}
    End Sub

    Public Sub New()
        ' Initialize the form
        Me.Text = "Column Chart Example"
        Me.Size = New Drawing.Size(900, 600)

        ' Create the chart control
        chart = New Chart()
        chart.Dock = DockStyle.Fill

        ' Create and configure the chart area
        chartArea = New ChartArea("MainArea")
        chartArea.AxisX.Title = "Time (seconds)"
        chartArea.AxisY.Title = "Value"

        ' Add a zero-crossing line on the Y-axis for clarity
        chartArea.AxisX.Crossing = 0
        chartArea.AxisY.Crossing = 0
        chartArea.AxisY.IntervalAutoMode = IntervalAutoMode.VariableCount

        ' Optional: customize grid lines
        chartArea.AxisX.MajorGrid.LineColor = Drawing.Color.LightGray
        chartArea.AxisY.MajorGrid.LineColor = Drawing.Color.LightGray

        chart.ChartAreas.Add(chartArea)

        ' Create and configure the data series
        series = New Series("DataSeries")
        series.ChartType = SeriesChartType.Column
        series.ChartArea = "MainArea"
        series.IsValueShownAsLabel = True
        series.LabelForeColor = Drawing.Color.Black

        ' Sample data: time in seconds and corresponding positive/negative values
        Dim data As New List(Of Tuple(Of Double, Double)) From {
            Tuple.Create(1.0, 15.0),
            Tuple.Create(2.0, -8.0),
            Tuple.Create(3.0, 22.0),
            Tuple.Create(4.0, -5.0),
            Tuple.Create(5.0, -18.0),
            Tuple.Create(6.0, 7.0),
            Tuple.Create(7.0, 0.0),
            Tuple.Create(8.0, -12.0),
            Tuple.Create(9.0, 30.0),
            Tuple.Create(10.0, -3.0)
        }

        ' Populate the series and color each column based on positive/negative value
        For Each point In data
            Dim dp As New DataPoint()
            dp.SetValueXY(point.Item1, point.Item2)
            dp.AxisLabel = point.Item1.ToString() ' X-axis label shows time in seconds

            ' Color logic: blue for positive, red for negative
            If point.Item2 >= 0 Then
                dp.Color = Drawing.Color.Blue
            Else
                dp.Color = Drawing.Color.Red
            End If

            series.Points.Add(dp)
        Next

        chart.Series.Add(series)

        ' Add a legend for clarity
        Dim legend As New Legend("MainLegend")
        legend.Docking = Docking.Top
        chart.Legends.Add(legend)

        ' Add the chart to the form
        Me.Controls.Add(chart)
    End Sub

    ' summary
    ' Entry point to run the form.

        Public Shared Sub Main()
            Application.EnableVisualStyles()
            Application.SetCompatibleTextRenderingDefault(False)
        Application.Run(New Form1())   '(New ColumnChartExample())
    End Sub

    End Class
---------
Hope you are able to shed some light on my mistake?

Regards,
Antony]]></description>
			<content:encoded><![CDATA[<div>Hi Guys,<br />
<br />
I am getting a Type Expected error when I am using the following simple line of code<br />
<br />
Dim chart as new Chart()<br />
<br />
I have searched extensively but am unable to find out why the error occurs or what to do about it.<br />
I am trying to create a simple XY Column Graph with Positive(Blue) and negative(Red) values on the Y axis and Time on the X axis<br />
<br />
Here is the code so far.<br />
<div class="bbcode_container">
	<div class="bbcode_description">Code:</div>
	<hr /><code class="bbcode_code"><br />
Imports System.Security.Cryptography.X509Certificates<br />
Imports System.Windows.Forms.DataVisualization.Charting<br />
<br />
Public Class Form1 'ColumnChartExample<br />
&nbsp; &nbsp; ' summary<br />
&nbsp; &nbsp; ' Windows Forms example for a column chart with time (seconds) on the X-axis<br />
&nbsp; &nbsp; ' and positive/negative values on the Y-axis.<br />
&nbsp; &nbsp; ' Positive values are displayed in blue; negative values are displayed in red.<br />
<br />
<br />
&nbsp; &nbsp; Inherits Form<br />
<br />
&nbsp; &nbsp; Dim chart As New Chart()<br />
&nbsp; &nbsp; Private chartArea As ChartArea<br />
&nbsp; &nbsp; Private series As Series<br />
<br />
&nbsp; &nbsp; Public AnalysisValues(10) As Integer<br />
&nbsp; &nbsp; Private Sub Form_Load()<br />
<br />
&nbsp; &nbsp; End Sub<br />
&nbsp; &nbsp; Private Sub Data()<br />
&nbsp; &nbsp; &nbsp; &nbsp; AnalysisValues = {1, 3, 4, 3, 2, 1, 0, -1, -3, -4}<br />
&nbsp; &nbsp; End Sub<br />
<br />
&nbsp; &nbsp; Public Sub New()<br />
&nbsp; &nbsp; &nbsp; &nbsp; ' Initialize the form<br />
&nbsp; &nbsp; &nbsp; &nbsp; Me.Text = &quot;Column Chart Example&quot;<br />
&nbsp; &nbsp; &nbsp; &nbsp; Me.Size = New Drawing.Size(900, 600)<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; ' Create the chart control<br />
&nbsp; &nbsp; &nbsp; &nbsp; chart = New Chart()<br />
&nbsp; &nbsp; &nbsp; &nbsp; chart.Dock = DockStyle.Fill<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; ' Create and configure the chart area<br />
&nbsp; &nbsp; &nbsp; &nbsp; chartArea = New ChartArea(&quot;MainArea&quot;)<br />
&nbsp; &nbsp; &nbsp; &nbsp; chartArea.AxisX.Title = &quot;Time (seconds)&quot;<br />
&nbsp; &nbsp; &nbsp; &nbsp; chartArea.AxisY.Title = &quot;Value&quot;<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; ' Add a zero-crossing line on the Y-axis for clarity<br />
&nbsp; &nbsp; &nbsp; &nbsp; chartArea.AxisX.Crossing = 0<br />
&nbsp; &nbsp; &nbsp; &nbsp; chartArea.AxisY.Crossing = 0<br />
&nbsp; &nbsp; &nbsp; &nbsp; chartArea.AxisY.IntervalAutoMode = IntervalAutoMode.VariableCount<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; ' Optional: customize grid lines<br />
&nbsp; &nbsp; &nbsp; &nbsp; chartArea.AxisX.MajorGrid.LineColor = Drawing.Color.LightGray<br />
&nbsp; &nbsp; &nbsp; &nbsp; chartArea.AxisY.MajorGrid.LineColor = Drawing.Color.LightGray<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; chart.ChartAreas.Add(chartArea)<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; ' Create and configure the data series<br />
&nbsp; &nbsp; &nbsp; &nbsp; series = New Series(&quot;DataSeries&quot;)<br />
&nbsp; &nbsp; &nbsp; &nbsp; series.ChartType = SeriesChartType.Column<br />
&nbsp; &nbsp; &nbsp; &nbsp; series.ChartArea = &quot;MainArea&quot;<br />
&nbsp; &nbsp; &nbsp; &nbsp; series.IsValueShownAsLabel = True<br />
&nbsp; &nbsp; &nbsp; &nbsp; series.LabelForeColor = Drawing.Color.Black<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; ' Sample data: time in seconds and corresponding positive/negative values<br />
&nbsp; &nbsp; &nbsp; &nbsp; Dim data As New List(Of Tuple(Of Double, Double)) From {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Tuple.Create(1.0, 15.0),<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Tuple.Create(2.0, -8.0),<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Tuple.Create(3.0, 22.0),<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Tuple.Create(4.0, -5.0),<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Tuple.Create(5.0, -18.0),<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Tuple.Create(6.0, 7.0),<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Tuple.Create(7.0, 0.0),<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Tuple.Create(8.0, -12.0),<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Tuple.Create(9.0, 30.0),<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Tuple.Create(10.0, -3.0)<br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; ' Populate the series and color each column based on positive/negative value<br />
&nbsp; &nbsp; &nbsp; &nbsp; For Each point In data<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Dim dp As New DataPoint()<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dp.SetValueXY(point.Item1, point.Item2)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dp.AxisLabel = point.Item1.ToString() ' X-axis label shows time in seconds<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ' Color logic: blue for positive, red for negative<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; If point.Item2 &gt;= 0 Then<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dp.Color = Drawing.Color.Blue<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Else<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dp.Color = Drawing.Color.Red<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; End If<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; series.Points.Add(dp)<br />
&nbsp; &nbsp; &nbsp; &nbsp; Next<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; chart.Series.Add(series)<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; ' Add a legend for clarity<br />
&nbsp; &nbsp; &nbsp; &nbsp; Dim legend As New Legend(&quot;MainLegend&quot;)<br />
&nbsp; &nbsp; &nbsp; &nbsp; legend.Docking = Docking.Top<br />
&nbsp; &nbsp; &nbsp; &nbsp; chart.Legends.Add(legend)<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; ' Add the chart to the form<br />
&nbsp; &nbsp; &nbsp; &nbsp; Me.Controls.Add(chart)<br />
&nbsp; &nbsp; End Sub<br />
<br />
&nbsp; &nbsp; ' summary<br />
&nbsp; &nbsp; ' Entry point to run the form.<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; Public Shared Sub Main()<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Application.EnableVisualStyles()<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Application.SetCompatibleTextRenderingDefault(False)<br />
&nbsp; &nbsp; &nbsp; &nbsp; Application.Run(New Form1())&nbsp;  '(New ColumnChartExample())<br />
&nbsp; &nbsp; End Sub<br />
<br />
&nbsp; &nbsp; End Class</code><hr />
</div>Hope you are able to shed some light on my mistake?<br />
<br />
Regards,<br />
Antony</div>

]]></content:encoded>
			<category domain="https://www.vbforums.com/forumdisplay.php?25-Visual-Basic-NET">Visual Basic .NET</category>
			<dc:creator>AntonyL</dc:creator>
			<guid isPermaLink="true">https://www.vbforums.com/showthread.php?912011-Type-Expected-error-when-attempting-to-use-Chart</guid>
		</item>
	</channel>
</rss>
