|
-
Apr 29th, 2002, 02:37 PM
#1
Thread Starter
Addicted Member
Arrays [resolved]
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
Last edited by Martin Wilson; May 1st, 2002 at 03:35 PM.
What is the answer to this question?
-
Apr 29th, 2002, 02:47 PM
#2
What are you trying to do?
And no - there is no mid for arrays.
-
Apr 29th, 2002, 02:57 PM
#3
Thread Starter
Addicted Member
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
What is the answer to this question?
-
Apr 29th, 2002, 03:07 PM
#4
Member
Yeah, tell us what it is you're trying to do. A mid statement might not be the way to do it?
-
May 1st, 2002, 03:24 PM
#5
Thread Starter
Addicted Member
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
What is the answer to this question?
-
May 1st, 2002, 03:25 PM
#6
Stuck in the 80s
Not to sound like an echo, but what exactly are you trying to do?
-
May 1st, 2002, 03:28 PM
#7
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.
-
May 1st, 2002, 03:35 PM
#8
Thread Starter
Addicted Member
It is working fine! I was being an idiot and comparing two compeltely different byte arrays! Oooops
What is the answer to this question?
-
May 1st, 2002, 04:21 PM
#9
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
Need to re-register ASP.NET?
C:\WINNT\Microsoft.NET\Framework\v#VERSIONNUMBER#\aspnet_regiis -i
(Edit #VERSIONNUMBER# as needed - do a DIR if you don't know)
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
|