PDA

View Full Version : Mid() mismatch



smountain
05-08-2014, 03:30 PM
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

patel
05-09-2014, 01:37 AM
variable n is not defined in your code

snb
05-09-2014, 04:25 AM
sub M_snb()
sn=strconv("2x^5-3x^2-5",64)
end sub