• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 160
  • Last Modified:

error

why do I get an error in here?

    Public Function Parse(ByRef sIn As String, ByRef sDel As String) As Object
        Dim s, i, x, t As Short
        i = 1 : s = 1 : t = 1 : x = 1
        Dim tArr(x) As Object


        If InStr(1, sIn, sDel) <> 0 Then


            Do
                ReDim Preserve tArr(x)
                tArr(i) = Mid(sIn, t, InStr(s, sIn, sDel) - t)
                t = InStr(s, sIn, sDel) + Len(sDel)
                s = t
                If tArr(i) <> "" Then i = i + 1
                x = x + 1
            Loop Until InStr(s, sIn, sDel) = 0
            ReDim Preserve tArr(x)
            tArr(i) = Mid(sIn, t, Len(sIn) - t + 1)
        Else
            tArr(1) = sIn
        End If
        Parse = VB6.CopyArray(tArr)
    End Function
0
aplelois
Asked:
aplelois
  • 5
1 Solution
 
prakash_prkCommented:
what do u want to do?
0
 
apleloisAuthor Commented:
I have a listbox and a button, I want to collect the IDs from my email into the listbox so when I click the button
I will see all the IDs inside the listbox like this
12356
3265
356698
3264486
etc....

this is my other code

    Function ParseIt(ByRef Expression As String, ByRef DelimiterA As String, ByRef DelimiterB As String) As Object
        Dim A, B As Integer
        A = 1
        While InStr(A, Expression, DelimiterA) > 0
            A = InStr(A, Expression, DelimiterA) + Len(DelimiterA)
            B = InStr(A, Expression, DelimiterB)
            ParseIt = Mid(Expression, A, B - A)
        End While
    End Function

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        ListBox1.Items.Clear()
        Dim TheRealList As String
        Dim TheFinishedList As String
        TheRealList = WebBrowser1.Document.DomDocument.documentElement.InnerHTML
        TheFinishedList = ParseIt(TheRealList, "main.asp?MailID=", Chr(34) & ">")
        Dim A As Object
        Dim i As Short
        i = 1
        A = Parse(TheFinishedList, ",")
        For i = 1 To UBound(A)
            ListBox1.Items.Add(A(i))
        Next i
    End Sub
0
 
apleloisAuthor Commented:
but is not working!!
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
apleloisAuthor Commented:
Error      1      Name 'VB6' is not declared.
Warning      2      Function 'ParseIt' doesn't return a value on all code paths. A null reference exception could occur at run time when the result is used.
0
 
Fernando SotoCommented:
Hi aplelois;

This function may not be doing what you want. If I am not mistaken Expression holds multiple ID's in it. but the function only returns the last one found.

    Function ParseIt(ByRef Expression As String, _
        ByRef DelimiterA As String, ByRef DelimiterB As String) As Object

        Dim A, B As Integer
        A = 1
        While InStr(A, Expression, DelimiterA) > 0
            A = InStr(A, Expression, DelimiterA) + Len(DelimiterA)
            B = InStr(A, Expression, DelimiterB)


            ' This statement overwrites the last one found.
            ParseIt = Mid(Expression, A, B - A)

        End While

    End Function

This is how I would change it.

    ' You do not need to send the parameters ByRef. The return type
    ' is a String
    Function ParseIt(ByVal Expression As String, _
        ByVal DelimiterA As String, ByVal DelimiterB As String) As String

        Dim A, B As Integer
        A = 1
        ParseIt = ""

        While InStr(A, Expression, DelimiterA) > 0
            A = InStr(A, Expression, DelimiterA) + Len(DelimiterA)
            B = InStr(A, Expression, DelimiterB)
            ' Add the ID to the result list with a comma at the end
            ParseIt += Mid(Expression, A, B - A) & ","
        End While

        ' If the list is not empty then remove the last comma from the list
        If Not ParseIt = "" Then
            ParseIt = ParseIt.Substring(0, ParseIt.LastIndexOf(","))
        End If

    End Function

The next function you have is:

    Public Function Parse(ByRef sIn As String, ByRef sDel As String) As Object
        Dim s, i, x, t As Short
        i = 1 : s = 1 : t = 1 : x = 1
        Dim tArr(x) As Object

        If InStr(1, sIn, sDel) <> 0 Then

            Do
                ReDim Preserve tArr(x)
                tArr(i) = Mid(sIn, t, InStr(s, sIn, sDel) - t)
                t = InStr(s, sIn, sDel) + Len(sDel)
                s = t
                If tArr(i) <> "" Then i = i + 1
                x = x + 1
            Loop Until InStr(s, sIn, sDel) = 0
            ReDim Preserve tArr(x)
            tArr(i) = Mid(sIn, t, Len(sIn) - t + 1)
        Else
            tArr(1) = sIn
        End If
        Parse = VB6.CopyArray(tArr)

    End Function

This is how I would change it:

    Public Function Parse(ByVal sIn As String, _
        ByVal sDel As String) As String()

        Dim tArr() As String = sIn.Split(sDel)
        Return tArr

    End Function

In Visual Basic 6 arrays started with index at 1 in VB .Net they start at zero. The use of InStr will return invalid values because of it.

Try doing the above to see if it fixes your problem.

Fernando
0
 
apleloisAuthor Commented:
Yes, Fernando thats what I was looking for it works.. thanks
check this one out http:Q_21843101.html
0
 
apleloisAuthor Commented:
Fernando, I think you are the only one who can help me http:Q_21843102.html
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now