I should really know this but I can't think straight at the moment.
Is there a Mid equivalent for arrays? Can you do it using CopyMemory or something similar or do I just have to use loops?
Thanks
Printable View
I should really know this but I can't think straight at the moment.
Is there a Mid equivalent for arrays? Can you do it using CopyMemory or something similar or do I just have to use loops?
Thanks
What are you trying to do?
And no - there is no mid for arrays.
I came up with this which seems to work well:VB Code:
Private Sub MidArray(iStart, iLength, inArray() As Byte, ByRef outArray() As Byte) ReDim outArray(iLength) For i = 0 To iLength outArray(i) = inArray(iStart + i) Next i End Sub
Yeah, tell us what it is you're trying to do. A mid statement might not be the way to do it?
This seems to do the same this but not quite. Can you see what is wrong with it?VB Code:
CopyMemory outArray(0), inArray(iStart), iLength
Not to sound like an echo, but what exactly are you trying to do?
I think you might need to take into account the actual # of bytes that a datatype uses up. For example if it uses 2 bytes, then you would pass iLength*2 for the length.
It is working fine! I was being an idiot and comparing two compeltely different byte arrays! :D Oooops
VB Code:
Option Explicit Private Sub Form_Load() Dim myArray() As String Dim myInput() As String Dim myString As String myString = "this that and the other" myInput = Split(myString) ArrayMid myInput, myArray, 1 MsgBox Join(myArray) End Sub Private Sub ArrayMid(ByRef Source_Array() As String, ByRef Target_Array() As String, StartIndex As Long, Optional NumIndexes As Long) If StartIndex < LBound(Source_Array) Then Err.Raise 9 If NumIndexes < 1 Then NumIndexes = UBound(Source_Array) - (StartIndex - LBound(Source_Array)) + 1 If NumIndexes - 1 + StartIndex > UBound(Source_Array) Then NumIndexes = UBound(Source_Array) - (StartIndex - LBound(Source_Array)) + 1 ReDim Target_Array(0 To NumIndexes - 1) Dim LoopVar As Long For LoopVar = StartIndex To StartIndex + NumIndexes - 1 Target_Array(LoopVar - StartIndex) = Source_Array(LoopVar) Next End Sub