Results 1 to 9 of 9

Thread: [2005] Int32[]Array? Array help

  1. #1

    Thread Starter
    Addicted Member Abrium's Avatar
    Join Date
    Feb 2007
    Location
    The Great State of Texas
    Posts
    205

    Question [2005] Int32[]Array? Array help

    I have a small array here and when I debug I receive Int32[]Array... I don't even know what that means at this point but moving on. I am attempting to store the size of fish into an array and this is what I have:

    Code:
    dim fish(19) as Integer
    dim count as Integer = 0
    dim size as Integer
    
    size = Cint(InputBox("What size fish did you catch?"))
    
    For count = 0 to 19
    fish(count) = size
    next count
    
    LisBox1.Items.Add(fish)
    What I am trying to do is have the input box appear 20 times and have each entry stored in the array. Yet when I attempt to run this small lil prog my listbox shows Int32[]Array. Any help guys?

    I'm gonig to research Int32[]Array because I really do not know what this means and I can't find it covered in the book and this is my first attempt at an array.

    Thank you in Advance,
    honest Abe
    Last edited by Abrium; Apr 17th, 2007 at 04:41 AM.
    Abrium
    Asking the beginners questions so you don't have to!
    If by chance hell actually froze over and I some how helped you... Please rate.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: [2005] Int32[]Array? Array help

    You're only calling InputBox once. If you want it to be called more than once then it needs to be inside the loop.

    Also, you're only adding one item to the ListBox. That item is the array itself, so that's what you're seeing: a string representation of an Int32 array. If you want to add the contents of the array then you you need to call AddRange instead of Add.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3
    Frenzied Member stimbo's Avatar
    Join Date
    Jun 2006
    Location
    UK
    Posts
    1,739

    Re: [2005] Int32[]Array? Array help

    Fish is an array. You are trying to add Fish which doesn't have an index value for a start so it's giving you the array type. You need to move things around.
    vb Code:
    1. Dim fish(19) As Integer
    2.         Dim count As Integer = 0
    3.         Dim size As Integer = 0
    4.  
    5.         For count = 0 To 19
    6.             size = CInt(InputBox("What size fish did you catch?"))
    7.             fish(count) = size
    8.             ListBox1.Items.Add(fish(count))  'Add current value
    9.         Next count
    Last edited by stimbo; Apr 17th, 2007 at 04:48 AM.
    Stim

    Free VB.NET Book Chapter
    Visual Basic 2005 Cookbook Sample Chapter

  4. #4

    Thread Starter
    Addicted Member Abrium's Avatar
    Join Date
    Feb 2007
    Location
    The Great State of Texas
    Posts
    205

    Re: [2005] Int32[]Array? Array help

    I see what your saying Jm, I don't know why I didn't see that. Stim I made the alterations that you suggested and the listbox does indeed show each index now instead of the repersentation of the array but my values are not transfering from the input box to the listbox.

    I mean this is day 1, hour 1, 10 minutes into my first array and I'm finding it, for lack of a better word, squirrelly... hehe
    Abrium
    Asking the beginners questions so you don't have to!
    If by chance hell actually froze over and I some how helped you... Please rate.

  5. #5

    Thread Starter
    Addicted Member Abrium's Avatar
    Join Date
    Feb 2007
    Location
    The Great State of Texas
    Posts
    205

    Re: [2005] Int32[]Array? Array help

    it doesn't care for the ".AddRange" either, I add that in there and my laptop about beats the hell outta me
    Abrium
    Asking the beginners questions so you don't have to!
    If by chance hell actually froze over and I some how helped you... Please rate.

  6. #6
    Frenzied Member stimbo's Avatar
    Join Date
    Jun 2006
    Location
    UK
    Posts
    1,739

    Re: [2005] Int32[]Array? Array help

    The listbox thing might be due to the difference in spelling. Yours is LisBox, mine is ListBox....

    Regarding the AddRange, you would need to move the Listbox.Items line out of the loop, add it after the loop.

    Although you probably have to change your declaration of fish as Listboxes take Objects so it may not like the String declaration of the Fish variable. Maybe JMC can clarify/confirm this...
    Stim

    Free VB.NET Book Chapter
    Visual Basic 2005 Cookbook Sample Chapter

  7. #7

    Thread Starter
    Addicted Member Abrium's Avatar
    Join Date
    Feb 2007
    Location
    The Great State of Texas
    Posts
    205

    Re: [2005] Int32[]Array? Array help

    We shall see... I'm just trying to grab the fundamentals of using the counter to store with in a variable. Once I can get that I can begin to alter the coding to perform bigger and better things, I just grabbed an example out of the book.

    I suppose with the rest of what I have done thus far in VB you have to crawl, walk, and then run with it.

    Always a pleasure Stim
    Abrium
    Asking the beginners questions so you don't have to!
    If by chance hell actually froze over and I some how helped you... Please rate.

  8. #8
    Frenzied Member stimbo's Avatar
    Join Date
    Jun 2006
    Location
    UK
    Posts
    1,739

    Re: [2005] Int32[]Array? Array help

    I think there's actually a phase before crawling. Just lying flat on your back wiggling about, crying and not getting anywhere.

    I just tried the AddRange thing to be sure and it didn't like the string declaration of fish. When I changed it to:

    Dim fish(19) As Object

    And then used after the loop was done:

    ListBox1.Items.AddRange(fish)

    it was fine. (Taking out the existing line: Add(fish(count) :example).
    So much can go wrong of course with the input - it needs to be numeric etc... but that's for another day.
    Stim

    Free VB.NET Book Chapter
    Visual Basic 2005 Cookbook Sample Chapter

  9. #9

    Thread Starter
    Addicted Member Abrium's Avatar
    Join Date
    Feb 2007
    Location
    The Great State of Texas
    Posts
    205

    Re: [2005] Int32[]Array? Array help

    I'm just going to take it step by step out of this chapter. You can't go wrong that way, well... you hope you can't anyway. What scares me is due to my oh-so-exciting life as a midnight network admin is I get to do this eight hours a night, 5 nights a week. I can only imagine how my college comrads are fairing at this point. The full comprehension of new controls is time consuming for me. That could just simply be because I'm partially retarded though. :-)>
    Abrium
    Asking the beginners questions so you don't have to!
    If by chance hell actually froze over and I some how helped you... Please rate.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width