在功能中使用(返回)声明?! [英] THE USE OF (RETURN) STATMENT IN FUNCTIONS?!

查看:85
本文介绍了在功能中使用(返回)声明?!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在函数中使用(返回)语句有什么用?

实际上我已经弄乱了函数不能让它感到迷失?

解决方案

LOL


好​​一个

这是一个例子。

公共功能HowUglyIsShe(Age as Integer)As String

选择案例年龄

案例16至22
返回Innocently Beautifull
案例23至30
返回Beautifull Mostly
案例31至39
返回更容易挑选up
案例40至60
返回当你努力工作时
案例61至100
返回谁在乎
案件其他
返回太年轻的评论或应该现在已经死了

结束选择

结束职能



Toreturn函数返回调用代码的结果......


" ---------" <一个******* @ discussions.microsoft.com>在消息中写道

news:22 ********************************** @ microsof t.com ...

在函数中使用(返回)语句有什么用?
实际上我已经弄乱了函数不能让它感觉丢失?


其他人给出了很好的例子,但是我要添加一条评论。

有两种方法可以从函数中返回一个值。这两个都将

工作:


函数区域(半径为单一)单个

''使用Return语句

返回半径*半径* 3.14159

''此处的其他代码将被忽略

结束功能


功能区(单个半径)单个

''设置它等于功能名称

面积=半径*半径* 3.14159

''此处的其他代码将被执行

结束功能


主要区别在于,在第一个示例中,返回充当EXIT

FUNCTION,执行后没有代码。在第二个示例中,在FunctionName =之后的任何

附加代码声明将被执行。


(刚刚在我的项目中遇到过这个。哎呀,为什么我的SQL没有任何关闭?b $ b关闭?因为我是在我使用return语句之后关闭连接对象。)


What is the use of (return ) statment in functions?
in fact i have got mess with function can''t catch it feel lost?

解决方案

LOL

Nice one

Here is an example.

Public Function HowUglyIsShe( Age As Integer ) As String

Select Case Age

case 16 to 22
Return "Innocently Beautifull"
case 23 to 30
Return "Beautifull Mostly"
case 31 to 39
Return "Easier to pick up"
case 40 to 60
Return "When you are hard up"
case 61 to 100
Return "Who cares"
case else
Return "Too young to comment or should be
dead by now"

End Select

End Function

Regards - OHM



To "return" the result of the function back to the calling code ...

"---------" <an*******@discussions.microsoft.com> wrote in message
news:22**********************************@microsof t.com...

What is the use of (return ) statment in functions?
in fact i have got mess with function can''t catch it feel lost?



Others have given good examples, but let me add one comment.
There are TWO ways to return a value from a function. Both of these will
work:

Function Area(radius as single) as single
''Using the Return statement
Return radius * radius * 3.14159
''Other code here will be ignored
End Function

Function Area(radius as single) as single
''Setting it equal to the name of the function
Area = radius * radius * 3.14159
''Other code here will be executed
End Function

The main difference is that in the first example, the return acts as an EXIT
FUNCTION, and NO code after it will be executed. In the second example, any
additional code after the "FunctionName =" statement WILL be executed.

(Just encountered this in my project. Gee, why aren''t any of my SQL
connections closing? Because I was closing the connection objects AFTER I
used the return statement.)


这篇关于在功能中使用(返回)声明?!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆