Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ASP MID Function issue...

Status
Not open for further replies.

Clarkie001

IS-IT--Management
Aug 26, 2003
59
0
0
GB
I am receiving a runtime error 'Invalid Procedure on the MID functions in the following code.

Please shed some light on this..

Thanks

Clarkie

<%
dim conn, rs, sql

set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open(Server.Mappath("Nuggit_v1.0.mdb"))
set rs = server.createobject("ADODB.Recordset")

sql = "SELECT * FROM tblRetailer_Product_Key;"

rs.open sql, conn, 3


Dim iStart
Dim iProductKey
Dim iKeyLength
Dim i
Dim myArray()
Dim myArray2()
Dim strCurrComma

Do until rs.EOF
iKeyLength = Len(rs("Product_key"))
For i = 1 To iKeyLength
strCurrComma = Mid(rs("Product_Key"), i, 1)
If strCurrComma = Chr(44) Then
redim myarray(0)
If isarray(myArray) Then
ReDim Preserve myArray(UBound(myArray) + 1)
myArray(UBound(myArray)) = i
Else
ReDim myArray(0)
myArray(UBound(myArray)) = i
End If
End If
Next
For i = 0 To UBound(myArray)
If i > 0 Then
If isarray(myarray2) Then
redim myarray2(0)
ReDim Preserve myArray2(UBound(myArray2) + 1)
myArray2(UBound(myArray2)) = myArray(i) - myArray(i - 1)
Else
ReDim myArray2(0)
myArray2(0) = myArray(0)
End If
End If
Next

For i = 0 To UBound(myArray) + 1
If i = 0 Then 'First Product Key in sequence
iProductKey = Mid(rs("Product_Key"),1, myArray(i) - 1)
Else If i > UBound(myArray) Then 'Last Product Key in sequence
iProductKey = Mid(rs("Product_Key"), myArray(UBound(myArray)) + 1, iKeyLength - UBound(myArray))
Else
iProductKey = Mid(rs("Product_Key"), myArray(i) - (myArray2(i - 1) - 1), myArray2(i - 1) - 1)
End If
End if
response.write(iProductKey)
Next

rs.MoveNext
Loop


conn.close

set rs = nothing
set conn = nothing
%>
 
Please don't post all your code. Just the one that is erroring out

is it this?
Mid(rs("Product_Key"),1, myArray(i) - 1)
or the others?

Did you validate those arguments are valid? usually procedural calls are results of not valid arguments. meaning a -1 or null etc..

[sub]____________ signature below ______________
You are a amateur developer until you realize all your code sucks.
Jeff Atwood[/sub]
 
I agree with onpnt, try this:[tt]
strCurrComma = Mid(rs("Product_Key") [red]& ""[/red], i, 1)
[/tt]

By concatinating an empty string to the recordset value, any Nulls or Numeric values will be converted to a character string.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top