IIS ASP - Problem with ASP class which does not pass its variables

This is Interesting: Free IT Magazines  
Home > Archive > IIS ASP > July 2005 > Problem with ASP class which does not pass its variables





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Problem with ASP class which does not pass its variables
nicver@yahoo.com

2005-07-27, 2:49 am

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!

Ray Costanzo [MVP]

2005-07-27, 5:54 pm

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


<nicver@yahoo.com> wrote in message
news:1122449623.594282.27880@o13g2000cwo.googlegroups.com...
> 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!
>



Nicolas Verhaeghe

2005-07-27, 5:54 pm

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


"Ray Costanzo [MVP]" <my first name at lane 34 dot commercial> wrote in
message news:uka4jQrkFHA.764@TK2MSFTNGP14.phx.gbl...
> 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
>
>
> <nicver@yahoo.com> wrote in message
> news:1122449623.594282.27880@o13g2000cwo.googlegroups.com...
>
>



Ray Costanzo [MVP]

2005-07-27, 5:54 pm


"Nicolas XXXXXXXXX" <nospam_nicver@yahoo.com_nospam> wrote in message
news:42e7c377$0$22196$39cecf19@news.twtelecom.net...
> 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


Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com