Consulting

Results 1 to 3 of 3

Thread: Mid() mismatch

  1. #1

    Mid() mismatch

    Hello All,

    The debugger points to the first use of mid() as 'Error 13' type mismatch.

    The idea of the subroutine is to take a string like 2x^5-3x^2-5 and put the coefficients and exponents into arrays. Can anyone tell me where I am going wrong?

    Private Sub loadfunc()
    
    Dim xptr As Integer, i As Integer, ptr As Integer, signptr As Integer, posptr As Integer, negptr As Integer
    Dim s As String, tempstr As String
    
    
    ReDim c(n) As Double
    ReDim e(n) As Double
    
    
    s = TB_EQ
    
    
    ptr = 1
    
    
    For i = 1 To n
        If i = n Then
            c(i) = mid(s, ptr + 1)
        Else
            xptr = InStr(ptr, s, "x")
            posptr = InStr(ptr + 1, s, "+")
            negptr = InStr(ptr + 1, s, "-")
            If negptr = 0 Then
                signptr = posptr
            ElseIf posptr = 0 Then
                signptr = negptr
            ElseIf posptr < negptr Then
                signptr = posptr
            Else
                signptr = negptr
            End If
            tempstr = mid(s, ptr, xptr - ptr)
            c(i) = CDbl(tempstr)
            tempstr = mid(s, xptr + 2, signptr - (xptr + 2))
            e(i) = CDbl(tempstr)
            ptr = signptr
        End If
    Next i
    
    
    
    
    End Sub

  2. #2
    VBAX Mentor
    Joined
    Jul 2012
    Posts
    398
    Location
    variable n is not defined in your code

  3. #3
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,645
    sub M_snb()
      sn=strconv("2x^5-3x^2-5",64)
    end sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •