VB Trend Function - like Excel

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mark

    VB Trend Function - like Excel

    Hi - is there a function (or does anyone have any code) which replicates
    the TREND function in Excel:

    TREND(y, ,newx)

    I work in a call centre, and would like to predict the grade of service
    at the end of the month - based on the grade of service for each day of
    the month so far. I would like to have this contained within my vb.net
    web application, and not have to export data to Excel, then add the
    formulas, then create the report and reupload to our management portal.

    Any help/suggestions would be really appreciated.

    Thanks, Mark

    *** Sent via Developersdex http://www.developersdex.com ***
  • Mark

    #2
    Re: VB Trend Function - like Excel

    Hi - found it, in case anyone's interested:

    Public Sub LRegression(ByV al X() As Double, ByVal Y() As Double, ByRef
    Slope As Double, ByRef YInt As Double)
    Dim dblWork() As Object
    Dim dblXMean As Double
    Dim dblYMean As Double
    Dim dblSumXX As Double
    Dim dblSumXY As Double
    Dim dblSumYY As Double
    Dim dblSlope As Double
    Dim dblYInt As Double
    Dim lVCnt As Long
    Dim i As Long


    lVCnt = UBound(X)
    If (lVCnt <UBound(Y)) And (lVCnt 1) Then _
    Err.Raise(17, , "Arrays must match in number of vectors and
    have a count greater than 1.")

    lVCnt = lVCnt + 1

    ReDim dblWork(lVCnt)

    For i = 0 To lVCnt - 1
    dblXMean = dblXMean + X(i)
    Next i
    dblXMean = dblXMean / lVCnt

    For i = 0 To lVCnt - 1
    dblYMean = dblYMean + Y(i)
    Next i
    dblYMean = dblYMean / lVCnt

    For i = 0 To lVCnt - 1
    dblSumXX = dblSumXX + (X(i) - dblXMean) * (X(i) - dblXMean)
    Next i

    For i = 0 To lVCnt - 1
    dblSumYY = (dblSumYY + Y(i) - dblYMean) * (Y(i) - dblYMean)
    Next i

    For i = 0 To lVCnt - 1
    dblSumXY = dblSumXY + (X(i) - dblXMean) * (Y(i) - dblYMean)
    Next i

    dblSlope = dblSumXY / dblSumXX
    dblYInt = dblYMean - (dblSlope * dblXMean)

    Slope = Math.Round(dblS lope, 2)
    YInt = Math.Round(dblY Int, 2)


    End Sub



    *** Sent via Developersdex http://www.developersdex.com ***

    Comment

    Working...