-
Oct 22nd, 2020, 02:02 PM
#1
Thread Starter
Fanatic Member
Truncate the Array
Hello:
I have read about 47 posts on this today. Nothing makes sense.
I gave the following 2d array (110,2). I have been able to sort it, but I would just like to truncate it for the blank values.
Thoughts...
Code:
1: 3: DJK
9: 11: DJK
2: 4: DLS
3: 5: DLS
7: 9: DLS
41: 43: EJJ
42: 44: EJJ
50: 52: EJJ
51: 53: EJJ
53: 55: EJJ
63: 65: EJJ
21: 23: JRD
23: 25: JRD
31: 33: JRD
88: 90: JRD
89: 91: JRD
93: 95: JRD
11: 13: NBS
6: 8: NMS
8: 10: NMS
19: 21: PLL
29: 31: PLL
30: 32: PLL
36: 38: PLL
87: 89: PLL
39: 41: RME
40: 42: RME
35: 37: SEO
14: 16: SRM
15: 17: SRM
16: 18: SRM
17: 19: SRM
56: 58: SRM
80: 82: SRM
: :
: :
: :
: :
: :
: :
: :
: :
: :
: :
: :
: :
: :
: :
: :
: :
: :
: :
: :
: :
: :
: :
: :
: :
: :
: :
: :
: :
: :
: :
: :
: :
: :
: :
: :
: :
: :
: :
: :
: :
: :
: :
: :
: :
: :
: :
: :
: :
: :
: :
: :
: :
: :
: :
: :
: :
: :
: :
: :
: :
: :
: :
: :
: :
: :
: :
- A 'Hyperactive Member' trying to make a difference in a hyperactive world! And recently, I've been promoted to a 'Finatic Member,' whatever that means!
-
Oct 22nd, 2020, 02:07 PM
#2
Re: Truncate the Array
Reconsider how you are dimensioning it. You can only resize a multidimensional array on its last dimension while using the Preserve keyword.
Dim myarray (110,2) -- won't work for you
Dim myarray (2,110) -- will work for you: ReDim Preserve myarray (2, 77) for example
-
Oct 22nd, 2020, 03:14 PM
#3
Thread Starter
Fanatic Member
Re: Truncate the Array
110 rows and 3 columns. I'm not sure I can easily restructure things.
- A 'Hyperactive Member' trying to make a difference in a hyperactive world! And recently, I've been promoted to a 'Finatic Member,' whatever that means!
-
Oct 22nd, 2020, 03:30 PM
#4
Re: Truncate the Array
The first dimension is columns, the second rows, the 3rd if any is planes, the 4th cubes, etc.
-
Oct 22nd, 2020, 03:43 PM
#5
Re: Truncate the Array
it seems from the log that 2 values are numbers and the other is a 3 letter string.
if thats so, I would make a custom type,
example:
type mytype
value1 as integer
value2 as integer
myletter as string * 3
end type
Dim myarray(110) as mytype
-
Oct 22nd, 2020, 05:19 PM
#6
Re: Truncate the Array
Originally Posted by ssabc
110 rows and 3 columns. I'm not sure I can easily restructure things.
Either restucture or create a new array and transfer old array items to new in a loop, after first sizing the new array.
-
Oct 23rd, 2020, 01:00 AM
#7
Re: Truncate the Array
Originally Posted by LaVolpe
Either restucture or create a new array and transfer old array items to new in a loop, after first sizing the new array.
Or Dim the new Array to its new Size, and then CopyMemory the VarPtr of the old Array to the new Array with the correct/new length.
Don't forget to cheat the ref-count.
EDIT: I'm with baka on that re using an UDT.
But that opens another can of worms, since the OP said something about sorting.
EDIT2: A "Hacker's" Approach might be to manipulate the SAFEARRAY2D-Descriptor, since that one has a Field called Bounds Of Type SAFEARRAYBOUND....
No Idea if that approach might start a nuclear rocket in North Korea.....
Last edited by Zvoni; Oct 23rd, 2020 at 01:10 AM.
Last edited by Zvoni; Tomorrow at 31:69 PM.
----------------------------------------------------------------------------------------
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------------------
People call me crazy because i'm jumping out of perfectly fine airplanes.
---------------------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad
-
Oct 23rd, 2020, 08:50 AM
#8
Re: Truncate the Array
sorting is easy. u can modify a quicksort,
example:
Code:
Private Sub QuickSort(c() As mytype, ByVal first As Long, ByVal Last As Long)
Dim Low As Long, High As Long
Dim MidValue As String * 3
Dim Tmp as mytype
Low = first
High = Last
MidValue = c((first + Last) \ 2).myletter
Do
While c(Low).myletter < MidValue
Low = Low + 1
Wend
While c(High).myletter > MidValue
High = High - 1
Wend
If Low <= High Then
Tmp = c(Low): c(Low) = c(High): c(High) = Tmp
Low = Low + 1
High = High - 1
End If
Loop While Low <= High
If first < High Then QuickSort c, first, High
If Low < Last Then QuickSort c, Low, Last
End Sub
and u can have 3 different, if u need to sort all 3 values.
if u need to sort both 1&2 together it will be more complicated.
array resizing, I would use Redim if its about resizing the bounds,
if its instead removing 1 item I would use a replace method.
(I always use Redim myarray(1 to 110) instead of Redim myarray(110) this because I see 0 as nothing + I always have an extra amount value that tells me if the array is empty or not)
so here:
Code:
Private Sub RemoveMyArray(ByVal c&)
Dim i&
If c < myarrays Then
For i = c To myarrays - 1
myarray(i) = myarray(i + 1)
Next i
End If
myarrays = myarrays - 1
If myarrays = 0 Then Erase myarray Else ReDim Preserve myarray(1 To myarrays)
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|