Another on Functions

1. Senior Member
Join Date
Dec 1969
Posts
511

## Another on Functions

Is my understanding of functions correct?<BR><BR>Say I have a function that was (for easy sake)<BR><BR>Function workitout(imyvar)<BR><BR>IF imyvar = "" THEN<BR>fmyvar = 0 - 2<BR>ELSE<BR>fmyvar = imyvar - 2<BR>END IF<BR><BR>END FUNCTION<BR><BR><BR>So If i wrote on my page<BR><BR>workitout(15)<BR><BR>would this return the value 13?<BR><BR><BR>If so to move on a step say i wanted to nest functions can one function call another function?<BR>

2. Senior Member
Join Date
Dec 1969
Posts
7,686

## RE: Another on Functions

No, with functions you have to assign the value to the function&#039;<BR><BR>Function workitout(imyvar)<BR><BR>IF imyvar = "" THEN<BR>workitout= 0 - 2<BR>ELSE<BR>workitout = imyvar - 2<BR>END IF<BR><BR>END FUNCTION<BR><BR>Furthermore, you can&#039;t pass empty parameters to a function, so your test for "" will never work.<BR><BR>You can nest functions

3. Senior Member
Join Date
Dec 1969
Posts
11,247

## RE: Another on Functions

Function workitout(imyvar)<BR><BR>IF imyvar = "" THEN<BR>fmyvar = 0 - 2<BR>ELSE<BR>fmyvar = imyvar - 2<BR>END IF<BR>workitout= fmyvar<BR>END FUNCTION

4. Senior Member
Join Date
Dec 1969
Posts
2,854

## RE: Another on Functions

&#062;&#062;Furthermore, you can&#039;t pass empty parameters to a function, so your test for "" will never work.<BR><BR>Just to clarify, you can pass an Empty String.....<BR>Not a Null value...<BR><BR>Also, in your example, you pass in an Iteger, then test for an Empty String... you should get a type mismatch..<BR><BR>So, to account for this....<BR><BR>IF trim("" & imyvar) = "" THEN<BR>&#039;when passing in an Integer.<BR><BR><BR>HTH<BR>D.<BR>

5. Senior Member
Join Date
Dec 1969
Posts
511

## right i get that next bit

So I now realise the output variable must be the same as the function name.<BR><BR>So is there any way to set a default value to a function so you could just call it without passing a variable sometimes but not others so when you do pass a variable it uses it otherwise it uses the default value?

6. Senior Member
Join Date
Dec 1969
Posts
7,686

## RE: Another on Functions

&#062;&#062;&#062;Just to clarify, you can pass an Empty String.....<BR>Not a Null value...<BR><BR>You&#039;re right.

7. Senior Member
Join Date
Dec 1969
Posts
7,686

## RE: right i get that next bit

only if you code it like that<BR><BR>Function Foo ( bar )<BR>Foo = 1 &#039;default value<BR><BR>IF bar = "" Then<BR> Foo = 12<BR>END IF<BR><BR>In .Net this is a lot easier....

8. Senior Member
Join Date
Dec 1969
Posts
511

## RE: right i get that next bit

if i wrote Response.Write Foo() wouldnt this return 12 instead of 1<BR><BR>Function Foo ( bar ) <BR>Foo = 1 &#039;default value <BR><BR>IF bar = "" Then <BR> Foo = 12 <BR>END IF <BR><BR>&#039;&#039;&#039;How so? ----&#062; In .Net this is a lot easier....

9. Senior Member
Join Date
Dec 1969
Posts
7,686

## RE: right i get that next bit

&#062;&#062; if i wrote Response.Write Foo() wouldnt this return 12 instead of <BR><BR>No, that isn&#039;t possible. You can use Foo ( "" )<BR><BR>SO if you do Response.Write Foo ( "" ) it will return 12, in all other cases 1. It&#039;s just an example.<BR><BR><BR>&#062;&#062; &#039;&#039;&#039;How so? ----&#062; In .Net this is a lot easier....<BR>Because in .Net you can use function overloading

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•