none
vb.net and Excel question RRS feed

  • General discussion

  • Hello, I have 2 pieces of code I think are equivalent but I don't know why the second code doesn't work at the last statement even though the value is the same. can you explain for me? 

    first code:

            pr_regex = New Regex(strRegexPattern)
            Dim match As MatchCollection = pr_regex.matches(text)
            Dim a As Integer = match.Count
            If a = 0 Then Exit Sub
    
            Dim value(a - 1) As Object, i As Integer
            For Each item As Match In match
                value(i) = item.Value
                i += 1
            Next
    
           range.Resize(a, 1).Value2 =Excelapplication.WorksheetFunction.Transpose(value)


    '-------------------------------------------------------

    second code:

           pr_regex = New Regex(strRegexPattern)
    
            Dim match As MatchCollection = pr_regex.matches(text)
            Dim a As Integer = match.Count
            If a = 0 Then Exit Sub
    
            Dim value(a-1) As Object:match.CopyTo(value,0):
            range.Resize(a, 1).Value2 = Excelapplication.WorksheetFunction.Transpose(value)

    here is the error i get at last line:

    It looks like excelapplication is no longer working. I do not see the its value

    Thanks so much!



    • Edited by Khanh01 Monday, March 16, 2020 8:23 PM
    Monday, March 16, 2020 8:10 PM

All replies

  • Hi Khanh01,

    I guess you're using VB.NET with Windows Form (about the second code).
    And I'm afraid you need to provide more code, since I cannot know how some variables are defined.

    Regards,

    Ashidacchi -- http://hokusosha.com

    Tuesday, March 17, 2020 7:10 AM
  • Hi @Ashidacchi omg you were right i am using on winform, currently i am using option 1
    Tuesday, March 17, 2020 6:23 PM