1 Replies - 6594 Views - Last Post: 29 January 2011 - 07:26 PM Rate Topic: -----

#1 kblaw88  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 29-January 11

Put multiple text box values into array

Posted 29 January 2011 - 07:12 PM

I'd like to create an array of one column from the text box entries (as shown in the picture) when i click the button.
Example: when i enter "1" in the first textbox and "2" in the second textbox and click the button, the
array should have values:
1
2
and when i enter "3" and "4" the array values should be
1
2
3
4

in my code i used three buttons making some invisible until i click the one overlapping on it. but i want to use only one button to do everything if that is possible. i want to use three subsequent clicks to enter numbers into the array (that is after i have entered numbers into the text boxes) and then the third or fourth button click to draw the lines.
i thought about looping button clicks but have no idea how to do that.

the gist is that:
1- enter numbers to textbox1 and textbox2
2- click button and numbers are read to array
3- first line is drawn on form
4- enter numbers again to textbox1 and textbox2
5- click button and numbers are appended to array
6- enter final numbers to textbox1 and textbox2
7- second line is drawn on form
8- click button and numbers are appended to array and
9- last line is drawn
10- the array should read as:
1
2
3
4
5
6

Attached Image

my problem is that i want to do all these with only one button not with the three i have used.

this is the code

 Imports System.IO
Imports System.Drawing
Imports System.Drawing.Drawing2D


Public Class Drawing
    Dim Array(0 To 5) As Integer

    Private Sub xTextBox_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles xTextBox.KeyUp

    End Sub

    Private Sub xTextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles xTextBox.TextChanged

    End Sub

    Private Sub yTextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles yTextBox.TextChanged

    End Sub

    Private Sub firstPointButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles firstPointButton.Click

        Dim i As Integer
        For i = 1 To 3
            Array(i) = CInt(xTextBox.Text)
        Next

        If xTextBox.Text <> "" Then
            If yTextBox.Text <> "" Then
                'MessageBox.Show("All Data OK, proceed", "Valid Data", MessageBoxButtons.OK, MessageBoxIcon.Information)
            Else
                MessageBox.Show("Y coordinate Value Required", "Missing Data", MessageBoxButtons.OK, MessageBoxIcon.Information)
            End If
        Else
            MessageBox.Show("X coordinate Value Required", "Missing Data", MessageBoxButtons.OK, MessageBoxIcon.Information)
        End If

        Array(0) = CInt(xTextBox.Text)
        Array(1) = CInt(yTextBox.Text)

        xTextBox.Text = ""
        yTextBox.Text = ""

        firstPointButton.Visible = False
        secondPointButton.Visible = True

    End Sub

    Private Sub secondPointButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles secondPointButton.Click


        If xTextBox.Text <> "" Then
            If yTextBox.Text <> "" Then
                'MessageBox.Show("All Data OK, proceed", "Valid Data", MessageBoxButtons.OK, MessageBoxIcon.Information)
            Else
                MessageBox.Show("Y coordinate Value Required", "Missing Data", MessageBoxButtons.OK, MessageBoxIcon.Information)
            End If
        Else
            MessageBox.Show("X coordinate Value Required", "Missing Data", MessageBoxButtons.OK, MessageBoxIcon.Information)
        End If

        Array(2) = CInt(xTextBox.Text)
        Array(3) = CInt(yTextBox.Text)

        xTextBox.Text = ""
        yTextBox.Text = ""

        firstPointButton.Visible = False
        secondPointButton.Visible = False
        drawButton.Visible = True

    End Sub

    Private Sub drawButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles drawButton.Click

        If xTextBox.Text <> "" Then
            If yTextBox.Text <> "" Then
                'MessageBox.Show("All Data OK, proceed", "Valid Data", MessageBoxButtons.OK, MessageBoxIcon.Information)
            Else
                MessageBox.Show("Y coordinate Value Required", "Missing Data", MessageBoxButtons.OK, MessageBoxIcon.Information)
            End If
        Else
            MessageBox.Show("X coordinate Value Required", "Missing Data", MessageBoxButtons.OK, MessageBoxIcon.Information)
        End If

        Array(4) = CInt(xTextBox.Text)
        Array(5) = CInt(yTextBox.Text)

        xTextBox.Text = ""
        yTextBox.Text = ""

        
    End Sub

    Private Sub Drawing_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
        Dim Drawing As Graphics
        Drawing = Me.CreateGraphics
        Dim redPen As Pen = New Pen(Color.Red, 2)


        Dim point1 As Point = New Point(Array(0), Array(1))
        Dim point2 As Point = New Point(Array(2), Array(3))
        Dim point3 As Point = New Point(Array(4), Array(5))

        Drawing.DrawLine(redPen, point1, point2)
        Drawing.DrawLine(redPen, point2, point3)
        Drawing.DrawLine(redPen, point3, point1)

        firstPointButton.Visible = True
        secondPointButton.Visible = False
        drawButton.Visible = False
    End Sub
End Class 


Is This A Good Question/Topic? 0
  • +

Replies To: Put multiple text box values into array

#2 Jack Eagles1  Icon User is offline

  • Pugnacious Penguin (inspired by no2pencil)
  • member icon

Reputation: 183
  • View blog
  • Posts: 1,152
  • Joined: 10-December 08

Re: Put multiple text box values into array

Posted 29 January 2011 - 07:26 PM

You could just use a System.Collections.Specialized.StringCollection... Then all you'd need to do is add the value of each textbox to the array.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1