|
-
Apr 18th, 2007, 03:52 AM
#1
Thread Starter
Addicted Member
[RESOLVED] [2005] Simple Array break down please
Hey guys,
With only four months of VB experience under my belt as with many new controls I find myself not able to instantly comprehend the full use of a new control and arrays seem to be no different. I come to this forum for the experience that is offered and outside input that can see very very stupid newbie mistakes that I over look in trying to comprehend it.
I have made a small array and For... Next statement and would like it if someone could just give me a simple break down line by line so I can get a starting point in understanding the use of the counter that enables to gather input from a user and put that information into the array. Feel free to help out.
Code:
Dim intArray(19) as Integer
Dim howmany as Integer
Dim count as integer
For count = 0 to 19
howmany = CInt(InputBox("Please input how many fish " & ControlChars.CrLf _
& "you caught on each trip."))
ListBox1.Items.Add(intArray(howmany))
count += 1
Next count
Thanks
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.
-
Apr 18th, 2007, 03:57 AM
#2
Fanatic Member
Re: [2005] Simple Array break down please
I see a possible issue: you need not increment the counter manually by doing Count += 1. In the For...Next loop it is incremented automatically. In this case, it might be that the loop will run only 10 times. What else are you looking for?
-
Apr 18th, 2007, 04:03 AM
#3
Registered User
Re: [2005] Simple Array break down please
i cant understand, please explain what you want exactly.
-
Apr 18th, 2007, 04:05 AM
#4
Thread Starter
Addicted Member
Re: [2005] Simple Array break down please
Good call on the automatic incremention of the counter. The loop only ran 10 times, my next task is to find out how to take the number from the input box and store the user input into the indexes of the array. When the loop runs the output is 0 instead of the number being put in the input box.
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.
-
Apr 18th, 2007, 04:06 AM
#5
Re: [2005] Simple Array break down please
I see a bigger issue than that!
vb Code:
ListBox1.Items.Add(intArray(howmany))
Howmany is the number that people are entering, not an index value. What you need is:
vb Code:
Dim intArray(19) As Integer
Dim howmany As Integer
Dim count As Integer
For count = 0 To 19
'GET VALUE THAT USER ENTERS
howmany = CInt(InputBox("Please input how many fish " & ControlChars.CrLf _
& "you caught on each trip."))
'ASSIGN THE VALUE HOW MANY TO YOUR intARRAY AT THE CURRENT POSITION (0, then 1, then 2 etc...)
intArray(count) = howmany
'Place CURRENT intArray value into Listbox - it's the count index that tells us that
ListBox1.Items.Add(intArray(count))
'NO NEED FOR 'COUNT += 1'
Next count
-
Apr 18th, 2007, 04:08 AM
#6
Re: [2005] Simple Array break down please
You're adding elements from the array to the ListBox but you never put anything into the array, so all elements will always be zero. I was under the impression that we had addressed this same issue in another thread. Inside the loop you want to assign the value 'howmany' to the element at index 'count':
vb Code:
inatArray(count) = howmany
You can then add that value to the ListBox in the loop too using:
vb Code:
ListBox1.Items.Add(howmany)
or:
vb Code:
ListBox1.Items.Add(intArray(count))
or else you can wait until the end of the loop and then add all the values in one go, which I did post to your other thread:
vb Code:
ListBox1.Items.AddRange(intArray)
-
Apr 18th, 2007, 04:11 AM
#7
Thread Starter
Addicted Member
Re: [2005] Simple Array break down please
Boy talk about a go to guy...
Stim nailed what I needed, I line by line shown by use of comments of what is going on. Sometimes I wish I could just carry you around in my back pocket man.
Not to be out done, jmc gave a great explination also, thanks guys I'm going to be studying your replies and gaining a good working knowledge of whats going on here...
God I LOVE this forum!
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.
-
Apr 18th, 2007, 04:13 AM
#8
Thread Starter
Addicted Member
Re: [2005] Simple Array break down please
Hey Stim how are you inputting your code into this forum? Are you using the VB tag or pasting?
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.
-
Apr 18th, 2007, 04:20 AM
#9
Re: [RESOLVED] [2005] Simple Array break down please
I just put the code in the VB tags. Although it's easier to read when in colour but I don't like the numbers. Is there an option where you can have colour but not numbers? It makes copy/pasting a pain.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|