VB a function to pass multiple values

xiaoxiao2021-03-06  62

Solve Function can only pass a value problem

-------------------------------------------------- ------------------------------

● Use function as a subsidy of subroutines, that is, the function itself can pass back a value to the last layer of call, but the problem is coming, if you work, you want to pass more than one value once, then What should I do?

Private submmand1_click ()

Myreturn 5, 6

End Sub

Private function myreturn (x, y) As long

A = x y

B = x - y

C = x * y

D = x / y

'Want to return to A, B, C, D four values ​​back, how to write?

END FUNCTION

● This is a basic concept problem, the passage of the subroutine and the substruction has two kinds of ByVal and byref. Byval is the passage between the two subroutines in different memory locations, and the preset byref is transmitted The value is placed in the same memory location, so this can be used to rewrite the above:

Private submmand1_click ()

Myreturn 5, 6, ANS1, ANS2, ANS3, ANS4

"& Ans1 & Ans1 & Ans)," & ANS3 & ANS "," & ANS3 & ANS "

End Sub

Private function myreturn (x, y, a, b, c, d) as long

A = x y

B = x - y

C = x * y

D = x / y

END FUNCTION

● Or use the data into a Variant type array back:

Private submmand1_click ()

ANS = Myreturn (5, 6)

"Answers" & ANS (0) & "& Ans (2) &", "& Anshi (2) &"

End Sub

Private function myreturn (x, y) As Variant

Myreturn = array (x y, x - y, x * y, x / y)

END FUNCTION

转载请注明原文地址:https://www.9cbs.com/read-113718.html

New Post(0)