4 Replies - 3569 Views - Last Post: 17 February 2011 - 11:02 AM Rate Topic: -----

#1 ryomadarktezuka  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 55
  • Joined: 02-August 09

put the values of textbox into an array

Posted 17 February 2011 - 10:33 AM

need help guys, I'm working on my code about cpu scheduling and I encountered a problem in putting the values inputted of the user from the textbox to an array, when I try to retrieve the value from the array I always get '0' and I don't know where did I get that 0. here's my code hope you could help me >___<




Public Class Form3
    'Public txtIN As TextBox
    Dim lbl As Label
    Dim arrival As TextBox()
    Dim inp As Integer
    Dim y As Integer
    Dim x As Integer
    Dim a, b As Integer
    Public arrival_time(9) As Integer
    Public burst_time(9) As Integer
    Public AT() As Integer
  


    Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        inp = Val(Form1.txtINPUT.Text)


        b = 50


        For ctr As Integer = 0 To inp - 1
            Dim lbl As New Label
            lbl.SetBounds(30, b, 30, 25)
            lbl.Text = "P" + Str(ctr + 1)
            Me.Controls.Add(lbl)

            Dim arrival(inp) As TextBox
            arrival(ctr) = New TextBox
            arrival(ctr).SetBounds(109, b, 50, 25)
            arrival_time(ctr) = Val(arrival(ctr).Text)
            Controls.Add(arrival(ctr))


            Dim burst As TextBox
            burst = New TextBox
            burst.SetBounds(217, b, 50, 25)
            Controls.Add(burst)
            burst_time(ctr) = Val(burst.Text)


            Dim c As New Label
            c.SetBounds(30, b, 30, 25)
            c.Text = "time: " + Str(arrival_time(ctr))
            Me.Controls.Add(c)


            b = b + 30


        Next ctr



 

    End Sub

    Private Sub btnGET_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGET.Click

   
        Label4.Text = Str(arrival_time(0))
        Label5.Text = Str(arrival_time(1))
        Label6.Text = Str(arrival_time(2))

    End Sub

End Class



Is This A Good Question/Topic? 0
  • +

Replies To: put the values of textbox into an array

#2 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9096
  • View blog
  • Posts: 34,161
  • Joined: 12-June 08

Re: put the values of textbox into an array

Posted 17 February 2011 - 10:37 AM

Is there a reason why you are doing line 29?

Dim arrival(inp) As TextBox

Was This Post Helpful? 0
  • +
  • -

#3 ryomadarktezuka  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 55
  • Joined: 02-August 09

Re: put the values of textbox into an array

Posted 17 February 2011 - 10:41 AM

View Postmodi123_1, on 17 February 2011 - 10:37 AM, said:

Is there a reason why you are doing line 29?

Dim arrival(inp) As TextBox


I'm trying to create an array of textboxes sir but I'm not sure about it's syntax cause I just rely on the codes I've seen over the net.
Was This Post Helpful? 0
  • +
  • -

#4 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9096
  • View blog
  • Posts: 34,161
  • Joined: 12-June 08

Re: put the values of textbox into an array

Posted 17 February 2011 - 10:50 AM

That's what I figured.

Okay, for loops... they loop, right? Repeat instructions. If you declare an object inside of a for loop each time that loop comes back around again that object is re-declared.

In this case you are perpetually declaring an array of size "inp", and then going to a specific element (of this empty array) to add something create a new textbox.

That doesn't make much sense, right?
Was This Post Helpful? 0
  • +
  • -

#5 ryomadarktezuka  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 55
  • Joined: 02-August 09

Re: put the values of textbox into an array

Posted 17 February 2011 - 11:02 AM

OHHHHH!! I see sir!! thanks for pointing that matter! I'll work on my code again xD thanks Sir!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1