Solved

Sub Calling a Function - VBScript/Classic ASP

Posted on 2014-04-16
7
787 Views
Last Modified: 2014-04-16
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!
0
Comment
Question by:Nico2011
  • 3
  • 2
  • 2
7 Comments
 
LVL 32

Expert Comment

by:Big Monty
ID: 40004057
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
0
 

Author Comment

by:Nico2011
ID: 40004080
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 ;-) )
0
 
LVL 52

Accepted Solution

by:
Scott Fell,  EE MVE earned 500 total points
ID: 40004087
I think the problem is you are not returning a variable as the function name.  Look at this over simple example

featured_property("abc")

Sub featured_property(PropID)

    msg = locImg(PropID)
    response.write msg

End Sub

Function locImg(x)
    if cstr(x)<>"abc" then
         locImg="found"
         else
         locImg="not found"
    end if
end Function

Open in new window

vs this one will not work
featured_property("abc")

Sub featured_property(PropID)

    msg = locImg(PropID)
    response.write msg

End Sub

Function locImg(x)
    if cstr(x)<>"abc" then
' **** imgsrc should be the name of the function *****
         imgsrc ="found"
         else
         imgsrc ="not found"
    end if
end Function

Open in new window

In your code for the function just change these two lines
' ****** imgsrc = imgurl & imagefile & imgclass & classer
locImg = imgurl & imagefile & imgclass & classer
else

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

Open in new window

0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 32

Expert Comment

by:Big Monty
ID: 40004090
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
0
 
LVL 52

Expert Comment

by:Scott Fell, EE MVE
ID: 40004111
That's 2 to confirm the same solution.  I think you have a winner.
0
 
LVL 32

Expert Comment

by:Big Monty
ID: 40004123
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
0
 

Author Closing Comment

by:Nico2011
ID: 40004147
Thanks Scott - works perfectly!

Sorry everyone else - Scott was first ;-)
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Well hello again!  Glad to see you've made it this far without giving up.  In this, the fourth installment of my popular series, I'm going to cover functions and subroutines, what they are, and why they are useful.  Just in case you stumbled onto th…
Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now