write vb script code to delete the duplicate values in an
array.

Answers were Sorted based on User's Feedback



write vb script code to delete the duplicate values in an array...

Answer / guest

dim a
aList=Array(5,5,5,5,12,10,15,10,125,5)
Dim sNewList
dim newArray
b= ubound(aList)

For x=0 to b
If InStr(sNewList,(aList(x) & ",")) <= 0 Then
sNewList = sNewList & aList(x) & ","
End If


Next
newArray = split(sNewList,",")
MsgBox sNewList

Is This Answer Correct ?    37 Yes 10 No

write vb script code to delete the duplicate values in an array...

Answer / saket bharti

aList=Array(5,5,5,5,12,10,15,10,125,5,1,1,2,3,4,5,6,7,8,8,8,8,8,8,8)

ReDim newArray(UBound(aList))

count=1

newArray(0)=aList(0)

for i=0 to UBound(aList)

temp=aList(i)

flag=0

for j=0 to UBound(newArray)

if ( newArray(j)=temp) Then

flag=1

End if

Next

if flag=0 then

newArray(count)=temp

count=count+1

End If

Next

ReDim Preserve newArray(count)


for j=0 to UBound(newArray)-1

msgbox newArray(j)

Next

Is This Answer Correct ?    9 Yes 1 No

write vb script code to delete the duplicate values in an array...

Answer / jay prakash

There are many ways this script can be written.
One simple algo which i followed was:

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''Script Starts Here'''''''''''''''''''''''''''''''

Option Explicit

Dim i, j, k, aMyArr, aNewArr( ), iNewIndex, iNewLim, bFlag

bFlag = 0

aMyArr = Array("AA","BB","AA", "BB" )

iNewIndex = UBound(aMyArr)

ReDim aNewArr(0)
aNewArr(0) = aMyArr(0)

For i=0 To UBound(aMyArr)

iNewLim = UBound(aNewArr)

For j = 0 To iNewLim
If aMyArr(i) = aNewArr(j) Then
bFlag = 0
Exit For
Else
bFlag = 1
End If
Next

If bflag = 1 Then
k=iNewLim+1
ReDim Preserve aNewArr(k)
aNewArr(k)=aMyArr(i)
End If

Next

' To display the new array...
For i = 0 to UBound(aNewArr)
msgbox aNewArr(i)
Next


Erase aMyArr
Erase aNewArr

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''Script Ends Here'''''''''''''''''''''''''''''''

Please let me know if it satisfies ur query.

Is This Answer Correct ?    9 Yes 4 No

write vb script code to delete the duplicate values in an array...

Answer / bhaskar sarma

Input = Array(6,6,6,7,6,75,78,75,75,6,66,6.6)
count = 0
arr = ","

for Bye =0 to ubound(input)-1 step 1

for Hello=Bye+1 to ubound(input) step 1

if strcomp(Input(Bye),Input(Hello),1)=0 AND instr(1,arr,Input(Hello))<=0 then
count = count + 1
arr = input(Hello) & ","
exit for
end if
next
next

msgbox count

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More QTP Interview Questions

I have action1, action2, action3 r there.my query is while executing if i get any error in action1 i want exit from here itself, otherwise execute action2, if i get any error in action2 i want exit from hereitself, like this,what is the method for this?

5 Answers   AZTEC,


Hello! i am having two comboboxes.Each having 10 items in it.when i select first item in first combobox,it is not similar in the second combobox.for ex in first combo if it is Hyderabad,in second it should be some chenai or some other item .Write a VBSCRIPT for that?

3 Answers   Tech Mahindra,


What is Optional step?

4 Answers  


i've installed qtp9.2 on Windows 7. Recording and everything no problem. But when i am saving the test, it is not happening. it says 'general error while saving'. But teh test is getting saved but as a folder with lock icon. When i wanted to open it, it is jst showing as a locked folder but not as a test. Somebody help me out plz

1 Answers  


How to test the mandatory fields in QTP?

1 Answers   SoftSolve, TE,






When to use descriptive programming?

0 Answers  


we have 10 automation scripts. how to call them from one main script.

2 Answers  


If I change the property value at runtime is it effect is object repository?

0 Answers  


wt is playback facilityin qtp?

2 Answers   IBM,


Hi, How to export the Checkpoints and Output values(Test area output values) from Object Repository to Excel

3 Answers   Wipro,


I want to know how to execute the descriptive programming in qtp for the webedit object which does not contain attached text property. but i have checked it with name and html id property. Even though it is not executing. it is giving error in object's physical description.

2 Answers  


How to execute a winrunner script in quicktest professional (qtp)?

0 Answers  


Categories