CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 2018
    Posts
    1

    Please help to find errors

    Hi,

    I am new to VB, can anyone explain the concept on this code.

    Code:
    Public Sub resultsto(rpath As String, tabname As String)
    Dim exapp As Object
    Dim wb As Workbook
    Dim ws As Worksheet
    Dim i As Long
    Dim j As Long
    Dim resultssplit As Variant
    Dim fieldssplilt As Variant
    Dim hrs As Variant
    Set exapp = CreateObject("Excel.Application")
    exapp.DisplayAlerts = False
    If Dir(rpath) <> "" Then
        Set wb = exapp.Workbooks.Open(rpath)
    Else
        Set wb = exapp.Workbooks.Add
    End If
    Set ws = wb.sheeets.Add
    ws.Name = tabname
    c = 1
    hrs = Split(strsomerecordset, vbLf)
    
    If UBound(hrs) <> -1 Then
        For i = 1 To Len(hrs(0))
            If (Mid(hrs(0), i, 1)) = "," Then
                c = c + 1
            End If
            ws.Cells(1, c).Value = ws.Cells(1, c).Value & Mid(hrs(0), i, 1)
        Next i
    End If
    r = 2
    c = 1
    
    If UBound(hrs) > 0 Then
        resultssplit= split(hrs(1),"<rd>"
        For i = 0 To UBound(resultssplit)
            fieldssplit = Split(resultssplit(i), "<fd>")
            For j = 0 To Split(resultsplit)
                ws.Cells(1, c).Value = Replace(fieldssplit(j), "<empty>", "")
                c = c + 1
            Next j
            c = 1
            r = r + 1
    else
        ws.Cells(1, c).Value = "no results returned"
    end if 
    
    If Dir(rpath) <> "" Then
        wb.Save
    Else
        wb.SaveAs rpath
    End If
    exapp.Quit
    End Sub

    Thanks
    Last edited by 2kaud; March 29th, 2018 at 04:45 AM. Reason: Added code tags

  2. #2
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,824

    Re: Please help to find errors

    [When posting code please use code tags so that the code is readable. Go Advanced, select the formatted code and click '#'].

    Cheers!
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  3. #3
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,824

    Re: Please help to find errors

    I'm not a VB programmer so can't really advise - but is there a missing next i after r = r + 1 ??
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

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

Featured