Problem with ASP class which does not pass its variables

N

nicver

I am fixing a client's Web site and for some reason an ASP class does
not want to use the variables it retrieves when it initialiases.

This is an excerpt of the class and it is enough to show what is not
working correctly:
------
Class clsAd
private pintMyData1
private pintMyData2
private pintMyData3

Private Sub class_Initialize()
(... creates some objects)
GetRequestData()
End Sub

Private Sub Class_Terminate()
(... kills some objects)
End Sub

Private Sub GetRequestData()
pintMyData1 = request("MyData1")
pintMyData2 = request("MyData2")
pintMyData3 = request("MyData3")
End Sub

Public Function AdList()
(retrieves a list from an SQL database use MyData1, etc...)
End Function

End Class

Dim AD
Set AD = new clsAd
------

First, MyPage.asp will include the class:

<!--#include virtual="/inc/clsAd.asp"-->

Then this code is supposed to retrieve a list of ads:
MyArray = AD.AdList()

The problem is that the variables are not retrieved properly and
therefore the list always includes the entire list (the Stored
Procedures functions this way).

If I insert "response.write pintMyData1" inside of the class, either
inside of GetRequestData() or of class_Initialize(), then the data will
show.

If I insert "response.write pintMyData1" inside of the parent
MyPage.asp, after the include, it does not show the data. If I insert
it inside of Public Function AdList(), it does not show either.

What is wrong in this code? I wonder if all the "private" should not be
switched to "public"? Or should I look into something else?

Thanks a lot in advance!
 
R

Ray Costanzo [MVP]

1. Do not use Request("name"). Specify what collection you're pulling
from, eg. Request.Form("name")
2. I suggest modifying your class and making public properties for
assigning those private values instead of pulling them from a request
object.
3. In regard to "> If I insert "response.write pintMyData1" inside of the
parent> MyPage.asp," this is expected. pingMyData1 is a private variable
available only to the class. Try this version:


Class clsAd

private _pintMyData1
private _pintMyData2
private _pintMyData3


Private Sub class_Initialize()
(... creates some objects)
_pintMyData1 = "some default value" 'optional
_pintMyData2 = "some default value" 'optional
_pintMyData3 = "some default value" 'optional
End Sub



Public Property Set pingMyData1(s)
_pintMyData1 = s
End Property

Private Sub Class_Terminate()
(... kills some objects)
End Sub



Public Function AdList()
(retrieves a list from an SQL database use MyData1, etc...)
End Function
End Class

Dim AD
Set AD = new clsAD
clsAD.pintMyData1 = "some value"
clsAD.pintMyData2 = "some value"
clsAD.pintMyData3 = "some value"

MyArray = clsAd.AdList()


Ray at work
 
N

Nicolas Verhaeghe

Thanks. Ok for the private variable kept inside the class, but even when I
try to print it from inside the class itself (AdList function) the value
does not show.

I already have that code as well, I forgot to mention:

Public Property Set pingMyData1(s)
_pintMyData1 = s
End Property
 
R

Ray Costanzo [MVP]

Nicolas Verhaeghe said:
Thanks. Ok for the private variable kept inside the class, but even when I
try to print it from inside the class itself (AdList function) the value
does not show.


Perhaps that is because Request("MyData1") doesn't have a value. First,
change it to Request.FOrm, Querystring, or whatever collection you're
pulling from. Then try. If that doesn't work, make sure your item actually
does have a value by trying something like:

For Each hamsandwich in Request.Form
Response.Write hamsandwich & " = " & Request.Form(hamsandwich) & "<br
/>"
Next

Ray at work
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top