p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


  Return to Index  

proasp_codeclinic thread: function in sub routine not returning results?


Message #1 by dont worry <aspmailbox@y...> on Wed, 21 Nov 2001 09:53:46 -0800 (PST)
hi,

to return a value in a function, you have to name the variable
used for the return value the same as the function, as in following example:

function length(word)
	length = len(word)
end function

The function returns this value, so you can use it this way:
	if length(word) > 5 then response.write "Word has more than 5 characters"
or
	dim WordLen 
	Wordlen = length(word)
	if Wordlen > 5 then> response.write "Word has more than 5 characters"


You can also use return <value> in the function itself, but i think I've read 
somewhere that it's not recommended.

Declaring a new variable in the function will create a local variable, which 
cannot be used outside the function.  I think you can use global vars 
(declared in the normal code) in a function, but that is called 'Dirty 
Programming' :p

Greetz,
Steven

############################################################################################


On Wednesday 21 November 2001 18:53, dont worry wrote:
> I have a sub routine which calls the
> emptyItem(x_Address1) function. The function checks
> data and should return a result of 1 or 0.  It doesn't
> return anything?  I need to run this same function
> multi times in this same sub routine.  any hints?
> 'CODE BELOW'
> sub checkinfo
> 'check on x_Address1
> emptyItem(x_Address1)
> if emptyStat = 1 then
> 	x_Address = x_Address1 &" "&x_Address2
> 	Response.Write "hello"
> end if
> Response.write x_Address1 & emptyStat &"<BR>"
> end sub
>
> 'Function to check empty status of item
> Function emptyItem(ByVal item)
> dim emptyStat
> emptyStat = 0
> 'Response.Write emptyStat
> If NOT IsNull(item) or NOT IsEmpty(item) Or
> NOT(Trim(item)="")OR Len(item) > 0 Then
> 	emptyStat= 1
> end if
> 'Response.Write item &"<BR>"
> Response.Write emptyStat
> end function
>
>
>
> __________________________________________________
> Do You Yahoo!?
> Yahoo! GeoCities - quick and easy web site hosting, just $8.95/month.
> http://geocities.yahoo.com/ps/info1
>
>
> Steven.Broos@N... 
> $subst('Email.Unsub')

  Return to Index