Array of custom classes problem [modified]
-
Hi! I have an array of custom classes. When I try to set a variable with one of the array item, I get this error: Microsoft VBScript runtime error '800a01a8' Object required: '[undefined]' I guess I'm not far off but I must be missing something. Here's my code ( Important lines are in bold ):
class CReviews private m_IDProd private m_aReviews public sub GetReviews(IDProd) i = 1 m_IDProd = IDProd mySQL = "SELECT * FROM ProductReviews WHERE IDProd = " & IDProd & ";" set rs = conn.execute(mySQL) if not rs.eof then m_aReviews = Array( i ) rs.movefirst do while not rs.eof ReDim m_aReviews( i ) Set review = New CReview review.GetReview( rs("ID") ) Set m_aReviews( i ) = review i = i + 1 rs.movenext loop end if end sub public function GetReviewCount() GetReviewCount = UBound( m_aReviews ) end function public function GetReview(nIndex) if nIndex > 0 AND nIndex <= GetReviewCount() then GetReview = m_aReviews( nIndex ) else GetReview = nothing end if end function end class class CReview private m_ID private m_ReviewEn public sub GetReview(ID) 'do stuff end sub public property Get ReviewEn() ReviewEn = m_ReviewEn end property end class sub GetReview(IDProd) Set reviews = New CReviews reviews.GetReviews( IDProd ) response.Write( reviews.GetReviewCount() ) 'This line generates the error Set review = reviews.GetReview( 1 ) if review <> nothing then response.Write( review.ReviewEn() ) end if end sub
Thanks! Luc -- modified at 13:21 Saturday 29th July, 2006
-
Hi! I have an array of custom classes. When I try to set a variable with one of the array item, I get this error: Microsoft VBScript runtime error '800a01a8' Object required: '[undefined]' I guess I'm not far off but I must be missing something. Here's my code ( Important lines are in bold ):
class CReviews private m_IDProd private m_aReviews public sub GetReviews(IDProd) i = 1 m_IDProd = IDProd mySQL = "SELECT * FROM ProductReviews WHERE IDProd = " & IDProd & ";" set rs = conn.execute(mySQL) if not rs.eof then m_aReviews = Array( i ) rs.movefirst do while not rs.eof ReDim m_aReviews( i ) Set review = New CReview review.GetReview( rs("ID") ) Set m_aReviews( i ) = review i = i + 1 rs.movenext loop end if end sub public function GetReviewCount() GetReviewCount = UBound( m_aReviews ) end function public function GetReview(nIndex) if nIndex > 0 AND nIndex <= GetReviewCount() then GetReview = m_aReviews( nIndex ) else GetReview = nothing end if end function end class class CReview private m_ID private m_ReviewEn public sub GetReview(ID) 'do stuff end sub public property Get ReviewEn() ReviewEn = m_ReviewEn end property end class sub GetReview(IDProd) Set reviews = New CReviews reviews.GetReviews( IDProd ) response.Write( reviews.GetReviewCount() ) 'This line generates the error Set review = reviews.GetReview( 1 ) if review <> nothing then response.Write( review.ReviewEn() ) end if end sub
Thanks! Luc -- modified at 13:21 Saturday 29th July, 2006
if( not review ) -- then error ----
-------------------------------------------------------- 1 line of code equals many bugs. So don't write any!! My mad coder blog
-
if( not review ) -- then error ----
-------------------------------------------------------- 1 line of code equals many bugs. So don't write any!! My mad coder blog
-
sorry i dont do VB if( review is nothing ) then -- do some error code --- end if
-------------------------------------------------------- 1 line of code equals many bugs. So don't write any!! My mad coder blog
-
sorry i dont do VB if( review is nothing ) then -- do some error code --- end if
-------------------------------------------------------- 1 line of code equals many bugs. So don't write any!! My mad coder blog
-
Hi! I have an array of custom classes. When I try to set a variable with one of the array item, I get this error: Microsoft VBScript runtime error '800a01a8' Object required: '[undefined]' I guess I'm not far off but I must be missing something. Here's my code ( Important lines are in bold ):
class CReviews private m_IDProd private m_aReviews public sub GetReviews(IDProd) i = 1 m_IDProd = IDProd mySQL = "SELECT * FROM ProductReviews WHERE IDProd = " & IDProd & ";" set rs = conn.execute(mySQL) if not rs.eof then m_aReviews = Array( i ) rs.movefirst do while not rs.eof ReDim m_aReviews( i ) Set review = New CReview review.GetReview( rs("ID") ) Set m_aReviews( i ) = review i = i + 1 rs.movenext loop end if end sub public function GetReviewCount() GetReviewCount = UBound( m_aReviews ) end function public function GetReview(nIndex) if nIndex > 0 AND nIndex <= GetReviewCount() then GetReview = m_aReviews( nIndex ) else GetReview = nothing end if end function end class class CReview private m_ID private m_ReviewEn public sub GetReview(ID) 'do stuff end sub public property Get ReviewEn() ReviewEn = m_ReviewEn end property end class sub GetReview(IDProd) Set reviews = New CReviews reviews.GetReviews( IDProd ) response.Write( reviews.GetReviewCount() ) 'This line generates the error Set review = reviews.GetReview( 1 ) if review <> nothing then response.Write( review.ReviewEn() ) end if end sub
Thanks! Luc -- modified at 13:21 Saturday 29th July, 2006
LukeV wrote:
Set review = New CReview review.GetReview( rs("ID") ) Set m_aReviews( i ) = review
Try this: Set m_aReviews( i ) = review.GetReview( rs("ID") )
-------------------------------------------------------- 1 line of code equals many bugs. So don't write any!! My mad coder blog