Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9076721
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T19:10:34+00:00 2026-06-16T19:10:34+00:00

I have an Array say: VMHArray = (12,22,34,4) Now have another Arraylist object say

  • 0

I have an Array say: VMHArray = (12,22,34,4) Now have another Arraylist object say ArrayListTaskDetails holding the data as (12,55,44,4,12,22,21,107,43,22,34) Now the below code I wrote to remove items from the list ArrayListTaskDetails which are not present in the VMHArray.

Code

Dim Flag : Flag = true
Dim Counter
For IndexSearch = 0 To ArrayListTaskDetails.Count - 1 step 4

    Counter = 0
    Do while Flag

        If VMHArray(Counter) <> ArrayListTaskDetails (IndexSearch) Then

          ArrayListTaskDetails.RemoveRange IndexSearch, 4
          Flag = False

        End If
    Counter = Counter + 1
    Loop

Next

Now Suppose a match found at IndexSearch = 0,so according it would delete the element at locations 0,1,2,3 – quite good. But due to removal and to make the ArrayList object contiguous by functionality other elements will be shifted by 4 to left. Now the problem is as For Loop already incremented by 4,so it would start from next iteration from location 4. Thus now the new element at 0 location in the array list can never get a chance to test the equality with the VMHArray array elements. Can we handle such scenario without loosing the intended operation or anyway if we can set the For Loop counter to its immediate position,where the just recent match found and 4 elements removed.?

If any issue to understand the problem,let me know please!

EDIT Go to will not work

CODE(as per @Ankit suggestion)

Option Explicit

Dim Flag : Flag = true
Dim Counter
Dim VMHArray : VMHArray = Array(12,22,34,4) 
Dim ArrayListTaskDetails : Set ArrayListTaskDetails = CreateObject("System.Collections.ArrayList")

    ArrayListTaskDetails.Add(45)
    ArrayListTaskDetails.Add(4)
    ArrayListTaskDetails.Add(22)
    ArrayListTaskDetails.Add(4)
    ArrayListTaskDetails.Add(45)
    ArrayListTaskDetails.Add(20)
    ArrayListTaskDetails.Add(12)
    ArrayListTaskDetails.Add(35)
    ArrayListTaskDetails.Add(34)

    Restart:
For IndexSearch = 0 To ArrayListTaskDetails.Count - 1 step 4

    Counter = 0
    Do while Flag

        If VMHArray(Counter) <> ArrayListTaskDetails (IndexSearch) Then

          ArrayListTaskDetails.RemoveRange IndexSearch, 4
          Goto Restart
          Flag = False

        End If
    Counter = Counter + 1
    Loop

Next

MsgBox(Join(ArrayListTaskDetails.ToArray()),"$")

Error

Thanks,

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T19:10:35+00:00Added an answer on June 16, 2026 at 7:10 pm

    Two ideas to solve the problem:

    1. use a dictionary to check for the items to keep
    2. loop backwards

    In code:

    Option Explicit
    
    Dim alSrc : Set alSrc = CreateObject("System.Collections.ArrayList")
    Dim sE
    For Each sE In Split("a x x x b x x x c x x x d x x x e x x x f x x x a x x x")
        alSrc.Add sE
    Next
    WScript.Echo "alSrc:", Join(alSrc.ToArray(), ".")
    Dim aKeep   : aKeep       = Split("a d")
    WScript.Echo "aKeep:", Join(aKeep, ".")
    Dim dicKeep : Set dicKeep = CreateObject("Scripting.Dictionary")
    For Each sE In aKeep
        dicKeep(sE) = 0
    Next
    WScript.Echo "dicKeep:", Join(dicKeep.Keys(), ".")
    Dim nI
    For nI = alSrc.Count - 4 To 0 Step -4
        sE = alSrc(nI)
        If Not dicKeep.Exists(sE) Then
           alSrc.RemoveRange nI, 4
        End If
        WScript.Echo sE, nI, Join(alSrc.ToArray(), ".")
    Next
    WScript.Echo "alSrc:", Join(alSrc.ToArray(), ".")
    

    output:

    alSrc: a.x.x.x.b.x.x.x.c.x.x.x.d.x.x.x.e.x.x.x.f.x.x.x.a.x.x.x
    aKeep: a.d
    dicKeep: a.d
    a 24 a.x.x.x.b.x.x.x.c.x.x.x.d.x.x.x.e.x.x.x.f.x.x.x.a.x.x.x
    f 20 a.x.x.x.b.x.x.x.c.x.x.x.d.x.x.x.e.x.x.x.a.x.x.x
    e 16 a.x.x.x.b.x.x.x.c.x.x.x.d.x.x.x.a.x.x.x
    d 12 a.x.x.x.b.x.x.x.c.x.x.x.d.x.x.x.a.x.x.x
    c 8 a.x.x.x.b.x.x.x.d.x.x.x.a.x.x.x
    b 4 a.x.x.x.d.x.x.x.a.x.x.x
    a 0 a.x.x.x.d.x.x.x.a.x.x.x
    alSrc: a.x.x.x.d.x.x.x.a.x.x.x
    

    As to the mystery of .Count – ?:

    1 2 3 4 5 6 7 8 - Count 1 - 8
    0 1 2 3 4 5 6 7 - Idx   0 - 7
    A x x x B x x x - Count (8) - Step (4) = Pos to check (4)
                      Count (8) - Step + 1 (5) = Not the pos to check (3)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an array lets say a = { 1,4,5,6,2,23,4,2}; now I have to
lets say i have one array a = numpy.arange(8*6*3).reshape((8, 6, 3)) #and another: l
I have an Array say A=(11,23,32,44,56,88,55,14,78,79) And B=(44,56,88,55,14) .Now using VBScript can I perform
I have the array variable say $value, and it has the below given array
I have an array of bytes (say byte[] data), which contains text with custom
Possible Duplicate: Can php variable hold harmfull code safely? Let's say I have array
Suppose i have array of characters. say char x[100] Now, i take input from
Possible Duplicate: convert object to array Let's say I have an array like this:
I have a problem as stated below: i have an array(say) a[]={10,24,56,33,22,11,21} i have
Populate php array into HTML table I have data in a php array (say,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.