Log inUsernamePassword
Log me on automatically each visit    
Register
Register
Log in to check your private messages
Log in to check your private messages
Visual Basic Forum for Visual Basic Programmers VB Forum Index » General

Post new topic   Reply to topic
Multible array's
View previous topic :: View next topic  
Author Message
Downtown
Newbie


Joined: 06 Dec 2003
Posts: 10

PostPosted: Dec 10th, 2003 10:06 PM    Post subject: Multible array's Reply with quote

I have two array's, consisting of 2 labels each. Using the Do-Until and a Do While Loop I can get one array to show integers
when I run the code but then I get an error message that reads "Control array element "2" does not exist" I have these two arrays: LblRed and LblWhite with two labels each. I have enclosed the current code I have been working with. Any ideas? I'm attaching a Word doc with the play command for this code.
Thanks in advance,
Downtown
PS:
I will also submitt the code in another Tread as it is to large for this one.
_________________
We can not change the past, the best we can hope for is to influence the future.
Back to top
View user's profile Send private message Send e-mail
Downtown
Newbie


Joined: 06 Dec 2003
Posts: 10

PostPosted: Dec 10th, 2003 10:07 PM    Post subject: Code Reply with quote

Private Sub CmdPlay_Click(Index As Integer)
Dim LblRedVal(26) As Integer 'an array with a maximum value of 26
Dim LblWhiteVal(26) As Integer 'an array with a maximum value of 26
Dim iVal As Integer 'number of labels in array
Dim iNumber As Integer 'starts with 0
Dim Randomize
'Loop to random number for each label 1-2
Do While iVal < 2
iNumber = 25 * Rnd
If LblWhiteVal(iNumber) = 0 Then
LblWhite(iVal).Caption = iNumber + 1
LblWhiteVal(iNumber) = 1
iVal = iVal + 1
End If
Loop

Do
iNumber = 25 * Rnd
If LblRedVal(iNumber) = 0 Then
LblRed(iVal).Caption = iNumber + 1
LblRedVal(iNumber) = 1
iVal = iVal + 1
End If
Loop Until iVal = 2

End Sub
_________________
We can not change the past, the best we can hope for is to influence the future.
Back to top
View user's profile Send private message Send e-mail
Blaz3
Guest





PostPosted: Dec 10th, 2003 11:51 PM    Post subject: Reply with quote

Try loading it first.

Load LblWhiteVal(iNumber)
Back to top
Dragona
Newbie


Joined: 11 Dec 2003
Posts: 7

PostPosted: Dec 12th, 2003 04:49 AM    Post subject: Reply with quote

did it work, if not i think its because arrays start at 0 and you have told it to add 1 each time to its going

0 +1
1 +1
2 this number doesnt exist

so try something like

if lblWhite(ival) = 1 then
Exit sub
else
lblWhite(ival) + 1
end if

or try a For Next statement

does that look about right? i hope it helps and i hope it is right its off the top of my head so early in the morning *yawn*
_________________
Biggrin :O Biggrin


Last edited by Dragona on Dec 12th, 2003 04:52 AM; edited 1 time in total
Back to top
View user's profile Send private message
Downtown
Newbie


Joined: 06 Dec 2003
Posts: 10

PostPosted: Dec 12th, 2003 07:23 AM    Post subject: Trying Reply with quote

I will try this code change, but the current code if I only use one array. As in I comment out the white array and then the
red array works fine or vice-versa so the 0
+ 1 is OK. I'm going to change the name of the array's to array1 and array2 to see if that will help. maybe I don't understand the term "element"?

Thanks,
Downtown
_________________
We can not change the past, the best we can hope for is to influence the future.
Back to top
View user's profile Send private message Send e-mail
Dragona
Newbie


Joined: 11 Dec 2003
Posts: 7

PostPosted: Dec 12th, 2003 08:21 AM    Post subject: Reply with quote

when ever i get that i have a loop that goes on and on but doesnt stop at the end of the array so i have an array of 5 and it says element 6 is not dfined or what ever.

i recently made a lotto program and i had several errors like this when i used a loop i had 6 text boxes i had an array declared as

dim intRNArray(5) ' 6 places

so for me element 6 was either a seventh text box or a seventh memory location to rectify it i had to put a -1 some where in the loop.

so element is probarbly a control on the form.

i know sometimes dont type clearly but i hope some of this makes sense
_________________
Biggrin :O Biggrin
Back to top
View user's profile Send private message
Dragona
Newbie


Joined: 11 Dec 2003
Posts: 7

PostPosted: Dec 12th, 2003 08:45 AM    Post subject: Reply with quote

i have figured it out ^^ if you want the code then PM or post

edit: my code is almost identical to yours

and your numbers are not random

you need to put randomize above each "rnd" statement otherwise you will get the same numbers in the same order every time you play the game from scratch
_________________
Biggrin :O Biggrin


Last edited by Dragona on Dec 12th, 2003 08:52 AM; edited 1 time in total
Back to top
View user's profile Send private message
Downtown
Newbie


Joined: 06 Dec 2003
Posts: 10

PostPosted: Dec 13th, 2003 12:00 PM    Post subject: Element "2" Randomize Reply with quote

I had noticed the problem with the reoccuring numbers. So I loaded the "Randomize" in the Form Load. Now the array labels that work are truely random every time. I still have a problem with the 2nd array of labels not receiving the numbers because of the missing "2" element. So I still need help. And I'm working on a Lotto number picker 2 red numbers and 2 white number. I can use two command buttons but that's not what I want. When it works properly it will also print to the form and I will add a text box to ask for the number of plays I wish to print on the form. I have done this with an array of 5 plus an additional label with no problems, but having 2 arrays has caused me this headache.
Thanks in advance,
Downtown
_________________
We can not change the past, the best we can hope for is to influence the future.
Back to top
View user's profile Send private message Send e-mail
Downtown
Newbie


Joined: 06 Dec 2003
Posts: 10

PostPosted: Dec 14th, 2003 08:46 PM    Post subject: Reply with quote

Problem solved!!
Made these changes.
Dim iVal As Integer 'number of labels in array
Dim iNumber As Integer 'starts with 0
To
Dim iVal1 As Integer 'number of labels in array
Dim iNumber1 As Integer 'starts with 0

By adding a 1 to the end of iVal and iNumber I then could run the second loop.

Thanks to all who helped.
Downtown
_________________
We can not change the past, the best we can hope for is to influence the future.
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    Visual Basic Forum for Visual Basic Programmers VB Forum Index » General All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Visual Basic Forum runs phpBB | Forum Template © iOptional
VB Resources | SSL | Visual Basic