hi to all
iam using vb6.0 can any one tell me how to duplicate values in a array if possible i want to delete the duplicate values
its urgent
thanks
10 28020
hi to all
iam using vb6.0 can any one tell me how to duplicate values in a array if possible i want to delete the duplicate values
its urgent
thanks
yes, there are many ways and methods, some faster than others. The worst, slower, but easier will be to check each one vs each one, lets say your array is Arr1 - dim i, j, n as integer
-
dim list() as integer
-
n=0
-
for i = lbound(arr1) to ubound(arr1) - 1
-
for j = i + 1 to ubound(arr1)
-
if arr1(i) = arr1(j) then
-
'here use "home made function" to delete the j-th item from the array
-
j=j-1
-
end if
-
next j
-
next i
well, that wont be fast, but it'll work.
HTH
Edit: ok, i have some free time:
home made function: - arr1(j) = arr1(ubound(arr1))
-
redim preserve arr1(lbound(arr1) to ubound(arr1) -1)
^.^ wasnt that hard
I don't think you'll find many faster methods. The mistake a lot of people make is starting the inner loop form the beginning each time.
Note also, your home-made function will work only if the sequence of the elements is not significant. Oh, and you may find that a bit of extra testing or error-handling is required, since your code may try to go past the end of the array.
However, what about an alternative? If you use a collection rather than an array, you can easily prevent any duplicates being added in the first place.
There are a couple of minor tweaks which might make some difference. I'll list them in descending order of possible performance impact... - Make sure the "home-made function" is coded in-line rather than as an actual function, to reduce time used up in calling it.
- Keep track of the upper bound and just do one ReDim Preserve at the end, rather than each time you remove an entry.
- Change all Integer variables to Long.
- Define i and j as Integer or Long. You currently have them defined as the default type, most likely Variant. (No, check your syntax - they are not defined as Integer. Only n is.)
- Remove variable names from the Next statements. (This comes from an older version of BASIC and may not relate to VB, but you don't need them anyway.)
And a couple of general comments... - What the heck is list()?
- You do not need to set n = 0 at the start. It's only just been created.
- Actually, you don't even need to define n, since it isn't used.
Hi,
One of the Fastest way would be, if using a Database, add all the Values of Array to a TempTable. And Query Distinct Field Values..
Regards
Veena
One of the Fastest way would be, if using a Database, add all the Values of Array to a TempTable. And Query Distinct Field Values.
Surely a collection (or even looping through the array) would have to be faster than using a database?
Surely a collection (or even looping through the array) would have to be faster than using a database?
Hi,
I actually meant "Least Coding" or "Simple Logic"
Regards
Veena
thanks for your reply
iam having another doubt
am comparing two arrays, in array1 the size is 100 and for array2 it will took the count of first array
but my problem is
i saved 5 values to array1 ,rest of the values will be null
while comparing i need only the 5 values from array1 but it shows it has 100 values with nulls
we can restrict the values in the array1 by checking null, is there any alternative to have only the fivwe values.
can you please give me any example for multi dimensinal array.
Hi,
Declare the Array as Variant:
Dim MyArr(1 To 100)
And Check with Function IsEmpty: If you have not assigned any value to the array item, then it will be Empty..
If IsEmpty(MyArr(6)) Then
Regards
Veena
...
Note also, your home-made function will work only if the sequence of the elements is not significant. Oh, and you may find that a bit of extra testing or error-handling is required, since your code may try to go past the end of the array.
And a couple of general comments...- What the heck is list()?
- You do not need to set n = 0 at the start. It's only just been created.
- Actually, you don't even need to define n, since it isn't used.
Well about the general comments, sorry, i took it from some other code i had and forgot to clean it.
And since you're using REDIM each time you're avoiding the error handler, since you wont exceed the limits, that're actually redefined each time you remove an item, but using REDIM and UBOUND each time coud slow down things a little bit. Well, as you said, it could be faster using a counter and an error handler, or a collection.
And since you're using REDIM each time you're avoiding the error handler, since you wont exceed the limits, that're actually redefined each time you remove an item...
Actually, that's not quite correct. It's because of the ReDim that you may overrun the array. Your loop will continue on to where the array originally ended, but by then it may have shrunk.
The ending point of a FOR loop is set at the start, and does not change. So although the value returned by the Ubound() function may have changed, the FOR loop will still keep going.
...Check with Function IsEmpty...
If possible (it depends on your circumstances), it would be more efficient to keep track of how many you've populated, and only access that many.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Trond |
last post by:
I have been trying to fig out how to build up an array with dates. When its
generated i want to be able to remove duplicate dates. The dates is
generated by FileInfo object that is scanning a...
|
by: vbportal |
last post by:
Hi,
I would like to add BitArrays to an ArrayList and then remove any duplicates
- can someone please help me forward. I seem to have (at leaset ;-) )2
problems/lack of understanding (see test...
|
by: JTreefrog |
last post by:
Hello - I've read a ton of stuff about deleting duplicate values in an array. They are all very useful - they just haven't addressed an array of objects.
Here's my array:
var sDat = ;
The...
|
by: joestevens232 |
last post by:
Hello Im having problems figuring out how to remove the duplicate entries in an array...Write a program that accepts a sequence of integers (some of which may repeat) as input
into an array. Write...
|
by: aknoch |
last post by:
My basic situation is this - I ONLY want duplicates, so the opposite
of DISTINCT:
I have two tables. Ordinarily, Table1ColumnA corresponds in a one to
one ratio with Table2ColumnB through a...
|
by: cmdolcet69 |
last post by:
i need to find a way to look through my _ReadingArrayList3 and see if any number stored in the inarrayindex are duplicated. I need to first collect all the data and place it into the array, once the...
|
by: raviufor |
last post by:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>
#include <ctype.h>
#include <ctype.h>
#include <time.h>
#include <sys/types.h>
|
by: raphael001 |
last post by:
In my Visual Basic program I'm just trying to find duplicate values entered into an array from an inputbox, but i can't seem to get the coding right on the final part to check for duplicate values...
|
by: dawn123 |
last post by:
I have a 2-d array that the user enters tress species and diameter so it looks something like:
sm 10
rm 18
bf 12
sm10
sm10
rm18
and so on.. I need to be able to seach though my array and find...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |