Results 1 to 5 of 5

Thread: [RESOLVED] Array is inheriting instead of reseting....

Threaded View

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Sep 2011
    Location
    Seattle
    Posts
    218

    Resolved [RESOLVED] Array is inheriting instead of reseting....

    Im having a little issue in my code that I wasnt expecting and Im not quite sure how to fix it.

    normally in an example like this:

    Code:
            Dim test1 As String = "1"
            Dim test2 As String = test1
            test2 = "test"
    
            MsgBox(test1 & test2)
    You would expect the prompt to be "1test" as defining test2 = "test" will not change test1 to "test" giving you the prompt "testtest"

    However, that is exactely what is happening when I use this principal on a two dimensional string array.

    Code:
       Public Shared Sub MakeSchedule(ByVal BUArray As String(,), ByVal unPatList As List(Of String))
            Dim patRemove As New List(Of Integer)
    
            Do Until patRemove.Count = unPatList.Count
                Dim nArray As String(,) = BUArray
                patRemove = New List(Of Integer)
    
                For x as integer = 0 to 8
                       'Do a bunch of code to fill in nArray 
                       'add to PatRemove.count 
                Next
            Loop
        End Sub
    Where the comments are I am doing a series of commands that add to both nArray and patRemove.count. However, sometimes after the commands patRemove.count will still not be high enough (equal to unPatlist.count). On those instances I need patRemove.Count to start back at 0 and for nArray to reinitialize itself from BUArray (BackUp Array). But when it goes to reinitialize, BUArray has been changing alongside nArray isstead of staying with the original data even though I make absolutely no mention anywhere in the code to change BUArray.

    So my question is, why is changing nArray changing BUArray when the only mention of BUArray is when I am setting nArray? wouldnt it work just like the above example with test1 and test2?

    Thank You,
    -Z


    As a side note, I should mention that I can tell BUArray is changing from the following code

    Code:
    sb1 = New StringBuilder
    sb1.AppendLine("Rooms: " & patRemove.Count)
    sb1.AppendLine("AMT")
    For x As Integer = 0 To BUArray.GetUpperBound(1)
         Dim str As String = ""
         For y As Integer = 0 To BUArray.GetUpperBound(0)
               str += BUArray(y, x) & ","
         Next
         sb1.AppendLine(str)
    Next
    Last edited by Zmcpherson; Jan 12th, 2016 at 05:25 PM.

Tags for this Thread

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