Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Removing Value From Array

Posted on 2009-12-27
5
Medium Priority
?
295 Views
Last Modified: 2013-11-27
Is there a way i can remove a value from the array if the value already exists. I have prepopulated the bye positions in the table, which are predetermined draw locations. so when rndvalue =  bye position i need to be able to remove that value from the array randomize again and then proceed with my code..

thanks

Dim RndValue As Integer
Dim arr() As Integer
Dim i As Integer, j As Integer
 
ReDim arr(intRange)
 
For i = 0 To intRange ' populate array with initial values
arr(i) = i + 1
Next i
 
For i = intRange To 0 Step -1
Randomize    ' Initialize random-number generator.
RndValue = Int(((i + 1) * Rnd)) ' get random value

Debug.Print arr(RndValue) ' print in immediae window
'''if this arr(rndValue) exists in table x, remove this value from this array and continue. 


For j = RndValue To i - 1 ' repopulate array
arr(j) = arr(j + 1)
Next j
 
Next i

Open in new window

0
Comment
Question by:j_Bryan
  • 3
  • 2
5 Comments
 
LVL 7

Expert Comment

by:msacc97
ID: 26128902
Did you read the explanation to the previous question?
Again, what do you mean by removing value from array?
Picked value is no more used in further seed and Randomize fires at the beginning of every cycle.
0
 

Author Comment

by:j_Bryan
ID: 26128976
I am buidling a Tournament Bracket Database

If there isnt a full field of players then their will be byes, these byes are a predetermined draw no...for example if there are 31 players then code selects a 32 player bracket, the 1 bye that is used would be placed at position 32, if there are only 30 players, the two byes would be placed at 32 and 16 respectively., this would continue until the total players are 16 or less, then bracket would change to 16 player bracket etc...

so right now, my code determines how many players there are, selects the proper bracket, then determines if there are byes, if there are byes, my code opens up rst and updates the brackets that would be receving a bye with a player named "bye"...

so when this array is being used i need to be able to check to see if the random value pulled from the array is already assigned a bye in the table...this would be easy if the bye locations didn't matter, i would then just fill the array with as many players as i have....no problem...but the byes are set in the following order based on how many there are  

1st bye DrawNo 32  or Bracket Spot 32
2nd bye drawNo 16 or bracket spot 16
17
1
25
25
9
24
8
29
13
21
5
20
4
28


does this help
0
 
LVL 7

Accepted Solution

by:
msacc97 earned 750 total points
ID: 26129709
You can use type of

If DCount("PlayerID","TableX","PlayerValue = " & RndValue) > 0 Then

to figure out if value is already present in the table
0
 

Author Closing Comment

by:j_Bryan
ID: 31670243
figured out myself
0
 

Author Comment

by:j_Bryan
ID: 26375206
Figured
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
In a use case, a user needs to close an opened report by simply pressing the Escape (Esc) key. This can be done by adding macro code in Report_KeyPress or Report_KeyDown event.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
Suggested Courses

564 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question