Drawing circles from array to a Form

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;







up vote
6
down vote

favorite












I've actually been struggling with painting with VB.Net for a few weeks. All I know is that I shouldn't use CreateGraphics if I can avoid it, so I've done just that. One of the community-challenge questions comes from a CodeGolf challenge that requires users to draw sprockets.



This is only my beginning of that. I've never displayed anything I haven't drawn in excel. At first I tried a Class of sprockets, but it wouldn't fill my List properly, so I've boiled it down to



  1. populating an array

  2. passing that array to the form

  3. Painting my circles.

Essentially I read the input, convert it to integer array, send that to the form and draw the circles. I've probably made it way too complicated, but like I said, I've struggled for a few weeks, which is why I'm here. Parsing the input was pretty tricky to me, actually.



Input



Comes in the form of (sets of) 3 integers (x-position, y-position, radius) e.g.




(0, 0, 16), (100, 0, 16), (100, 100, 12), (50, 50, 24), (0, 100, 12)



Output



enter image description here



Standard Module



Option Explicit On
Option Strict On
Option Infer On
Option Compare Text
Imports System.IO
Module Module1
Const INPUT_PATH As String = "C:Tempgearinput.txt"
Public delimiter() As String = "),"
Sub Main()
Dim inputData() As String
inputData = GetInput()
Dim sprocketData() As String = Custom_Split(inputData(0))
Dim paintingdata(,) As Integer = StringToIntArray(sprocketData)
Dim targetForm As New Form1
targetForm.Visible = True
targetForm.DrawSprockets(targetForm, paintingdata)
End Sub
Private Function Custom_Split(ByVal stringToSplit As String) As String()
stringToSplit = stringToSplit.Replace("(", String.Empty)
stringToSplit = stringToSplit.Replace(" ", String.Empty)
Dim stringArray() As String = stringToSplit.Split(delimiter, StringSplitOptions.RemoveEmptyEntries)
stringArray(stringArray.Length - 1) = stringArray(stringArray.Length - 1).Replace(")", String.Empty)
Return stringArray
End Function
Private Function StringToIntArray(ByVal sprocketdata() As String) As Integer(,)
Dim firstDimensionSize As Integer = sprocketdata.GetUpperBound(0)
Dim integerArray(firstDimensionSize, 2) As Integer
Dim tempString() As String
For i As Integer = 0 To firstDimensionSize
tempString = sprocketdata(i).Split(","c)
For j = 0 To 2
integerArray(i, j) = Convert.ToInt32(tempString(j))
Next
Next
Return integerArray
End Function

Private Function GetInput() As String()
Return File.ReadAllLines(INPUT_PATH)
End Function
End Module


Form Code



Imports System.Drawing
Imports System.Windows.Forms

Public Class Form1
Const BUFFER As Integer = 20
Dim xValue As Integer
Dim yValue As Integer
Dim pRadius As Integer
Dim paintData(,) As Integer
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load

End Sub
Public Shared Sub DrawSprockets(ByVal myForm As Form1, ByVal dataArray(,) As Integer)
myForm.paintData = dataArray
For i As Integer = 0 To myForm.paintData.GetUpperBound(0)
myForm.paintData(i, 0) += 10
myForm.paintData(i, 1) += 10
Next
myForm.Refresh()
End Sub


Private Sub Form1_Paint(ByVal sender As Object, e As PaintEventArgs) Handles MyBase.Paint
Dim myPen As Pen

myPen = New Pen(Brushes.Black)

For i As Integer = 0 To paintData.GetUpperBound(0)
e.Graphics.DrawEllipse(myPen, New Rectangle(paintData(i, 0), paintData(i, 1), paintData(i, 2), paintData(i, 2)))
e.Graphics.FillEllipse(Brushes.Black, New Rectangle(paintData(i, 0), paintData(i, 1), paintData(i, 2), paintData(i, 2)))

Next

End Sub

End Class






share|improve this question



























    up vote
    6
    down vote

    favorite












    I've actually been struggling with painting with VB.Net for a few weeks. All I know is that I shouldn't use CreateGraphics if I can avoid it, so I've done just that. One of the community-challenge questions comes from a CodeGolf challenge that requires users to draw sprockets.



    This is only my beginning of that. I've never displayed anything I haven't drawn in excel. At first I tried a Class of sprockets, but it wouldn't fill my List properly, so I've boiled it down to



    1. populating an array

    2. passing that array to the form

    3. Painting my circles.

    Essentially I read the input, convert it to integer array, send that to the form and draw the circles. I've probably made it way too complicated, but like I said, I've struggled for a few weeks, which is why I'm here. Parsing the input was pretty tricky to me, actually.



    Input



    Comes in the form of (sets of) 3 integers (x-position, y-position, radius) e.g.




    (0, 0, 16), (100, 0, 16), (100, 100, 12), (50, 50, 24), (0, 100, 12)



    Output



    enter image description here



    Standard Module



    Option Explicit On
    Option Strict On
    Option Infer On
    Option Compare Text
    Imports System.IO
    Module Module1
    Const INPUT_PATH As String = "C:Tempgearinput.txt"
    Public delimiter() As String = "),"
    Sub Main()
    Dim inputData() As String
    inputData = GetInput()
    Dim sprocketData() As String = Custom_Split(inputData(0))
    Dim paintingdata(,) As Integer = StringToIntArray(sprocketData)
    Dim targetForm As New Form1
    targetForm.Visible = True
    targetForm.DrawSprockets(targetForm, paintingdata)
    End Sub
    Private Function Custom_Split(ByVal stringToSplit As String) As String()
    stringToSplit = stringToSplit.Replace("(", String.Empty)
    stringToSplit = stringToSplit.Replace(" ", String.Empty)
    Dim stringArray() As String = stringToSplit.Split(delimiter, StringSplitOptions.RemoveEmptyEntries)
    stringArray(stringArray.Length - 1) = stringArray(stringArray.Length - 1).Replace(")", String.Empty)
    Return stringArray
    End Function
    Private Function StringToIntArray(ByVal sprocketdata() As String) As Integer(,)
    Dim firstDimensionSize As Integer = sprocketdata.GetUpperBound(0)
    Dim integerArray(firstDimensionSize, 2) As Integer
    Dim tempString() As String
    For i As Integer = 0 To firstDimensionSize
    tempString = sprocketdata(i).Split(","c)
    For j = 0 To 2
    integerArray(i, j) = Convert.ToInt32(tempString(j))
    Next
    Next
    Return integerArray
    End Function

    Private Function GetInput() As String()
    Return File.ReadAllLines(INPUT_PATH)
    End Function
    End Module


    Form Code



    Imports System.Drawing
    Imports System.Windows.Forms

    Public Class Form1
    Const BUFFER As Integer = 20
    Dim xValue As Integer
    Dim yValue As Integer
    Dim pRadius As Integer
    Dim paintData(,) As Integer
    Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load

    End Sub
    Public Shared Sub DrawSprockets(ByVal myForm As Form1, ByVal dataArray(,) As Integer)
    myForm.paintData = dataArray
    For i As Integer = 0 To myForm.paintData.GetUpperBound(0)
    myForm.paintData(i, 0) += 10
    myForm.paintData(i, 1) += 10
    Next
    myForm.Refresh()
    End Sub


    Private Sub Form1_Paint(ByVal sender As Object, e As PaintEventArgs) Handles MyBase.Paint
    Dim myPen As Pen

    myPen = New Pen(Brushes.Black)

    For i As Integer = 0 To paintData.GetUpperBound(0)
    e.Graphics.DrawEllipse(myPen, New Rectangle(paintData(i, 0), paintData(i, 1), paintData(i, 2), paintData(i, 2)))
    e.Graphics.FillEllipse(Brushes.Black, New Rectangle(paintData(i, 0), paintData(i, 1), paintData(i, 2), paintData(i, 2)))

    Next

    End Sub

    End Class






    share|improve this question























      up vote
      6
      down vote

      favorite









      up vote
      6
      down vote

      favorite











      I've actually been struggling with painting with VB.Net for a few weeks. All I know is that I shouldn't use CreateGraphics if I can avoid it, so I've done just that. One of the community-challenge questions comes from a CodeGolf challenge that requires users to draw sprockets.



      This is only my beginning of that. I've never displayed anything I haven't drawn in excel. At first I tried a Class of sprockets, but it wouldn't fill my List properly, so I've boiled it down to



      1. populating an array

      2. passing that array to the form

      3. Painting my circles.

      Essentially I read the input, convert it to integer array, send that to the form and draw the circles. I've probably made it way too complicated, but like I said, I've struggled for a few weeks, which is why I'm here. Parsing the input was pretty tricky to me, actually.



      Input



      Comes in the form of (sets of) 3 integers (x-position, y-position, radius) e.g.




      (0, 0, 16), (100, 0, 16), (100, 100, 12), (50, 50, 24), (0, 100, 12)



      Output



      enter image description here



      Standard Module



      Option Explicit On
      Option Strict On
      Option Infer On
      Option Compare Text
      Imports System.IO
      Module Module1
      Const INPUT_PATH As String = "C:Tempgearinput.txt"
      Public delimiter() As String = "),"
      Sub Main()
      Dim inputData() As String
      inputData = GetInput()
      Dim sprocketData() As String = Custom_Split(inputData(0))
      Dim paintingdata(,) As Integer = StringToIntArray(sprocketData)
      Dim targetForm As New Form1
      targetForm.Visible = True
      targetForm.DrawSprockets(targetForm, paintingdata)
      End Sub
      Private Function Custom_Split(ByVal stringToSplit As String) As String()
      stringToSplit = stringToSplit.Replace("(", String.Empty)
      stringToSplit = stringToSplit.Replace(" ", String.Empty)
      Dim stringArray() As String = stringToSplit.Split(delimiter, StringSplitOptions.RemoveEmptyEntries)
      stringArray(stringArray.Length - 1) = stringArray(stringArray.Length - 1).Replace(")", String.Empty)
      Return stringArray
      End Function
      Private Function StringToIntArray(ByVal sprocketdata() As String) As Integer(,)
      Dim firstDimensionSize As Integer = sprocketdata.GetUpperBound(0)
      Dim integerArray(firstDimensionSize, 2) As Integer
      Dim tempString() As String
      For i As Integer = 0 To firstDimensionSize
      tempString = sprocketdata(i).Split(","c)
      For j = 0 To 2
      integerArray(i, j) = Convert.ToInt32(tempString(j))
      Next
      Next
      Return integerArray
      End Function

      Private Function GetInput() As String()
      Return File.ReadAllLines(INPUT_PATH)
      End Function
      End Module


      Form Code



      Imports System.Drawing
      Imports System.Windows.Forms

      Public Class Form1
      Const BUFFER As Integer = 20
      Dim xValue As Integer
      Dim yValue As Integer
      Dim pRadius As Integer
      Dim paintData(,) As Integer
      Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load

      End Sub
      Public Shared Sub DrawSprockets(ByVal myForm As Form1, ByVal dataArray(,) As Integer)
      myForm.paintData = dataArray
      For i As Integer = 0 To myForm.paintData.GetUpperBound(0)
      myForm.paintData(i, 0) += 10
      myForm.paintData(i, 1) += 10
      Next
      myForm.Refresh()
      End Sub


      Private Sub Form1_Paint(ByVal sender As Object, e As PaintEventArgs) Handles MyBase.Paint
      Dim myPen As Pen

      myPen = New Pen(Brushes.Black)

      For i As Integer = 0 To paintData.GetUpperBound(0)
      e.Graphics.DrawEllipse(myPen, New Rectangle(paintData(i, 0), paintData(i, 1), paintData(i, 2), paintData(i, 2)))
      e.Graphics.FillEllipse(Brushes.Black, New Rectangle(paintData(i, 0), paintData(i, 1), paintData(i, 2), paintData(i, 2)))

      Next

      End Sub

      End Class






      share|improve this question













      I've actually been struggling with painting with VB.Net for a few weeks. All I know is that I shouldn't use CreateGraphics if I can avoid it, so I've done just that. One of the community-challenge questions comes from a CodeGolf challenge that requires users to draw sprockets.



      This is only my beginning of that. I've never displayed anything I haven't drawn in excel. At first I tried a Class of sprockets, but it wouldn't fill my List properly, so I've boiled it down to



      1. populating an array

      2. passing that array to the form

      3. Painting my circles.

      Essentially I read the input, convert it to integer array, send that to the form and draw the circles. I've probably made it way too complicated, but like I said, I've struggled for a few weeks, which is why I'm here. Parsing the input was pretty tricky to me, actually.



      Input



      Comes in the form of (sets of) 3 integers (x-position, y-position, radius) e.g.




      (0, 0, 16), (100, 0, 16), (100, 100, 12), (50, 50, 24), (0, 100, 12)



      Output



      enter image description here



      Standard Module



      Option Explicit On
      Option Strict On
      Option Infer On
      Option Compare Text
      Imports System.IO
      Module Module1
      Const INPUT_PATH As String = "C:Tempgearinput.txt"
      Public delimiter() As String = "),"
      Sub Main()
      Dim inputData() As String
      inputData = GetInput()
      Dim sprocketData() As String = Custom_Split(inputData(0))
      Dim paintingdata(,) As Integer = StringToIntArray(sprocketData)
      Dim targetForm As New Form1
      targetForm.Visible = True
      targetForm.DrawSprockets(targetForm, paintingdata)
      End Sub
      Private Function Custom_Split(ByVal stringToSplit As String) As String()
      stringToSplit = stringToSplit.Replace("(", String.Empty)
      stringToSplit = stringToSplit.Replace(" ", String.Empty)
      Dim stringArray() As String = stringToSplit.Split(delimiter, StringSplitOptions.RemoveEmptyEntries)
      stringArray(stringArray.Length - 1) = stringArray(stringArray.Length - 1).Replace(")", String.Empty)
      Return stringArray
      End Function
      Private Function StringToIntArray(ByVal sprocketdata() As String) As Integer(,)
      Dim firstDimensionSize As Integer = sprocketdata.GetUpperBound(0)
      Dim integerArray(firstDimensionSize, 2) As Integer
      Dim tempString() As String
      For i As Integer = 0 To firstDimensionSize
      tempString = sprocketdata(i).Split(","c)
      For j = 0 To 2
      integerArray(i, j) = Convert.ToInt32(tempString(j))
      Next
      Next
      Return integerArray
      End Function

      Private Function GetInput() As String()
      Return File.ReadAllLines(INPUT_PATH)
      End Function
      End Module


      Form Code



      Imports System.Drawing
      Imports System.Windows.Forms

      Public Class Form1
      Const BUFFER As Integer = 20
      Dim xValue As Integer
      Dim yValue As Integer
      Dim pRadius As Integer
      Dim paintData(,) As Integer
      Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load

      End Sub
      Public Shared Sub DrawSprockets(ByVal myForm As Form1, ByVal dataArray(,) As Integer)
      myForm.paintData = dataArray
      For i As Integer = 0 To myForm.paintData.GetUpperBound(0)
      myForm.paintData(i, 0) += 10
      myForm.paintData(i, 1) += 10
      Next
      myForm.Refresh()
      End Sub


      Private Sub Form1_Paint(ByVal sender As Object, e As PaintEventArgs) Handles MyBase.Paint
      Dim myPen As Pen

      myPen = New Pen(Brushes.Black)

      For i As Integer = 0 To paintData.GetUpperBound(0)
      e.Graphics.DrawEllipse(myPen, New Rectangle(paintData(i, 0), paintData(i, 1), paintData(i, 2), paintData(i, 2)))
      e.Graphics.FillEllipse(Brushes.Black, New Rectangle(paintData(i, 0), paintData(i, 1), paintData(i, 2), paintData(i, 2)))

      Next

      End Sub

      End Class








      share|improve this question












      share|improve this question




      share|improve this question








      edited Mar 28 at 4:04









      200_success

      123k14142399




      123k14142399









      asked Mar 24 at 0:13









      Raystafarian

      5,4331046




      5,4331046




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          3
          down vote



          accepted










          The overall structure of your code looks good, but the readability is a tad poor. You should always strive to follow the Framework Design Guidelines. Use proper naming and add a few linebreaks.



          Rather than using arrays, create a dedicated "Sprocket" class to hold the parsed input data.



          Public Class Sprocket
          Public Property X As Integer
          Public Property Y As Integer
          Public Property R As Integer
          End Class


          Now, if you add the rest of the non-numeric characters to the separator list you could actually read and parse the file in two lines. (Though you ougth to use the line-continuation character for readability as seen at the bottom)



          Dim numbers = File.ReadAllText("C:Tempgearinput.txt").Split($"Environment.NewLine ,)(".ToCharArray(), StringSplitOptions.RemoveEmptyEntries).Select(Function(n) Integer.Parse(n)).ToArray()
          Dim sprockets = Enumerable.Range(0, (numbers.Length 3)).Select(Function(i) New Sprocket With .X = numbers(((i * 3) + 0)), .Y = numbers(((i * 3) + 1)), .R = numbers(((i * 3) + 2))).ToArray()



          Window



          Sprocket.vb



          Public Class Sprocket

          Public Property X As Integer
          Public Property Y As Integer
          Public Property R As Integer

          Public Overrides Function ToString() As String
          Return $" X=Me.X, Y=Me.Y, R=Me.R "
          End Function

          End Class


          Program.vb



          Public Module Program

          <STAThread>
          Public Sub Main()

          'TODO: Read file
          Dim input = "(0, 0, 16), (100, 0, 16), (100, 100, 12), (50, 50, 24), (0, 100, 12)"

          Dim numbers = input _
          .Split($"Environment.NewLine ,)(".ToCharArray(), StringSplitOptions.RemoveEmptyEntries) _
          .Select(Function(n) Integer.Parse(n)) _
          .ToArray()

          Dim sprockets = Enumerable _
          .Range(0, (numbers.Length 3)) _
          .Select(Function(i) New Sprocket With

          .X = numbers(((i * 3) + 0)),
          .Y = numbers(((i * 3) + 1)),
          .R = numbers(((i * 3) + 2))
          ) _
          .ToArray()

          Application.EnableVisualStyles()
          Application.SetCompatibleTextRenderingDefault(False)
          Application.Run(New Window(sprockets))

          End Sub

          End Module


          Window.vb



          Public Class Window
          Inherits Form

          Private ReadOnly sprockets As Sprocket()

          Public Sub New(sprockets As Sprocket())

          If (sprockets Is Nothing) Then
          Throw New ArgumentNullException(NameOf(sprockets))
          End If

          Me.sprockets = sprockets

          Me.SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.UserPaint Or ControlStyles.OptimizedDoubleBuffer, True)

          Me.Text = "Sprockets"
          Me.AutoScaleMode = AutoScaleMode.Font
          Me.ClientSize = New Size(800, 450)

          End Sub

          Protected Overrides Sub OnPaint(e As PaintEventArgs)

          e.Graphics.Clear(Me.BackColor)
          e.Graphics.SmoothingMode = Drawing2D.SmoothingMode.HighQuality

          For Each sprocket In Me.sprockets

          Dim diameter = (sprocket.R * 2)
          Dim rect = New Rectangle(sprocket.X, sprocket.Y, diameter, diameter)

          e.Graphics.FillEllipse(Brushes.Black, rect)

          Next

          End Sub

          End Class





          share|improve this answer























          • Thanks. Haven't had a chance to read this, but I didn't want you to think I wasn't interested!
            – Raystafarian
            Mar 28 at 21:26






          • 1




            @Raystafarian No problem. As a side note: Your entry point (sub Main) looks a bit weird. No reference to Application.Run (the start of the message pump). Visual Studio auto-generate the entry point for VB.NET applications. But to manually wire up the start (as I did in the Program module) you do as follows: Double click "My project" in the solution pane. Click "Application" tab and uncheck "Enable application framework". Then choose "Sub Main" from the "Startup object" dropdown.
            – Bjørn-Roger Kringsjå
            Mar 29 at 9:32










          • Great, that's something I had no idea about - thanks
            – Raystafarian
            Mar 30 at 8:47










          • With naming, the guide is basically saying everything should be PascalCase except parameters in functions, I'm reading that correctly?
            – Raystafarian
            Mar 30 at 23:04










          • Yup. And even though the guide do not specify a convention for variables, the consensus is to use camelCase.
            – Bjørn-Roger Kringsjå
            Mar 31 at 7:01










          Your Answer




          StackExchange.ifUsing("editor", function ()
          return StackExchange.using("mathjaxEditing", function ()
          StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
          StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
          );
          );
          , "mathjax-editing");

          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "196"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          convertImagesToLinks: false,
          noModals: false,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );








           

          draft saved


          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f190344%2fdrawing-circles-from-array-to-a-form%23new-answer', 'question_page');

          );

          Post as a guest






























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          3
          down vote



          accepted










          The overall structure of your code looks good, but the readability is a tad poor. You should always strive to follow the Framework Design Guidelines. Use proper naming and add a few linebreaks.



          Rather than using arrays, create a dedicated "Sprocket" class to hold the parsed input data.



          Public Class Sprocket
          Public Property X As Integer
          Public Property Y As Integer
          Public Property R As Integer
          End Class


          Now, if you add the rest of the non-numeric characters to the separator list you could actually read and parse the file in two lines. (Though you ougth to use the line-continuation character for readability as seen at the bottom)



          Dim numbers = File.ReadAllText("C:Tempgearinput.txt").Split($"Environment.NewLine ,)(".ToCharArray(), StringSplitOptions.RemoveEmptyEntries).Select(Function(n) Integer.Parse(n)).ToArray()
          Dim sprockets = Enumerable.Range(0, (numbers.Length 3)).Select(Function(i) New Sprocket With .X = numbers(((i * 3) + 0)), .Y = numbers(((i * 3) + 1)), .R = numbers(((i * 3) + 2))).ToArray()



          Window



          Sprocket.vb



          Public Class Sprocket

          Public Property X As Integer
          Public Property Y As Integer
          Public Property R As Integer

          Public Overrides Function ToString() As String
          Return $" X=Me.X, Y=Me.Y, R=Me.R "
          End Function

          End Class


          Program.vb



          Public Module Program

          <STAThread>
          Public Sub Main()

          'TODO: Read file
          Dim input = "(0, 0, 16), (100, 0, 16), (100, 100, 12), (50, 50, 24), (0, 100, 12)"

          Dim numbers = input _
          .Split($"Environment.NewLine ,)(".ToCharArray(), StringSplitOptions.RemoveEmptyEntries) _
          .Select(Function(n) Integer.Parse(n)) _
          .ToArray()

          Dim sprockets = Enumerable _
          .Range(0, (numbers.Length 3)) _
          .Select(Function(i) New Sprocket With

          .X = numbers(((i * 3) + 0)),
          .Y = numbers(((i * 3) + 1)),
          .R = numbers(((i * 3) + 2))
          ) _
          .ToArray()

          Application.EnableVisualStyles()
          Application.SetCompatibleTextRenderingDefault(False)
          Application.Run(New Window(sprockets))

          End Sub

          End Module


          Window.vb



          Public Class Window
          Inherits Form

          Private ReadOnly sprockets As Sprocket()

          Public Sub New(sprockets As Sprocket())

          If (sprockets Is Nothing) Then
          Throw New ArgumentNullException(NameOf(sprockets))
          End If

          Me.sprockets = sprockets

          Me.SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.UserPaint Or ControlStyles.OptimizedDoubleBuffer, True)

          Me.Text = "Sprockets"
          Me.AutoScaleMode = AutoScaleMode.Font
          Me.ClientSize = New Size(800, 450)

          End Sub

          Protected Overrides Sub OnPaint(e As PaintEventArgs)

          e.Graphics.Clear(Me.BackColor)
          e.Graphics.SmoothingMode = Drawing2D.SmoothingMode.HighQuality

          For Each sprocket In Me.sprockets

          Dim diameter = (sprocket.R * 2)
          Dim rect = New Rectangle(sprocket.X, sprocket.Y, diameter, diameter)

          e.Graphics.FillEllipse(Brushes.Black, rect)

          Next

          End Sub

          End Class





          share|improve this answer























          • Thanks. Haven't had a chance to read this, but I didn't want you to think I wasn't interested!
            – Raystafarian
            Mar 28 at 21:26






          • 1




            @Raystafarian No problem. As a side note: Your entry point (sub Main) looks a bit weird. No reference to Application.Run (the start of the message pump). Visual Studio auto-generate the entry point for VB.NET applications. But to manually wire up the start (as I did in the Program module) you do as follows: Double click "My project" in the solution pane. Click "Application" tab and uncheck "Enable application framework". Then choose "Sub Main" from the "Startup object" dropdown.
            – Bjørn-Roger Kringsjå
            Mar 29 at 9:32










          • Great, that's something I had no idea about - thanks
            – Raystafarian
            Mar 30 at 8:47










          • With naming, the guide is basically saying everything should be PascalCase except parameters in functions, I'm reading that correctly?
            – Raystafarian
            Mar 30 at 23:04










          • Yup. And even though the guide do not specify a convention for variables, the consensus is to use camelCase.
            – Bjørn-Roger Kringsjå
            Mar 31 at 7:01














          up vote
          3
          down vote



          accepted










          The overall structure of your code looks good, but the readability is a tad poor. You should always strive to follow the Framework Design Guidelines. Use proper naming and add a few linebreaks.



          Rather than using arrays, create a dedicated "Sprocket" class to hold the parsed input data.



          Public Class Sprocket
          Public Property X As Integer
          Public Property Y As Integer
          Public Property R As Integer
          End Class


          Now, if you add the rest of the non-numeric characters to the separator list you could actually read and parse the file in two lines. (Though you ougth to use the line-continuation character for readability as seen at the bottom)



          Dim numbers = File.ReadAllText("C:Tempgearinput.txt").Split($"Environment.NewLine ,)(".ToCharArray(), StringSplitOptions.RemoveEmptyEntries).Select(Function(n) Integer.Parse(n)).ToArray()
          Dim sprockets = Enumerable.Range(0, (numbers.Length 3)).Select(Function(i) New Sprocket With .X = numbers(((i * 3) + 0)), .Y = numbers(((i * 3) + 1)), .R = numbers(((i * 3) + 2))).ToArray()



          Window



          Sprocket.vb



          Public Class Sprocket

          Public Property X As Integer
          Public Property Y As Integer
          Public Property R As Integer

          Public Overrides Function ToString() As String
          Return $" X=Me.X, Y=Me.Y, R=Me.R "
          End Function

          End Class


          Program.vb



          Public Module Program

          <STAThread>
          Public Sub Main()

          'TODO: Read file
          Dim input = "(0, 0, 16), (100, 0, 16), (100, 100, 12), (50, 50, 24), (0, 100, 12)"

          Dim numbers = input _
          .Split($"Environment.NewLine ,)(".ToCharArray(), StringSplitOptions.RemoveEmptyEntries) _
          .Select(Function(n) Integer.Parse(n)) _
          .ToArray()

          Dim sprockets = Enumerable _
          .Range(0, (numbers.Length 3)) _
          .Select(Function(i) New Sprocket With

          .X = numbers(((i * 3) + 0)),
          .Y = numbers(((i * 3) + 1)),
          .R = numbers(((i * 3) + 2))
          ) _
          .ToArray()

          Application.EnableVisualStyles()
          Application.SetCompatibleTextRenderingDefault(False)
          Application.Run(New Window(sprockets))

          End Sub

          End Module


          Window.vb



          Public Class Window
          Inherits Form

          Private ReadOnly sprockets As Sprocket()

          Public Sub New(sprockets As Sprocket())

          If (sprockets Is Nothing) Then
          Throw New ArgumentNullException(NameOf(sprockets))
          End If

          Me.sprockets = sprockets

          Me.SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.UserPaint Or ControlStyles.OptimizedDoubleBuffer, True)

          Me.Text = "Sprockets"
          Me.AutoScaleMode = AutoScaleMode.Font
          Me.ClientSize = New Size(800, 450)

          End Sub

          Protected Overrides Sub OnPaint(e As PaintEventArgs)

          e.Graphics.Clear(Me.BackColor)
          e.Graphics.SmoothingMode = Drawing2D.SmoothingMode.HighQuality

          For Each sprocket In Me.sprockets

          Dim diameter = (sprocket.R * 2)
          Dim rect = New Rectangle(sprocket.X, sprocket.Y, diameter, diameter)

          e.Graphics.FillEllipse(Brushes.Black, rect)

          Next

          End Sub

          End Class





          share|improve this answer























          • Thanks. Haven't had a chance to read this, but I didn't want you to think I wasn't interested!
            – Raystafarian
            Mar 28 at 21:26






          • 1




            @Raystafarian No problem. As a side note: Your entry point (sub Main) looks a bit weird. No reference to Application.Run (the start of the message pump). Visual Studio auto-generate the entry point for VB.NET applications. But to manually wire up the start (as I did in the Program module) you do as follows: Double click "My project" in the solution pane. Click "Application" tab and uncheck "Enable application framework". Then choose "Sub Main" from the "Startup object" dropdown.
            – Bjørn-Roger Kringsjå
            Mar 29 at 9:32










          • Great, that's something I had no idea about - thanks
            – Raystafarian
            Mar 30 at 8:47










          • With naming, the guide is basically saying everything should be PascalCase except parameters in functions, I'm reading that correctly?
            – Raystafarian
            Mar 30 at 23:04










          • Yup. And even though the guide do not specify a convention for variables, the consensus is to use camelCase.
            – Bjørn-Roger Kringsjå
            Mar 31 at 7:01












          up vote
          3
          down vote



          accepted







          up vote
          3
          down vote



          accepted






          The overall structure of your code looks good, but the readability is a tad poor. You should always strive to follow the Framework Design Guidelines. Use proper naming and add a few linebreaks.



          Rather than using arrays, create a dedicated "Sprocket" class to hold the parsed input data.



          Public Class Sprocket
          Public Property X As Integer
          Public Property Y As Integer
          Public Property R As Integer
          End Class


          Now, if you add the rest of the non-numeric characters to the separator list you could actually read and parse the file in two lines. (Though you ougth to use the line-continuation character for readability as seen at the bottom)



          Dim numbers = File.ReadAllText("C:Tempgearinput.txt").Split($"Environment.NewLine ,)(".ToCharArray(), StringSplitOptions.RemoveEmptyEntries).Select(Function(n) Integer.Parse(n)).ToArray()
          Dim sprockets = Enumerable.Range(0, (numbers.Length 3)).Select(Function(i) New Sprocket With .X = numbers(((i * 3) + 0)), .Y = numbers(((i * 3) + 1)), .R = numbers(((i * 3) + 2))).ToArray()



          Window



          Sprocket.vb



          Public Class Sprocket

          Public Property X As Integer
          Public Property Y As Integer
          Public Property R As Integer

          Public Overrides Function ToString() As String
          Return $" X=Me.X, Y=Me.Y, R=Me.R "
          End Function

          End Class


          Program.vb



          Public Module Program

          <STAThread>
          Public Sub Main()

          'TODO: Read file
          Dim input = "(0, 0, 16), (100, 0, 16), (100, 100, 12), (50, 50, 24), (0, 100, 12)"

          Dim numbers = input _
          .Split($"Environment.NewLine ,)(".ToCharArray(), StringSplitOptions.RemoveEmptyEntries) _
          .Select(Function(n) Integer.Parse(n)) _
          .ToArray()

          Dim sprockets = Enumerable _
          .Range(0, (numbers.Length 3)) _
          .Select(Function(i) New Sprocket With

          .X = numbers(((i * 3) + 0)),
          .Y = numbers(((i * 3) + 1)),
          .R = numbers(((i * 3) + 2))
          ) _
          .ToArray()

          Application.EnableVisualStyles()
          Application.SetCompatibleTextRenderingDefault(False)
          Application.Run(New Window(sprockets))

          End Sub

          End Module


          Window.vb



          Public Class Window
          Inherits Form

          Private ReadOnly sprockets As Sprocket()

          Public Sub New(sprockets As Sprocket())

          If (sprockets Is Nothing) Then
          Throw New ArgumentNullException(NameOf(sprockets))
          End If

          Me.sprockets = sprockets

          Me.SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.UserPaint Or ControlStyles.OptimizedDoubleBuffer, True)

          Me.Text = "Sprockets"
          Me.AutoScaleMode = AutoScaleMode.Font
          Me.ClientSize = New Size(800, 450)

          End Sub

          Protected Overrides Sub OnPaint(e As PaintEventArgs)

          e.Graphics.Clear(Me.BackColor)
          e.Graphics.SmoothingMode = Drawing2D.SmoothingMode.HighQuality

          For Each sprocket In Me.sprockets

          Dim diameter = (sprocket.R * 2)
          Dim rect = New Rectangle(sprocket.X, sprocket.Y, diameter, diameter)

          e.Graphics.FillEllipse(Brushes.Black, rect)

          Next

          End Sub

          End Class





          share|improve this answer















          The overall structure of your code looks good, but the readability is a tad poor. You should always strive to follow the Framework Design Guidelines. Use proper naming and add a few linebreaks.



          Rather than using arrays, create a dedicated "Sprocket" class to hold the parsed input data.



          Public Class Sprocket
          Public Property X As Integer
          Public Property Y As Integer
          Public Property R As Integer
          End Class


          Now, if you add the rest of the non-numeric characters to the separator list you could actually read and parse the file in two lines. (Though you ougth to use the line-continuation character for readability as seen at the bottom)



          Dim numbers = File.ReadAllText("C:Tempgearinput.txt").Split($"Environment.NewLine ,)(".ToCharArray(), StringSplitOptions.RemoveEmptyEntries).Select(Function(n) Integer.Parse(n)).ToArray()
          Dim sprockets = Enumerable.Range(0, (numbers.Length 3)).Select(Function(i) New Sprocket With .X = numbers(((i * 3) + 0)), .Y = numbers(((i * 3) + 1)), .R = numbers(((i * 3) + 2))).ToArray()



          Window



          Sprocket.vb



          Public Class Sprocket

          Public Property X As Integer
          Public Property Y As Integer
          Public Property R As Integer

          Public Overrides Function ToString() As String
          Return $" X=Me.X, Y=Me.Y, R=Me.R "
          End Function

          End Class


          Program.vb



          Public Module Program

          <STAThread>
          Public Sub Main()

          'TODO: Read file
          Dim input = "(0, 0, 16), (100, 0, 16), (100, 100, 12), (50, 50, 24), (0, 100, 12)"

          Dim numbers = input _
          .Split($"Environment.NewLine ,)(".ToCharArray(), StringSplitOptions.RemoveEmptyEntries) _
          .Select(Function(n) Integer.Parse(n)) _
          .ToArray()

          Dim sprockets = Enumerable _
          .Range(0, (numbers.Length 3)) _
          .Select(Function(i) New Sprocket With

          .X = numbers(((i * 3) + 0)),
          .Y = numbers(((i * 3) + 1)),
          .R = numbers(((i * 3) + 2))
          ) _
          .ToArray()

          Application.EnableVisualStyles()
          Application.SetCompatibleTextRenderingDefault(False)
          Application.Run(New Window(sprockets))

          End Sub

          End Module


          Window.vb



          Public Class Window
          Inherits Form

          Private ReadOnly sprockets As Sprocket()

          Public Sub New(sprockets As Sprocket())

          If (sprockets Is Nothing) Then
          Throw New ArgumentNullException(NameOf(sprockets))
          End If

          Me.sprockets = sprockets

          Me.SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.UserPaint Or ControlStyles.OptimizedDoubleBuffer, True)

          Me.Text = "Sprockets"
          Me.AutoScaleMode = AutoScaleMode.Font
          Me.ClientSize = New Size(800, 450)

          End Sub

          Protected Overrides Sub OnPaint(e As PaintEventArgs)

          e.Graphics.Clear(Me.BackColor)
          e.Graphics.SmoothingMode = Drawing2D.SmoothingMode.HighQuality

          For Each sprocket In Me.sprockets

          Dim diameter = (sprocket.R * 2)
          Dim rect = New Rectangle(sprocket.X, sprocket.Y, diameter, diameter)

          e.Graphics.FillEllipse(Brushes.Black, rect)

          Next

          End Sub

          End Class






          share|improve this answer















          share|improve this answer



          share|improve this answer








          edited Mar 29 at 9:42


























          answered Mar 27 at 16:19









          Bjørn-Roger Kringsjå

          1,2251915




          1,2251915











          • Thanks. Haven't had a chance to read this, but I didn't want you to think I wasn't interested!
            – Raystafarian
            Mar 28 at 21:26






          • 1




            @Raystafarian No problem. As a side note: Your entry point (sub Main) looks a bit weird. No reference to Application.Run (the start of the message pump). Visual Studio auto-generate the entry point for VB.NET applications. But to manually wire up the start (as I did in the Program module) you do as follows: Double click "My project" in the solution pane. Click "Application" tab and uncheck "Enable application framework". Then choose "Sub Main" from the "Startup object" dropdown.
            – Bjørn-Roger Kringsjå
            Mar 29 at 9:32










          • Great, that's something I had no idea about - thanks
            – Raystafarian
            Mar 30 at 8:47










          • With naming, the guide is basically saying everything should be PascalCase except parameters in functions, I'm reading that correctly?
            – Raystafarian
            Mar 30 at 23:04










          • Yup. And even though the guide do not specify a convention for variables, the consensus is to use camelCase.
            – Bjørn-Roger Kringsjå
            Mar 31 at 7:01
















          • Thanks. Haven't had a chance to read this, but I didn't want you to think I wasn't interested!
            – Raystafarian
            Mar 28 at 21:26






          • 1




            @Raystafarian No problem. As a side note: Your entry point (sub Main) looks a bit weird. No reference to Application.Run (the start of the message pump). Visual Studio auto-generate the entry point for VB.NET applications. But to manually wire up the start (as I did in the Program module) you do as follows: Double click "My project" in the solution pane. Click "Application" tab and uncheck "Enable application framework". Then choose "Sub Main" from the "Startup object" dropdown.
            – Bjørn-Roger Kringsjå
            Mar 29 at 9:32










          • Great, that's something I had no idea about - thanks
            – Raystafarian
            Mar 30 at 8:47










          • With naming, the guide is basically saying everything should be PascalCase except parameters in functions, I'm reading that correctly?
            – Raystafarian
            Mar 30 at 23:04










          • Yup. And even though the guide do not specify a convention for variables, the consensus is to use camelCase.
            – Bjørn-Roger Kringsjå
            Mar 31 at 7:01















          Thanks. Haven't had a chance to read this, but I didn't want you to think I wasn't interested!
          – Raystafarian
          Mar 28 at 21:26




          Thanks. Haven't had a chance to read this, but I didn't want you to think I wasn't interested!
          – Raystafarian
          Mar 28 at 21:26




          1




          1




          @Raystafarian No problem. As a side note: Your entry point (sub Main) looks a bit weird. No reference to Application.Run (the start of the message pump). Visual Studio auto-generate the entry point for VB.NET applications. But to manually wire up the start (as I did in the Program module) you do as follows: Double click "My project" in the solution pane. Click "Application" tab and uncheck "Enable application framework". Then choose "Sub Main" from the "Startup object" dropdown.
          – Bjørn-Roger Kringsjå
          Mar 29 at 9:32




          @Raystafarian No problem. As a side note: Your entry point (sub Main) looks a bit weird. No reference to Application.Run (the start of the message pump). Visual Studio auto-generate the entry point for VB.NET applications. But to manually wire up the start (as I did in the Program module) you do as follows: Double click "My project" in the solution pane. Click "Application" tab and uncheck "Enable application framework". Then choose "Sub Main" from the "Startup object" dropdown.
          – Bjørn-Roger Kringsjå
          Mar 29 at 9:32












          Great, that's something I had no idea about - thanks
          – Raystafarian
          Mar 30 at 8:47




          Great, that's something I had no idea about - thanks
          – Raystafarian
          Mar 30 at 8:47












          With naming, the guide is basically saying everything should be PascalCase except parameters in functions, I'm reading that correctly?
          – Raystafarian
          Mar 30 at 23:04




          With naming, the guide is basically saying everything should be PascalCase except parameters in functions, I'm reading that correctly?
          – Raystafarian
          Mar 30 at 23:04












          Yup. And even though the guide do not specify a convention for variables, the consensus is to use camelCase.
          – Bjørn-Roger Kringsjå
          Mar 31 at 7:01




          Yup. And even though the guide do not specify a convention for variables, the consensus is to use camelCase.
          – Bjørn-Roger Kringsjå
          Mar 31 at 7:01












           

          draft saved


          draft discarded


























           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f190344%2fdrawing-circles-from-array-to-a-form%23new-answer', 'question_page');

          );

          Post as a guest













































































          Popular posts from this blog

          Greedy Best First Search implementation in Rust

          Function to Return a JSON Like Objects Using VBA Collections and Arrays

          C++11 CLH Lock Implementation