Creating ArrayList to store data

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • cmdolcet69

    #1

    Creating ArrayList to store data

    I have a project in which i need to add to existing code. My
    predecessors, had all sorts of arraylist in which he would save his
    information. How can i create an arraylist of (intnumber) so that i
    can compare them against the original arraylist??

    Please help, Thanks in advance

  • Phillip Taylor

    #2
    Re: Creating ArrayList to store data

    On 3 Sep, 14:58, cmdolcet69 <colin_dolce... @hotmail.comwro te:
    I have a project in which i need to add to existing code. My
    predecessors, had all sorts of arraylist in which he would save his
    information. How can i create an arraylist of (intnumber) so that i
    can compare them against the original arraylist??
    >
    Please help, Thanks in advance
    Probably something like this:

    'at top of file
    Imports System.Collecti ons
    Imports System.Collecti ons.Generic

    'under some function

    dim myArrayList as New ArrayList(of IntNumber)

    for each hisObject as IntNumber in hisArrayList

    if (myArrayList.co ntains(hisObjec t)) then
    'I already have his object in my list
    else
    'I don't already have his object in my array list
    myArrayList.Add (hisObject)
    end if
    next

    Comment

    • cmdolcet69

      #3
      Re: Creating ArrayList to store data

      On Sep 3, 11:34 am, Phillip Taylor <Phillip.Ross.T ay...@gmail.com >
      wrote:
      On 3 Sep, 14:58, cmdolcet69 <colin_dolce... @hotmail.comwro te:
      >
      I have a project in which i need to add to existing code. My
      predecessors, had all sorts of arraylist in which he would save his
      information. How can i create an arraylist of (intnumber) so that i
      can compare them against the original arraylist??
      >
      Please help, Thanks in advance
      >
      Probably something like this:
      >
      'at top of file
      Imports System.Collecti ons
      Imports System.Collecti ons.Generic
      >
      'under some function
      >
      dim myArrayList as New ArrayList(of IntNumber)
      >
      for each hisObject as IntNumber in hisArrayList
      >
      if (myArrayList.co ntains(hisObjec t)) then
      'I already have his object in my list
      else
      'I don't already have his object in my array list
      myArrayList.Add (hisObject)
      end if
      next
      I added your following suggestion with a little modification:

      Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
      System.EventArg s) Handles Button1.Click
      Dim objects As Integer
      Dim index As Integer
      For objects = 0 To PassArrayList1( index)
      objects += 1
      Next

      End Sub


      However when i run it i get an error: An unhandled exception of type
      'System.Argumen tOutOfRangeExce ption' occurred in mscorlib.dll

      What does this mean and how can i fix this?

      Comment

      • Jack Jackson

        #4
        Re: Creating ArrayList to store data

        On Mon, 03 Sep 2007 15:51:40 -0700, cmdolcet69
        <colin_dolcetti @hotmail.comwro te:
        >On Sep 3, 11:34 am, Phillip Taylor <Phillip.Ross.T ay...@gmail.com >
        >wrote:
        >On 3 Sep, 14:58, cmdolcet69 <colin_dolce... @hotmail.comwro te:
        >>
        I have a project in which i need to add to existing code. My
        predecessors, had all sorts of arraylist in which he would save his
        information. How can i create an arraylist of (intnumber) so that i
        can compare them against the original arraylist??
        >>
        Please help, Thanks in advance
        >>
        >Probably something like this:
        >>
        >'at top of file
        >Imports System.Collecti ons
        >Imports System.Collecti ons.Generic
        >>
        >'under some function
        >>
        >dim myArrayList as New ArrayList(of IntNumber)
        >>
        >for each hisObject as IntNumber in hisArrayList
        >>
        > if (myArrayList.co ntains(hisObjec t)) then
        > 'I already have his object in my list
        > else
        > 'I don't already have his object in my array list
        > myArrayList.Add (hisObject)
        > end if
        >next
        >
        >I added your following suggestion with a little modification:
        >
        Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
        >System.EventAr gs) Handles Button1.Click
        Dim objects As Integer
        Dim index As Integer
        For objects = 0 To PassArrayList1( index)
        objects += 1
        Next
        >
        End Sub
        >
        >
        >However when i run it i get an error: An unhandled exception of type
        >'System.Argume ntOutOfRangeExc eption' occurred in mscorlib.dll
        >
        >What does this mean and how can i fix this?
        "with a little modification"? Your Sub bears no relation to the code
        Philip posted.

        You should be able to easily find bugs like this using the debugger.
        Which line gets the error when you run with the debugger? No doubt it
        is the For statement since you are indexing PassArrayList1 with a
        variable you have not initialized.

        Your For loop makes no sense. The For loop increments 'objects', but
        then you increment it again yourself. You also never set the variable
        'index'. The Sub doesn't return any value or affect any data outside
        of itself, so even it it didn't trap it would have no effect.

        I also don't see how this Sub has any relation to the original
        question you asked.

        Comment

        Working...