Link to home
Start Free TrialLog in
Avatar of Nico2011
Nico2011Flag for United Kingdom of Great Britain and Northern Ireland

asked on

Sub Calling a Function - VBScript/Classic ASP

Hello,

I have a sub which calls a function, however the function doesn't return any results when called from within the sub...!  I am guessing that there is some specific way of doing this that I don't know so would appreciate some guidance!

Here is the sub which is called from a classic asp page - the function is imgsrc = with the code being shown separately below... (I have tried Public Sub, but that didn't work either).

SUB:
Sub featured_property(PropID)
SQL = "Select * from Villas where ID = " & PropID
Set PropRS = DB.Execute(SQL)
'Response.Write(SQL)
If NOT PropRS.EOF Then
Sleeps = PropRS("Sleeps")
Property_Name = PropRS("Property_Name")
Country = PropRS("Country")
Region = PropRS("Region")
Town = PropRS("Town")
Bedrooms = PropRS("Bedrooms")
baths = PropRS("total_bathrooms")
Client_ID = PropRS("Client_ID")
Price_USD = PropRS("Rental_USD")
Price_EUR = PropRS("Rental_EUR")
Price_GBP = PropRS("Rental_GBP")
If PropRS("AWS") = 1 then
AWS = "http://www.vi11as.com/"
AWS1 = 1
Else
AWS = ""
AWS1 = 0
End If
		SQL = "Select TOP 3 image, verified, client_ID, URL from Photos where PropID = " & PropID & " Order By OrderBy"
		'Response.Write(SQL)
		Set PhotoRS = DB.Execute(SQL)
				
		If PhotoRS("Image") <> "" Then 
			'Response.Write(AWS1 & " - " & PhotoRS("verified") & " - " & Client_ID & " - " & PhotoRS("image") & " - " & PhotoRS("URL"))
			imgsrc = locImg(AWS1, PhotoRS("verified"), Client_ID, PhotoRS("image"), PhotoRS("URL"))
			photo = imgsrc & "SM" 
			TMPhoto = imgsrc & "TM"
		Else 
			photo = "http://www.villasdirect.com/villa/nopic.jpg"
			TMPhoto = ""
		End If
		
		If NOT PhotoRS.EOF Then
		PhotoRS.MoveNext
			If PhotoRS("Image") <> "" Then 
				Call locImg(AWS1, PhotoRS("verified"), Client_ID, PhotoRS("image"), PhotoRS("URL"))
				photo_two = imgsrc & "SM" 
				TMPhoto_two = imgsrc & "TM"
			Else 
				photo_two = "http://www.villasdirect.com/villa/nopic.jpg"
				TMPhoto_two = ""
			End If
		Else 
		photo_two = "http://www.villasdirect.com/villa/nopic.jpg"
		TMPhoto_two = ""			
		End If
		
		If NOT PhotoRS.EOF Then
		PhotoRS.MoveNext
			If PhotoRS("Image") <> "" Then 
				Call locImg(AWS1, PhotoRS("verified"), Client_ID, PhotoRS("image"), PhotoRS("URL"))
				photo_three = imgsrc & "SM" 
				TMPhoto_three = imgsrc & "TM"
			Else 
				photo_three = "http://www.villasdirect.com/villa/nopic.jpg"
				TMPhoto_three = ""
			End If
		Else 
		photo_three = "http://www.villasdirect.com/villa/nopic.jpg"
		TMPhoto_three = ""
		End If

		PhotoRS.Close
		Set PhotoRS = Nothing
%>	
<table width="200" align="left" border="0" cellspacing="0" cellpadding="0">
	<tbody><tr><td width="200" height="132" align="left" valign="top">
	<a href="http://www.villasdirect.com/<%=PropID%>" onclick="document.getElementById('holdpage').style.display='block';"><img src="<%=photo%>" name="<%=Property_Name%>" width="200" height="129" align="absmiddle" id="Villa<%=PropID%>" border="0" alt="Property <%=Property_Name%> for Rent in <%=town%>, <%=region%>, <%=country%>"/></a></td></tr>
<tr><td height="42" valign="top">
<table width="200" border="0" cellspacing="0" cellpadding="0">
		<tbody><tr>
<%if photo_two <> "" then%>
<td width="67" height="40" valign="bottom">
<a href="#" onmouseover="ChangePic('<%=Photo%>','Villa<%=PropID%>');"><img src="<%=TMPhoto%>" width="67" height="40" align="middle" border="0" alt="First Photo of Property <%=Property_Name%> for Rent in <%=town%>, <%=region%>, <%=country%>"/></a></td>
<%else%>
<td width="67" height="40"></td>
<%end if%>
<td width="66" height="40" valign="bottom">
<%If Photo_two <> "" then%>
<a href="#" onmouseover="ChangePic('<%=photo_two%>','Villa<%=PropID%>');"><img src="<%=TMPhoto_two%>" width="66" height="40" align="middle" border="0" alt="Second Photo of Property <%=Property_Name%> for Rent in <%=town%>, <%=region%>, <%=country%>"/></a></td>
<%else%>
<td width="66" height="40"</td>
<%end if%>
<td width="67" height="40" valign="bottom">
<%if photo_three <> "" then%>
<td width="67" height="40" valign="bottom">
<a href="#" onmouseover="ChangePic('<%=Photo_three%>','Villa<%=PropID%>');"><img src="<%=TMPhoto_three%>" width="67" height="40" align="middle" border="0" alt="Third Photo of Property <%=Property_Name%> for Rent in <%=town%>, <%=region%>, <%=country%>"/></a></td>
<%else%>
<td width="67" height="40"></td>
<%end if%>
</tr></tbody></table></td></tr>
<tr><td height="86" align="center" valign="top" class="indexfeatpropbkg">
<table width="200" border="0" cellspacing="0" cellpadding="0" class="indexfeatpropbkg">
<tr><td height="27" align="center" valign="bottom"><strong class="parablue14"><%=Country%>, Ref: <%=PropID%></strong></td></tr>
<tr><td height="39" valign="bottom"><table width="200" border="0" cellspacing="0" cellpadding="0">
<tr><td width="35" align="right"><img src="images/people_wh.png" width="26" height="25" alt="Sleeps <%=sleeps%> People" title="Sleeps <%=sleeps%> People"/></td>
<td width="42" class="para18white" align="left">&nbsp;<%=Sleeps%></td>
<td width="45"><img src="images/beds.png" width="41" height="25" alt="<%=bedrooms%> bedrooms" title="<%=bedrooms%> bedrooms"/></td>
<td width="23" class="para18white"><%=bedrooms%></td>
<td width="35"><img src="images/showers.png" width="31" height="30" alt="<%=baths%> baths/showers" title="<%=baths%> baths/showers"/></td>
<td width="20"><span class="para18white"><%=baths%></span></td></tr>
</table></td></tr>
<tr><td height="33" align="center" valign="top" class="para12white">price per week from<br />&#128;<%=Price_EUR%>&nbsp; &pound;<%=Price_GBP%>&nbsp;&nbsp;&#36;<%=Price_USD%></td>
</tr></table></td></tr><tr><td height="5"></td></tr>
<tr><td><table width="200" border="0" cellpadding="0" cellspacing="0">
<tr><td height="36" align="center" valign="bottom"><a href="http://www.villasdirect.com/<%=PropID%>" class="buttongrsresults" onclick="document.getElementById('holdpage').style.display='block';">&nbsp;&nbsp;VIEW PROPERTY!&nbsp;&nbsp;</a></td></tr>
</table></td></tr></tbody></table>
<%else%>
<table><tr><td>&nbsp;</td></tr></table>
<%end if
Response.write(FProp)
PropRS.Close
Set PropRS = Nothing

End Sub

Open in new window


And here is the FUNCTION:
Function locImg(AWS1, photoverified, OwnerID, image, URL)

imgurl = "http://www.villasdirect.com/dash/img/imagegen.ashx?image="
imgclass = "&class="

image = LCase(image)

If AWS1 = 1 then 
classer = "AWS"
else
classer = ""
end if
												
if photoverified = -2 then
classer = ""	

	if OwnerID = 6787 then 
	classer = classer & "6787"
	imagefile = image
	end if
								
	if OwnerID = 7026 then 

		If left(URL, 27) = "http://images.interhome.com" then
		classer = classer & "7026-images"
		imagefile = Right(URL, (Len(URL) - 28))
		else	
		
			If left(URL, 26) = "http://fijip.interhome.com" then
			classer = classer & "7026-fijip"
			imagefile = Right(URL, (Len(URL) - 27))
			else
			classer = classer & "FullURL"
			imagefile = URL
			end if
		end if
	end if
								
	if OwnerID = 6781 then 
	classer = classer & "6781"
	imagefile = image
	end if

imgsrc = imgurl & imagefile & imgclass & classer

else

imgsrc = imgurl & "villa/" & PropID & "/VB" & image & imgclass & classer
							
end if
End Function

Open in new window


THANKS in advance!
Avatar of Big Monty
Big Monty
Flag of United States of America image

are you getting an error or are you just not getting the results you expect?

the code (upon a very brief glance over) looks fine. and you're calling the sub the right way. what i would do is try putting Response.Write statements within the function and the sub and use them as break points. if you get that output, then you know you're on the right track.

so to start you in the right direction, i would do something like this:

		If PhotoRS("Image") <> "" Then 
			'Response.Write(AWS1 & " - " & PhotoRS("verified") & " - " & Client_ID & " - " & PhotoRS("image") & " - " & PhotoRS("URL"))
response.write "before function call"
			imgsrc = locImg(AWS1, PhotoRS("verified"), Client_ID, PhotoRS("image"), PhotoRS("URL"))
response.write "after function call"
			photo = imgsrc & "SM" 
			TMPhoto = imgsrc & "TM"
		Else 
			photo = "http://www.villasdirect.com/villa/nopic.jpg"
			TMPhoto = ""
response.write "no function call"
		End If

Open in new window


this will help you verify the function is being called
Avatar of Nico2011

ASKER

Thanks - yes - I have done that before I sent the request for help - it simply won't play ball...

I have put in your exact code and it does show before call and after call, but imgsrc stays as NULL, however this code works elsewhere (it is an include file) which is why I came to the conclusion that there must be something wrong with the way I am calling the function to get the imgsrc variable...

(it is starting to drive me nuts ;-) )
ASKER CERTIFIED SOLUTION
Avatar of Scott Fell
Scott Fell
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
looking at your function, it's not returning a value, change

imgsrc = imgurl & imagefile & imgclass & classer

else

imgsrc = imgurl & "villa/" & PropID & "/VB" & image & imgclass & classer

to

locimg = imgurl & imagefile & imgclass & classer

else

locimg = imgurl & "villa/" & PropID & "/VB" & image & imgclass & classer
That's 2 to confirm the same solution.  I think you have a winner.
yup, Scott beat me to it :)

Another thing you could look into is the scope of the variable. If this function is being used elsewhere, then you may not want to change it with fear of breaking other code. if you declare the variable imgsrc outside the sub and function, it'll be a global variable and accessible from within all subs functions. then the code you have in place for the function will work, you'll just have to change the call to the function and not assign it to a variable
Thanks Scott - works perfectly!

Sorry everyone else - Scott was first ;-)