Results 1 to 5 of 5

Thread: Why the value inside array becomes empty? [Resolved]

  1. #1

    Thread Starter
    Registered User
    Join Date
    Apr 2003
    Location
    Klang, Selangor, Malaysia
    Posts
    163

    Question Why the value inside array becomes empty? [Resolved]

    This is the code i work out:
    Code:
    Private Function funSplitText(ByVal strRinggit As String) As String()
            Dim strSplitted() As String = System.Text.RegularExpressions.Regex.Split(strRinggit, " ")
    
            Dim strConcatenatted() As String
            Dim strConcatenattedSize As Integer = 0
            ReDim strConcatenatted(strConcatenattedSize)
    
            Dim strTemp1 As String
            Dim strTemp2 As String
    
            Dim intCounter As Integer
            For intCounter = 0 To strSplitted.GetUpperBound(0)
                strTemp1 = strTemp1 & String.Concat(" ", strSplitted(intCounter), " ")
                strTemp1 = strTemp1.TrimStart(" ")
                strTemp1 = strTemp1.TrimEnd(" ")
    
                strTemp2 = strSplitted(intCounter)
    
                If strTemp1.Length > 39 Then
                    strConcatenattedSize += 1
                    ReDim strConcatenatted(strConcatenattedSize)
                    strConcatenatted(strConcatenattedSize) = strTemp2
                    strTemp1 = strTemp2
                Else
                    strConcatenatted(strConcatenattedSize) = strTemp1
                End If
                'MessageBox.Show(strConcatenattedSize & ": " & strConcatenatted(strConcatenattedSize))
            Next
    
            Dim x As Integer
            For x = 0 To strConcatenatted.GetUpperBound(0)
                MessageBox.Show(x & ": " & strConcatenatted(x))
            Next
    
            Return strConcatenatted
        End Function
    When i use the last MessageBox to display all value inside the array (strConcatenatted), i found that the array are all empty except the last array, which has value on it.
    For example, strConcatenatted's length is 3
    the value on:
    strConcatenatted(0) is ""
    strConcatenatted(1) is ""
    strConcatenatted(2) is "abcde"
    actually all of them should has string value.

    why is this so weird? pls guide me, thank you.
    Last edited by albertlse; Aug 21st, 2003 at 07:44 PM.

  2. #2
    Member
    Join Date
    Jul 2003
    Location
    Sweden
    Posts
    62
    Not sure but doesn´t the Redim empty the whole array?
    Try and set it to 3 and run it 3 times?
    //Martin Andersson

  3. #3
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985
    Originally posted by Iceman5
    Not sure but doesn´t the Redim empty the whole array?
    Try and set it to 3 and run it 3 times?
    Yes, if ReDim isn't accompanied by the Preserve keyword, the array will empty

  4. #4

    Thread Starter
    Registered User
    Join Date
    Apr 2003
    Location
    Klang, Selangor, Malaysia
    Posts
    163

    Thumbs up

    kasracer, thanx 4 ur help.
    my array is working fine now. it's jes bcoz of the keyword "Preserve"

  5. #5
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985
    Originally posted by albertlse
    kasracer, thanx 4 ur help.
    my array is working fine now. it's jes bcoz of the keyword "Preserve"

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