Results 1 to 9 of 9

Thread: Arrays [resolved]

  1. #1

    Thread Starter
    Addicted Member Martin Wilson's Avatar
    Join Date
    Mar 2002
    Location
    :)
    Posts
    236

    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?

  2. #2
    jim mcnamara
    Guest
    What are you trying to do?

    And no - there is no mid for arrays.

  3. #3

    Thread Starter
    Addicted Member Martin Wilson's Avatar
    Join Date
    Mar 2002
    Location
    :)
    Posts
    236
    I came up with this which seems to work well:
    VB Code:
    1. Private Sub MidArray(iStart, iLength, inArray() As Byte, ByRef outArray() As Byte)
    2.     ReDim outArray(iLength)
    3.     For i = 0 To iLength
    4.         outArray(i) = inArray(iStart + i)
    5.     Next i
    6. End Sub
    What is the answer to this question?

  4. #4
    Member
    Join Date
    Mar 2002
    Posts
    52
    Yeah, tell us what it is you're trying to do. A mid statement might not be the way to do it?

  5. #5

    Thread Starter
    Addicted Member Martin Wilson's Avatar
    Join Date
    Mar 2002
    Location
    :)
    Posts
    236
    This seems to do the same this but not quite. Can you see what is wrong with it?
    VB Code:
    1. CopyMemory outArray(0), inArray(iStart), iLength
    What is the answer to this question?

  6. #6
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Not to sound like an echo, but what exactly are you trying to do?
    My evil laugh has a squeak in it.

    kristopherwilson.com

  7. #7
    Megatron
    Guest
    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.

  8. #8

    Thread Starter
    Addicted Member Martin Wilson's Avatar
    Join Date
    Mar 2002
    Location
    :)
    Posts
    236
    It is working fine! I was being an idiot and comparing two compeltely different byte arrays! Oooops
    What is the answer to this question?

  9. #9
    C# Aficionado Lord_Rat's Avatar
    Join Date
    Sep 2001
    Location
    Cave
    Posts
    2,497
    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Form_Load()
    4.     Dim myArray() As String
    5.     Dim myInput() As String
    6.     Dim myString As String
    7.    
    8.     myString = "this that and the other"
    9.     myInput = Split(myString)
    10.    
    11.     ArrayMid myInput, myArray, 1
    12.    
    13.     MsgBox Join(myArray)
    14.    
    15. End Sub
    16.  
    17. Private Sub ArrayMid(ByRef Source_Array() As String, ByRef Target_Array() As String, StartIndex As Long, Optional NumIndexes As Long)
    18.     If StartIndex < LBound(Source_Array) Then Err.Raise 9
    19.     If NumIndexes < 1 Then NumIndexes = UBound(Source_Array) - (StartIndex - LBound(Source_Array)) + 1
    20.     If NumIndexes - 1 + StartIndex > UBound(Source_Array) Then NumIndexes = UBound(Source_Array) - (StartIndex - LBound(Source_Array)) + 1
    21.    
    22.     ReDim Target_Array(0 To NumIndexes - 1)
    23.    
    24.     Dim LoopVar As Long
    25.     For LoopVar = StartIndex To StartIndex + NumIndexes - 1
    26.         Target_Array(LoopVar - StartIndex) = Source_Array(LoopVar)
    27.     Next
    28.    
    29. 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
  •  



Click Here to Expand Forum to Full Width