ArrayList Function In Business Tier?

Discussion in 'ASP .Net' started by Leon, Nov 25, 2004.

  1. Leon

    Leon Guest

    I have a webform in which when the user press generate button the form
    generate six unique ramdon numbers, the user can also type these six numbers
    in manually in any order. however, the user can also press a post button
    that post these six numbers into the database. My problem is that these six
    numbers need to be posted to the database from less to greatest, and all of
    my code is within the business tier class not the code behind class.

    After looking at my code below...
    How do I create an ArrayList that can get the values from the Generate
    function ("which include a stack") and pass to the form, and get the values
    from the form and pass them to the database? **Please note where you see is
    my problem. Thanks


    Private Function Generate(ByVal Value As Integer) As Integer

    Dim arrl(Value) As Integer

    Dim x As Integer

    Dim j As Integer

    Dim s As Stack = New Stack

    Dim blnexists As Boolean = True

    For j = 0 To Value

    arr1(j) = GetRandomNumber()

    blnexists = s.Contains(arr1(j))

    While blnexists = True

    arr1(j) = GetRandomNumber()

    blnexists = s.Contains(arr1(j))

    End While

    s.Push(arr1(j))

    Next



    For x = 0 To Value

    arr1(x) = s.Pop()

    Next


    'Just Tried something did not work

    'Dim I As Integer

    'Dim pickNums As ArrayList = New ArrayList



    'For I = 0 To PickCount

    'pickNums.Add(arrl(I))

    'Next

    'GeneratePick = SortPick(pickNums)


    End Function



    'Just Tried something did not work

    'Public Function SortPick(ByVal UserPick As ArrayList)

    'UserPick.Sort()

    'End Function
     
    Leon, Nov 25, 2004
    #1
    1. Advertising

  2. Leon

    mortb Guest

    Not sure what you want to do but here is a function that returns a sorted
    stack of numberOfNumbers random numbers
    cheers,
    mortb

    Private Function Generate(ByVal numberOfNumbers As Integer) As Stack
    Dim al as ArrayList = new ArrayList(numberOfNumbers)
    Dim rand as random = new Random()
    for i as integer = 0 to numberOfNumbers
    Dim rnd as integer = rand.Next()
    while(al.Contains(rnd))
    rnd = rand.Next()
    end while
    al.Add(rnd)
    next
    al.Sort()
    Generate = new Stack(al)
    End Function

    pseudo code:
    page_onload

    stack = generate
    textbox1 = (stack.pop)ToString()
    textbox2 = (stack.pop)ToString()
    ..

    end function



    "Leon" <> wrote in message
    news:...
    >I have a webform in which when the user press generate button the form
    >generate six unique ramdon numbers, the user can also type these six
    >numbers in manually in any order. however, the user can also press a post
    >button that post these six numbers into the database. My problem is that
    >these six numbers need to be posted to the database from less to greatest,
    >and all of my code is within the business tier class not the code behind
    >class.
    >
    > After looking at my code below...
    > How do I create an ArrayList that can get the values from the Generate
    > function ("which include a stack") and pass to the form, and get the
    > values from the form and pass them to the database? **Please note where
    > you see is my problem. Thanks
    >
    >
    > Private Function Generate(ByVal Value As Integer) As Integer
    >
    > Dim arrl(Value) As Integer
    >
    > Dim x As Integer
    >
    > Dim j As Integer
    >
    > Dim s As Stack = New Stack
    >
    > Dim blnexists As Boolean = True
    >
    > For j = 0 To Value
    >
    > arr1(j) = GetRandomNumber()
    >
    > blnexists = s.Contains(arr1(j))
    >
    > While blnexists = True
    >
    > arr1(j) = GetRandomNumber()
    >
    > blnexists = s.Contains(arr1(j))
    >
    > End While
    >
    > s.Push(arr1(j))
    >
    > Next
    >
    >
    >
    > For x = 0 To Value
    >
    > arr1(x) = s.Pop()
    >
    > Next
    >
    >
    > 'Just Tried something did not work
    >
    > 'Dim I As Integer
    >
    > 'Dim pickNums As ArrayList = New ArrayList
    >
    >
    >
    > 'For I = 0 To PickCount
    >
    > 'pickNums.Add(arrl(I))
    >
    > 'Next
    >
    > 'GeneratePick = SortPick(pickNums)
    >
    >
    > End Function
    >
    >
    >
    > 'Just Tried something did not work
    >
    > 'Public Function SortPick(ByVal UserPick As ArrayList)
    >
    > 'UserPick.Sort()
    >
    > 'End Function
    >
    >
    >
     
    mortb, Nov 26, 2004
    #2
    1. Advertising

  3. Leon

    mortb Guest

    oops,
    when the elements are added to the stack they are reversed to avoid this
    insert
    al.Reverse()
    before
    Generate = new Stack(al)

    cheers,
    mortb

    "mortb" <mortb1<noospam<@hotmail.com> wrote in message
    news:...
    > Not sure what you want to do but here is a function that returns a sorted
    > stack of numberOfNumbers random numbers
    > cheers,
    > mortb
    >
    > Private Function Generate(ByVal numberOfNumbers As Integer) As Stack
    > Dim al as ArrayList = new ArrayList(numberOfNumbers)
    > Dim rand as random = new Random()
    > for i as integer = 0 to numberOfNumbers
    > Dim rnd as integer = rand.Next()
    > while(al.Contains(rnd))
    > rnd = rand.Next()
    > end while
    > al.Add(rnd)
    > next
    > al.Sort()
    > Generate = new Stack(al)
    > End Function
    >
    > pseudo code:
    > page_onload
    >
    > stack = generate
    > textbox1 = (stack.pop)ToString()
    > textbox2 = (stack.pop)ToString()
    > ..
    >
    > end function
    >
    >
    >
    > "Leon" <> wrote in message
    > news:...
    >>I have a webform in which when the user press generate button the form
    >>generate six unique ramdon numbers, the user can also type these six
    >>numbers in manually in any order. however, the user can also press a post
    >>button that post these six numbers into the database. My problem is that
    >>these six numbers need to be posted to the database from less to greatest,
    >>and all of my code is within the business tier class not the code behind
    >>class.
    >>
    >> After looking at my code below...
    >> How do I create an ArrayList that can get the values from the Generate
    >> function ("which include a stack") and pass to the form, and get the
    >> values from the form and pass them to the database? **Please note where
    >> you see is my problem. Thanks
    >>
    >>
    >> Private Function Generate(ByVal Value As Integer) As Integer
    >>
    >> Dim arrl(Value) As Integer
    >>
    >> Dim x As Integer
    >>
    >> Dim j As Integer
    >>
    >> Dim s As Stack = New Stack
    >>
    >> Dim blnexists As Boolean = True
    >>
    >> For j = 0 To Value
    >>
    >> arr1(j) = GetRandomNumber()
    >>
    >> blnexists = s.Contains(arr1(j))
    >>
    >> While blnexists = True
    >>
    >> arr1(j) = GetRandomNumber()
    >>
    >> blnexists = s.Contains(arr1(j))
    >>
    >> End While
    >>
    >> s.Push(arr1(j))
    >>
    >> Next
    >>
    >>
    >>
    >> For x = 0 To Value
    >>
    >> arr1(x) = s.Pop()
    >>
    >> Next
    >>
    >>
    >> 'Just Tried something did not work
    >>
    >> 'Dim I As Integer
    >>
    >> 'Dim pickNums As ArrayList = New ArrayList
    >>
    >>
    >>
    >> 'For I = 0 To PickCount
    >>
    >> 'pickNums.Add(arrl(I))
    >>
    >> 'Next
    >>
    >> 'GeneratePick = SortPick(pickNums)
    >>
    >>
    >> End Function
    >>
    >>
    >>
    >> 'Just Tried something did not work
    >>
    >> 'Public Function SortPick(ByVal UserPick As ArrayList)
    >>
    >> 'UserPick.Sort()
    >>
    >> 'End Function
    >>
    >>
    >>

    >
    >
     
    mortb, Nov 26, 2004
    #3
  4. Leon

    Leon Guest

    Thanks for your reply, but what I want to do is pass the randomly generated
    numbers from the Generate function which is in the business tier to my
    webform.
    Do I need to declare the Generate function as a ArrayList or build a
    separate ArrayList function or sub and pass the values from there to my
    page?
    OR....
    How do I get the five generated number from this class which is in the
    business tier to my webform?
    See Code...
    Private Function Generate(ByVal Value As Integer) As Integer
    Dim arrl(Value) As Integer
    Dim x As Integer
    Dim j As Integer
    Dim s As Stack = New Stack
    Dim blnexists As Boolean = True
    For j = 0 To Value
    arr1(j) = GetRandomNumber()
    blnexists = s.Contains(arr1(j))
    While blnexists = True
    arr1(j) = GetRandomNumber()
    blnexists = s.Contains(arr1(j))
    End While
    s.Push(arr1(j))
    Next
    For x = 0 To Value
    arr1(x) = s.Pop()
    Next
    End Function


    "mortb" <mortb1<noospam<@hotmail.com> wrote in message
    news:...
    > oops,
    > when the elements are added to the stack they are reversed to avoid this
    > insert
    > al.Reverse()
    > before
    > Generate = new Stack(al)
    >
    > cheers,
    > mortb
    >
    > "mortb" <mortb1<noospam<@hotmail.com> wrote in message
    > news:...
    >> Not sure what you want to do but here is a function that returns a sorted
    >> stack of numberOfNumbers random numbers
    >> cheers,
    >> mortb
    >>
    >> Private Function Generate(ByVal numberOfNumbers As Integer) As Stack
    >> Dim al as ArrayList = new ArrayList(numberOfNumbers)
    >> Dim rand as random = new Random()
    >> for i as integer = 0 to numberOfNumbers
    >> Dim rnd as integer = rand.Next()
    >> while(al.Contains(rnd))
    >> rnd = rand.Next()
    >> end while
    >> al.Add(rnd)
    >> next
    >> al.Sort()
    >> Generate = new Stack(al)
    >> End Function
    >>
    >> pseudo code:
    >> page_onload
    >>
    >> stack = generate
    >> textbox1 = (stack.pop)ToString()
    >> textbox2 = (stack.pop)ToString()
    >> ..
    >>
    >> end function
    >>
    >>
    >>
    >> "Leon" <> wrote in message
    >> news:...
    >>>I have a webform in which when the user press generate button the form
    >>>generate six unique ramdon numbers, the user can also type these six
    >>>numbers in manually in any order. however, the user can also press a post
    >>>button that post these six numbers into the database. My problem is that
    >>>these six numbers need to be posted to the database from less to
    >>>greatest, and all of my code is within the business tier class not the
    >>>code behind class.
    >>>
    >>> After looking at my code below...
    >>> How do I create an ArrayList that can get the values from the Generate
    >>> function ("which include a stack") and pass to the form, and get the
    >>> values from the form and pass them to the database? **Please note where
    >>> you see is my problem. Thanks
    >>>
    >>>
    >>> Private Function Generate(ByVal Value As Integer) As Integer
    >>>
    >>> Dim arrl(Value) As Integer
    >>>
    >>> Dim x As Integer
    >>>
    >>> Dim j As Integer
    >>>
    >>> Dim s As Stack = New Stack
    >>>
    >>> Dim blnexists As Boolean = True
    >>>
    >>> For j = 0 To Value
    >>>
    >>> arr1(j) = GetRandomNumber()
    >>>
    >>> blnexists = s.Contains(arr1(j))
    >>>
    >>> While blnexists = True
    >>>
    >>> arr1(j) = GetRandomNumber()
    >>>
    >>> blnexists = s.Contains(arr1(j))
    >>>
    >>> End While
    >>>
    >>> s.Push(arr1(j))
    >>>
    >>> Next
    >>>
    >>>
    >>>
    >>> For x = 0 To Value
    >>>
    >>> arr1(x) = s.Pop()
    >>>
    >>> Next
    >>>
    >>>
    >>> 'Just Tried something did not work
    >>>
    >>> 'Dim I As Integer
    >>>
    >>> 'Dim pickNums As ArrayList = New ArrayList
    >>>
    >>>
    >>>
    >>> 'For I = 0 To PickCount
    >>>
    >>> 'pickNums.Add(arrl(I))
    >>>
    >>> 'Next
    >>>
    >>> 'GeneratePick = SortPick(pickNums)
    >>>
    >>>
    >>> End Function
    >>>
    >>>
    >>>
    >>> 'Just Tried something did not work
    >>>
    >>> 'Public Function SortPick(ByVal UserPick As ArrayList)
    >>>
    >>> 'UserPick.Sort()
    >>>
    >>> 'End Function
    >>>
    >>>
    >>>

    >>
    >>

    >
    >
     
    Leon, Nov 26, 2004
    #4
  5. Leon

    mortb Guest

    Like this (pseudo code not compiled)?
    Page code behind:

    submit onclick:

    Dim userRandomNumbers as ArrayList = new ArrayList()
    if userRnd1.Text.Trim() != ""
    userRandomNumbers.Add(int.Parse(userRnd1.Text.Trim())) ' Assuming there
    are text fields for the random numbers
    end if
    if userRnd2.Text.Trim() != ""
    userRandomNumbers.Add(int.Parse(userRnd2.Text.Trim()))
    end if
    ....

    ' if the generate would return an arraylist of x random numbers:
    int x = 6 - userRandomNumbers.Count
    userRandomNumbers.AddRange(BusinessObject.Generate(x))
    userRandomNumbers.Sort()

    'if you want to display the resulting numbers on your webform:
    userRnd1.Text.= userRandomNumbers[0]
    userRnd2.Text.= userRandomNumbers[1]
    ....

    ' code that post data to database goes here...

    "Leon" <> wrote in message
    news:O%...
    > Thanks for your reply, but what I want to do is pass the randomly
    > generated numbers from the Generate function which is in the business tier
    > to my webform.
    > Do I need to declare the Generate function as a ArrayList or build a
    > separate ArrayList function or sub and pass the values from there to my
    > page?
    > OR....
    > How do I get the five generated number from this class which is in the
    > business tier to my webform?
     
    mortb, Nov 26, 2004
    #5
  6. Leon

    Leon Guest

    Thanks For all the help, but this is my code and it runs but it only return
    one value to the textbox and I know the other values exist because I step
    inside of my code. what do you see that I'm doing wrong. thanks again!!!

    Private Function Generate(ByVal Value As Integer) As ArrayList
    Dim arrl(Value) As Integer
    Dim x As Integer
    Dim j As Integer
    Dim s As Stack = New Stack
    Dim blnexists As Boolean = True
    For j = 0 To Value
    arr1(j) = GetRandomNumber()
    blnexists = s.Contains(arr1(j))
    While blnexists = True
    arr1(j) = GetRandomNumber()
    blnexists = s.Contains(arr1(j))
    End While
    s.Push(arr1(j))
    Next
    For x = 0 To Value
    arr1(x) = s.Pop()
    Next
    Dim I As Integer
    Dim UserNum As ArrayList = New ArrayList
    For I = 0 To Value
    UserNum.Add(arr1(I))
    Next
    Generate= New ArrayList(UserNum)
    End Function

    And then this code is in my code behind class...............

    Dim test As ArrayList
    test = newPick.GeneratePick(5)

    Me.TextBox1.Text = test.Item(0)
    Me.TextBox1.Text = test.Item(1)
    Me.TextBox1.Text = test.Item(2)
    Me.TextBox1.Text = test.Item(3)
    Me.TextBox1.Text = test.Item(4)
    Me.TextBox1.Text = test.Item(5)

    "mortb" <mortb1<noospam<@hotmail.com> wrote in message
    news:...
    > Like this (pseudo code not compiled)?
    > Page code behind:
    >
    > submit onclick:
    >
    > Dim userRandomNumbers as ArrayList = new ArrayList()
    > if userRnd1.Text.Trim() != ""
    > userRandomNumbers.Add(int.Parse(userRnd1.Text.Trim())) ' Assuming there
    > are text fields for the random numbers
    > end if
    > if userRnd2.Text.Trim() != ""
    > userRandomNumbers.Add(int.Parse(userRnd2.Text.Trim()))
    > end if
    > ...
    >
    > ' if the generate would return an arraylist of x random numbers:
    > int x = 6 - userRandomNumbers.Count
    > userRandomNumbers.AddRange(BusinessObject.Generate(x))
    > userRandomNumbers.Sort()
    >
    > 'if you want to display the resulting numbers on your webform:
    > userRnd1.Text.= userRandomNumbers[0]
    > userRnd2.Text.= userRandomNumbers[1]
    > ...
    >
    > ' code that post data to database goes here...
    >
    > "Leon" <> wrote in message
    > news:O%...
    >> Thanks for your reply, but what I want to do is pass the randomly
    >> generated numbers from the Generate function which is in the business
    >> tier to my webform.
    >> Do I need to declare the Generate function as a ArrayList or build a
    >> separate ArrayList function or sub and pass the values from there to my
    >> page?
    >> OR....
    >> How do I get the five generated number from this class which is in the
    >> business tier to my webform?

    >
    >
     
    Leon, Nov 26, 2004
    #6
  7. Leon

    mortb Guest

    If the numbers are there when you step into the code then the problem has to
    be somwhere else -- somewhere in the code that you haven't posted.

    By the way, why do you create a stack? and an array? It seems you only need
    the array list which you return...

    cheers,
    mortb

    Private Function Generate(ByVal Value As Integer) As ArrayList
    Dim arrl As ArrayList(Value)
    For j = 0 To Value
    Dim rnd as integer = GetRandomNumber()
    While arrl.Contains(rnd)
    rnd = GetRandomNumber()
    End While
    arrl .Add(rnd)
    Next
    Generate = arrl
    End Function


    "Leon" <> wrote in message
    news:...
    > Thanks For all the help, but this is my code and it runs but it only
    > return one value to the textbox and I know the other values exist because
    > I step inside of my code. what do you see that I'm doing wrong. thanks
    > again!!!
    >
    > Private Function Generate(ByVal Value As Integer) As ArrayList
    > Dim arrl(Value) As Integer
    > Dim x As Integer
    > Dim j As Integer
    > Dim s As Stack = New Stack
    > Dim blnexists As Boolean = True
    > For j = 0 To Value
    > arr1(j) = GetRandomNumber()
    > blnexists = s.Contains(arr1(j))
    > While blnexists = True
    > arr1(j) = GetRandomNumber()
    > blnexists = s.Contains(arr1(j))
    > End While
    > s.Push(arr1(j))
    > Next
    > For x = 0 To Value
    > arr1(x) = s.Pop()
    > Next
    > Dim I As Integer
    > Dim UserNum As ArrayList = New ArrayList
    > For I = 0 To Value
    > UserNum.Add(arr1(I))
    > Next
    > Generate= New ArrayList(UserNum)
    > End Function
    >
    > And then this code is in my code behind class...............
    >
    > Dim test As ArrayList
    > test = newPick.GeneratePick(5)
    >
    > Me.TextBox1.Text = test.Item(0)
    > Me.TextBox1.Text = test.Item(1)
    > Me.TextBox1.Text = test.Item(2)
    > Me.TextBox1.Text = test.Item(3)
    > Me.TextBox1.Text = test.Item(4)
    > Me.TextBox1.Text = test.Item(5)
    >
    > "mortb" <mortb1<noospam<@hotmail.com> wrote in message
    > news:...
    >> Like this (pseudo code not compiled)?
    >> Page code behind:
    >>
    >> submit onclick:
    >>
    >> Dim userRandomNumbers as ArrayList = new ArrayList()
    >> if userRnd1.Text.Trim() != ""
    >> userRandomNumbers.Add(int.Parse(userRnd1.Text.Trim())) ' Assuming
    >> there are text fields for the random numbers
    >> end if
    >> if userRnd2.Text.Trim() != ""
    >> userRandomNumbers.Add(int.Parse(userRnd2.Text.Trim()))
    >> end if
    >> ...
    >>
    >> ' if the generate would return an arraylist of x random numbers:
    >> int x = 6 - userRandomNumbers.Count
    >> userRandomNumbers.AddRange(BusinessObject.Generate(x))
    >> userRandomNumbers.Sort()
    >>
    >> 'if you want to display the resulting numbers on your webform:
    >> userRnd1.Text.= userRandomNumbers[0]
    >> userRnd2.Text.= userRandomNumbers[1]
    >> ...
    >>
    >> ' code that post data to database goes here...
    >>
    >> "Leon" <> wrote in message
    >> news:O%...
    >>> Thanks for your reply, but what I want to do is pass the randomly
    >>> generated numbers from the Generate function which is in the business
    >>> tier to my webform.
    >>> Do I need to declare the Generate function as a ArrayList or build a
    >>> separate ArrayList function or sub and pass the values from there to my
    >>> page?
    >>> OR....
    >>> How do I get the five generated number from this class which is in the
    >>> business tier to my webform?

    >>
    >>

    >
    >
     
    mortb, Nov 26, 2004
    #7
  8. Leon

    Leon Guest

    I use the stack just to make sure I get 5 unique random number back.
    however, what I sent was all the code and what I meant by say "the number
    are there when I step into my project is the numbers are in the stack, but
    it only sends one value back to the calling function ArrayList. maybe I can
    change the stack to ArrayList but my biggest problem is getting from the
    Generate Function ArrayList to my textboxes in my webform on button click.

    "mortb" <mortb1<noospam<@hotmail.com> wrote in message
    news:...
    > If the numbers are there when you step into the code then the problem has
    > to be somwhere else -- somewhere in the code that you haven't posted.
    >
    > By the way, why do you create a stack? and an array? It seems you only
    > need the array list which you return...
    >
    > cheers,
    > mortb
    >
    > Private Function Generate(ByVal Value As Integer) As ArrayList
    > Dim arrl As ArrayList(Value)
    > For j = 0 To Value
    > Dim rnd as integer = GetRandomNumber()
    > While arrl.Contains(rnd)
    > rnd = GetRandomNumber()
    > End While
    > arrl .Add(rnd)
    > Next
    > Generate = arrl
    > End Function
    >
    >
    > "Leon" <> wrote in message
    > news:...
    >> Thanks For all the help, but this is my code and it runs but it only
    >> return one value to the textbox and I know the other values exist because
    >> I step inside of my code. what do you see that I'm doing wrong. thanks
    >> again!!!
    >>
    >> Private Function Generate(ByVal Value As Integer) As ArrayList
    >> Dim arrl(Value) As Integer
    >> Dim x As Integer
    >> Dim j As Integer
    >> Dim s As Stack = New Stack
    >> Dim blnexists As Boolean = True
    >> For j = 0 To Value
    >> arr1(j) = GetRandomNumber()
    >> blnexists = s.Contains(arr1(j))
    >> While blnexists = True
    >> arr1(j) = GetRandomNumber()
    >> blnexists = s.Contains(arr1(j))
    >> End While
    >> s.Push(arr1(j))
    >> Next
    >> For x = 0 To Value
    >> arr1(x) = s.Pop()
    >> Next
    >> Dim I As Integer
    >> Dim UserNum As ArrayList = New ArrayList
    >> For I = 0 To Value
    >> UserNum.Add(arr1(I))
    >> Next
    >> Generate= New ArrayList(UserNum)
    >> End Function
    >>
    >> And then this code is in my code behind class...............
    >>
    >> Dim test As ArrayList
    >> test = newPick.GeneratePick(5)
    >>
    >> Me.TextBox1.Text = test.Item(0)
    >> Me.TextBox1.Text = test.Item(1)
    >> Me.TextBox1.Text = test.Item(2)
    >> Me.TextBox1.Text = test.Item(3)
    >> Me.TextBox1.Text = test.Item(4)
    >> Me.TextBox1.Text = test.Item(5)
    >>
    >> "mortb" <mortb1<noospam<@hotmail.com> wrote in message
    >> news:...
    >>> Like this (pseudo code not compiled)?
    >>> Page code behind:
    >>>
    >>> submit onclick:
    >>>
    >>> Dim userRandomNumbers as ArrayList = new ArrayList()
    >>> if userRnd1.Text.Trim() != ""
    >>> userRandomNumbers.Add(int.Parse(userRnd1.Text.Trim())) ' Assuming
    >>> there are text fields for the random numbers
    >>> end if
    >>> if userRnd2.Text.Trim() != ""
    >>> userRandomNumbers.Add(int.Parse(userRnd2.Text.Trim()))
    >>> end if
    >>> ...
    >>>
    >>> ' if the generate would return an arraylist of x random numbers:
    >>> int x = 6 - userRandomNumbers.Count
    >>> userRandomNumbers.AddRange(BusinessObject.Generate(x))
    >>> userRandomNumbers.Sort()
    >>>
    >>> 'if you want to display the resulting numbers on your webform:
    >>> userRnd1.Text.= userRandomNumbers[0]
    >>> userRnd2.Text.= userRandomNumbers[1]
    >>> ...
    >>>
    >>> ' code that post data to database goes here...
    >>>
    >>> "Leon" <> wrote in message
    >>> news:O%...
    >>>> Thanks for your reply, but what I want to do is pass the randomly
    >>>> generated numbers from the Generate function which is in the business
    >>>> tier to my webform.
    >>>> Do I need to declare the Generate function as a ArrayList or build a
    >>>> separate ArrayList function or sub and pass the values from there to my
    >>>> page?
    >>>> OR....
    >>>> How do I get the five generated number from this class which is in the
    >>>> business tier to my webform?
    >>>
    >>>

    >>
    >>

    >
    >
     
    Leon, Nov 26, 2004
    #8
  9. Leon

    Leon Guest

    Thanks for all the help I got it. LOOK! in the code I posted all the
    textboxes was the same name so all the values went to that textbox.

    Me.TextBox1.Text = test.Item(0)
    Me.TextBox1.Text = test.Item(1)
    Me.TextBox1.Text = test.Item(2)
    Me.TextBox1.Text = test.Item(3)
    Me.TextBox1.Text = test.Item(4)
    Me.TextBox1.Text = test.Item(5)

    "Leon" <> wrote in message
    news:...
    >I use the stack just to make sure I get 5 unique random number back.
    >however, what I sent was all the code and what I meant by say "the number
    >are there when I step into my project is the numbers are in the stack, but
    >it only sends one value back to the calling function ArrayList. maybe I can
    >change the stack to ArrayList but my biggest problem is getting from the
    >Generate Function ArrayList to my textboxes in my webform on button click.
    >
    > "mortb" <mortb1<noospam<@hotmail.com> wrote in message
    > news:...
    >> If the numbers are there when you step into the code then the problem has
    >> to be somwhere else -- somewhere in the code that you haven't posted.
    >>
    >> By the way, why do you create a stack? and an array? It seems you only
    >> need the array list which you return...
    >>
    >> cheers,
    >> mortb
    >>
    >> Private Function Generate(ByVal Value As Integer) As ArrayList
    >> Dim arrl As ArrayList(Value)
    >> For j = 0 To Value
    >> Dim rnd as integer = GetRandomNumber()
    >> While arrl.Contains(rnd)
    >> rnd = GetRandomNumber()
    >> End While
    >> arrl .Add(rnd)
    >> Next
    >> Generate = arrl
    >> End Function
    >>
    >>
    >> "Leon" <> wrote in message
    >> news:...
    >>> Thanks For all the help, but this is my code and it runs but it only
    >>> return one value to the textbox and I know the other values exist
    >>> because I step inside of my code. what do you see that I'm doing wrong.
    >>> thanks again!!!
    >>>
    >>> Private Function Generate(ByVal Value As Integer) As ArrayList
    >>> Dim arrl(Value) As Integer
    >>> Dim x As Integer
    >>> Dim j As Integer
    >>> Dim s As Stack = New Stack
    >>> Dim blnexists As Boolean = True
    >>> For j = 0 To Value
    >>> arr1(j) = GetRandomNumber()
    >>> blnexists = s.Contains(arr1(j))
    >>> While blnexists = True
    >>> arr1(j) = GetRandomNumber()
    >>> blnexists = s.Contains(arr1(j))
    >>> End While
    >>> s.Push(arr1(j))
    >>> Next
    >>> For x = 0 To Value
    >>> arr1(x) = s.Pop()
    >>> Next
    >>> Dim I As Integer
    >>> Dim UserNum As ArrayList = New ArrayList
    >>> For I = 0 To Value
    >>> UserNum.Add(arr1(I))
    >>> Next
    >>> Generate= New ArrayList(UserNum)
    >>> End Function
    >>>
    >>> And then this code is in my code behind class...............
    >>>
    >>> Dim test As ArrayList
    >>> test = newPick.GeneratePick(5)
    >>>
    >>> Me.TextBox1.Text = test.Item(0)
    >>> Me.TextBox1.Text = test.Item(1)
    >>> Me.TextBox1.Text = test.Item(2)
    >>> Me.TextBox1.Text = test.Item(3)
    >>> Me.TextBox1.Text = test.Item(4)
    >>> Me.TextBox1.Text = test.Item(5)
    >>>
    >>> "mortb" <mortb1<noospam<@hotmail.com> wrote in message
    >>> news:...
    >>>> Like this (pseudo code not compiled)?
    >>>> Page code behind:
    >>>>
    >>>> submit onclick:
    >>>>
    >>>> Dim userRandomNumbers as ArrayList = new ArrayList()
    >>>> if userRnd1.Text.Trim() != ""
    >>>> userRandomNumbers.Add(int.Parse(userRnd1.Text.Trim())) ' Assuming
    >>>> there are text fields for the random numbers
    >>>> end if
    >>>> if userRnd2.Text.Trim() != ""
    >>>> userRandomNumbers.Add(int.Parse(userRnd2.Text.Trim()))
    >>>> end if
    >>>> ...
    >>>>
    >>>> ' if the generate would return an arraylist of x random numbers:
    >>>> int x = 6 - userRandomNumbers.Count
    >>>> userRandomNumbers.AddRange(BusinessObject.Generate(x))
    >>>> userRandomNumbers.Sort()
    >>>>
    >>>> 'if you want to display the resulting numbers on your webform:
    >>>> userRnd1.Text.= userRandomNumbers[0]
    >>>> userRnd2.Text.= userRandomNumbers[1]
    >>>> ...
    >>>>
    >>>> ' code that post data to database goes here...
    >>>>
    >>>> "Leon" <> wrote in message
    >>>> news:O%...
    >>>>> Thanks for your reply, but what I want to do is pass the randomly
    >>>>> generated numbers from the Generate function which is in the business
    >>>>> tier to my webform.
    >>>>> Do I need to declare the Generate function as a ArrayList or build a
    >>>>> separate ArrayList function or sub and pass the values from there to
    >>>>> my page?
    >>>>> OR....
    >>>>> How do I get the five generated number from this class which is in the
    >>>>> business tier to my webform?
    >>>>
    >>>>
    >>>
    >>>

    >>
    >>

    >
    >
     
    Leon, Nov 26, 2004
    #9
  10. Leon

    mortb Guest

    Most small errors...so easy to miss and yet so obvious...we've all been
    there :)

    "Leon" <> wrote in message
    news:...
    > Thanks for all the help I got it. LOOK! in the code I posted all the
    > textboxes was the same name so all the values went to that textbox.
    >
    > Me.TextBox1.Text = test.Item(0)
    > Me.TextBox1.Text = test.Item(1)
    > Me.TextBox1.Text = test.Item(2)
    > Me.TextBox1.Text = test.Item(3)
    > Me.TextBox1.Text = test.Item(4)
    > Me.TextBox1.Text = test.Item(5)
    >
     
    mortb, Nov 30, 2004
    #10
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. rob

    ASP v2 & 3-tier or 2-tier

    rob, Aug 13, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    425
    Steve C. Orr [MVP, MCSD]
    Aug 13, 2004
  2. NOSPAM

    2 tier to 3 tier?

    NOSPAM, Oct 14, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    454
    =?Utf-8?B?Q293Ym95IChHcmVnb3J5IEEuIEJlYW1lcikgLSBN
    Oct 14, 2004
  3. Steve Kershaw

    Setting up a new tier in a 3-tier system?

    Steve Kershaw, Mar 28, 2006, in forum: ASP .Net
    Replies:
    3
    Views:
    466
    Steve Kershaw
    Mar 29, 2006
  4. Shantanu Bhattacharya
    Replies:
    2
    Views:
    573
    Christopher Benson-Manica
    Dec 26, 2003
  5. Nemisis
    Replies:
    1
    Views:
    508
    sloan
    Aug 22, 2006
Loading...

Share This Page