Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Array element
hello,
Someone could tell me which is the instruction to delete an Array element ? It could seems a silly question, but I didn't find it inside the VB manual. I submit a simply example to explain myself better: For primat = 1 To 50 if newarr(primat) = 15 then "delete element" Next primat here I have a "newarr" Array and verifying its elements, I want to delete all 15 values. Many thanks. Andrea. |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Array element
if newarr(primat) = 15 then "delete element"
becomes if newarr(primat) = 15 then newarr(primat) = 0 Pascal "Andrea" wrote in message ... hello, Someone could tell me which is the instruction to delete an Array element ? It could seems a silly question, but I didn't find it inside the VB manual. I submit a simply example to explain myself better: For primat = 1 To 50 if newarr(primat) = 15 then "delete element" Next primat here I have a "newarr" Array and verifying its elements, I want to delete all 15 values. Many thanks. Andrea. |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Array element
a P Daulton has implied, there is no command to delete an element of an
array. j = 1 for primat = 1 to 50 if newarr(primat) < 15 then newarr(j) = newarr(primat) j = j + 1 end if Next for i = j to 50 newarr(i) = 0 Next might be what you want. Sub tester1() Dim newarr(1 To 50) For i = 1 To 50 If Rnd() < 0.25 Then newarr(i) = 15 Else newarr(i) = i End If Next Range("A1:A50").Value = Application.Transpose(newarr) j = 1 For primat = 1 To 50 If newarr(primat) < 15 Then newarr(j) = newarr(primat) j = j + 1 End If Next For i = j To 50 newarr(i) = 0 Next Range("B1:B50").Value = Application.Transpose(newarr) End Sub -- Regards, Tom Ogilvy "Andrea" wrote in message ... hello, Someone could tell me which is the instruction to delete an Array element ? It could seems a silly question, but I didn't find it inside the VB manual. I submit a simply example to explain myself better: For primat = 1 To 50 if newarr(primat) = 15 then "delete element" Next primat here I have a "newarr" Array and verifying its elements, I want to delete all 15 values. Many thanks. Andrea. |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Array element
Andrea wrote:
hello, Someone could tell me which is the instruction to delete an Array element ? It could seems a silly question, but I didn't find it inside the VB manual. I submit a simply example to explain myself better: For primat = 1 To 50 if newarr(primat) = 15 then "delete element" Next primat here I have a "newarr" Array and verifying its elements, I want to delete all 15 values. Many thanks. Andrea. I don't know what you mean by "verifying its elements"; but in any event, in your workbook VB Editor click on Tools|References and check Microsoft Scripting Runtime. Then, assuming you have a 1-based, N-element, 1-D array named "newarr", call the following function with DeleteElems newarr, 15 to delete the elements equal to 15 (if any) and reduce the upper bound from N to N-the number of occurrences of 15: Function DeleteElems(InputArray, ElemValue) As Boolean Dim x As Dictionary, Elem As Variant Dim Num As Long, i As Long Set x = New Dictionary Num = 0 For Each Elem In InputArray x.Add CStr(Num), Elem If Elem = 15 Then x.Remove (CStr(Num)) Num = Num + 1 Next InputArray = x.Items ReDim Preserve InputArray(1 To UBound(InputArray) + 1) End Function Alan Beban |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
Array element
Tom Ogilvy wrote:
a P Daulton has implied, there is no command to delete an element of an array. j = 1 for primat = 1 to 50 if newarr(primat) < 15 then newarr(j) = newarr(primat) j = j + 1 end if Next for i = j to 50 newarr(i) = 0 Next might be what you want. If you substitute the following for the second loop you probably have it: ReDim Preserve newarr(1 To j - 1) Alan Beban |
#6
Posted to microsoft.public.excel.programming
|
|||
|
|||
Array element
Depends on whether i want to resize the array or not. Delete would imply
that but is not definitive. Resizing, as you know, but maybe the OP doesn't, would require that the array be dynamic. Looping with hard coded bounds would imply fixed - but again, specifics were not provided. -- Regards, Tom Ogilvy "Alan Beban" wrote in message ... Tom Ogilvy wrote: a P Daulton has implied, there is no command to delete an element of an array. j = 1 for primat = 1 to 50 if newarr(primat) < 15 then newarr(j) = newarr(primat) j = j + 1 end if Next for i = j to 50 newarr(i) = 0 Next might be what you want. If you substitute the following for the second loop you probably have it: ReDim Preserve newarr(1 To j - 1) Alan Beban |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Counting Array element | Excel Worksheet Functions | |||
Can one store a string in a Array element? | Excel Discussion (Misc queries) | |||
Search array and return element No | Excel Worksheet Functions | |||
Permutations of an array element < to a value | Excel Worksheet Functions | |||
deleting array element | Excel Programming |