Removing Value From Array

Posted on 2009-12-27
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..


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

Question by:j_Bryan
    LVL 7

    Expert Comment

    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.

    Author Comment

    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 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

    does this help
    LVL 7

    Accepted Solution

    You can use type of

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

    to figure out if value is already present in the table

    Author Closing Comment

    figured out myself

    Author Comment


    Featured Post

    Find Ransomware Secrets With All-Source Analysis

    Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

    Join & Write a Comment

    This isn't a frequent question on EE. I must have seen it three or four times (among several thousand questions). However, I use this trick quite often, most frequently as a delayed Current event. A form does not expose it's calculation dependenc…
    A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
    What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
    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…

    728 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

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now