Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello guys, im a bit stuck here as im not that good in programming and still learning :)

im stuck with an error "Index was outside the bounds of the array". i placed msgboxes so that i could really know how it is flowing, (i did'nt use the debug tool because i dont want it. :) )

anyhow the solutions i have made so far are:
1. i used
VB
Option Explicit on
= didnt worked.
2. tried to lessen the ubound(arrayTextFile)
VB
For i = 1 To UBound(ArrayTextFile) - 2
it ddnt work again
3. i used this kind of checking, i really dont know what it did. but it failed me :(

VB
Dim placename As String
If ListView1.Items.Count > 0 Then
    placename = ListView1.Items.Count = 0
Else
    placename = String.Empty
End If


i know i am missing something i just cant see through codes,
so can anybody please help me. thank you guys.
here's the code for the function.

after i pass MsgBox("inside with - " & ListView1.Items.Count) Im directed aleady to the catch and posted with the message "Index was outside the bounds of the array"
VB
Try
            Dim ArrayTextFile() As String
            Dim lineOfText As String
            Dim i As Integer

            lineOfText = rcvdata.ToString
            ArrayTextFile = Split(lineOfText, "+CMGL", , CompareMethod.Text)
            MsgBox("did i pass here?" & i)
            MsgBox(UBound(ArrayTextFile))
            For i = 1 To UBound(ArrayTextFile)
                Dim input As String = ArrayTextFile(i)
                Dim result() As String
                Dim pattern As String = "(:)|(,"")|("","")"
               
 MsgBox("did i pass here? -pattern")
                result = Regex.Split(input, pattern)

                Dim lvi As New ListViewItem
                Dim concat() As String
                MsgBox("did i pass here? -lvi and concat")

                With (ListView1.Items.Add("null"))
                    MsgBox("inside with - " & ListView1.Items.Count)
                    'for item 1
                    .SubItems.AddRange(New String() {result(2)})
                    MsgBox("did i pass here? result 2")
                    'for item 2
                    .SubItems.AddRange(New String() {result(4)})
                    MsgBox("did i pass here? -result 4")
                    'extract numbers
                    Dim myString, position As String
                    myString = result(6)
                    position = myString.Length - 2
                    myString = myString.Remove(position, 2)
                    .SubItems.Add(myString)
                    MsgBox("did i pass here? -result5")
                    'for date/time
                    concat = New String() {result(8) & result(9) & result(10) & result(11) & result(12).Substring(0, 2)}
                    .SubItems.AddRange(concat)
                    'message extracted
                    Dim lineOfTexts As String
                    Dim arrayTextFiles() As String
                    lineOfTexts = ArrayTextFile(i)
                    arrayTextFiles = Split(lineOfTexts, "+32", , CompareMethod.Text)
                    .SubItems.Add(arrayTextFiles(i))
                End With
                MsgBox("did i pass here? going to the top to loop again")
            Next
            MsgBox("loop finish")
        Catch ex As Exception
            MsgBox("what is wrong?" & ex.Message)
        End Try
    End Sub
Posted
Updated 3-Jul-14 4:07am
v2
Comments
[no name] 3-Jul-14 9:47am    
The error message means exactly what it says. If you "dont want" to use the debugger to find and fix your error, what makes you think that we will?

1 solution

Firstly - use the debugger if you want to be taken seriously. Not only can you determine exactly where the error occurred very quickly you can also easily examine the local variables to help determine what is wrong.

Clearly array result only has 2 elements and you are trying to access a third with result(2)

Remember arrays etc tend to be zero-based i.e. result(0) would be the first element not result(1)
 
Share this answer
 
Comments
rember241 4-Jul-14 8:01am    
thanks for the reply sir CHill60, i started at 1 because i dnt want to get the first element, and i tried using debug but i still cant figure out why am i not looping, im still out of bounds, please help im stuck here and cant move forward, many thanks guys :)

if i remove what is inside the with ...... end with

i can loop but if i will add it there will be no loop :( it will end already, i still can't figure it out why can't i loop :(

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900