如果完成了一个将字符串解析为片段(字段)的脚本,那么''返回True表示我们设置了值 GetMyValues = True 结束功能 但这不是我经常使用的方法。你可以得到函数返回一个字符串,如:" FirstName = Steve~LastName = Smith~DOB = 1965-01-01"然后将其拆分。或者你可以获得返回数组的功能。 或者用户定义的数据类型如何,例如 类型人物 FirstName As String LastName As String DOB作为日期结束类型 公共函数LoadPerson(psn As Person)As Boolean psn.FirstName =" Steve" psn.LastName =" Smith" psn.DOB = DateSerial(1965,1,1) LoadPerson = True Public Sub TestPerson() Dim psn As Person 如果LoadPerson(psn)那么 MsgBox"你好,我是&安培; psn.FirstName& " " &安培; psn.LastName 结束如果 结束子 There was a recent discussion on ByVal/ByRef concerning how function arguments are normally passed ByRef (unless you specify ByVal). This means that the function can change those actual values and you could use this as a way to get multiple values from a function - that is, you would get a single result to say whether all the values had been loaded into the parameters you passed: Public Function GetMyValues(strFirstName As String, strLastName As String, dteDOB As Date) As Boolean '' Do complicated processing to work out values strFirstName="Steve" strLastName="Smith" dteDOB=DateSerial(1965,01,01) '' Return True to say we have set the values GetMyValues=True End Function But this is not a method I have seen used very often. You could get you function to return a string like: "FirstName=Steve~LastName=Smith~DOB=1965-01-01" and split it up later. Or you could get the function to return an array. Or how about a user-defined data type, eg Type Person FirstName As String LastName As String DOB As Date End Type Public Function LoadPerson(psn As Person) As Boolean psn.FirstName = "Steve" psn.LastName = "Smith" psn.DOB = DateSerial(1965, 1, 1) LoadPerson = True End Function Public Sub TestPerson() Dim psn As Person If LoadPerson(psn) Then MsgBox "hello I''m " & psn.FirstName & " " & psn.LastName End If End Sub 这篇关于从函数中获取多个结果。?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
09-13 14:43